body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I have a php authentication script and everything works fine, but I'm very unsure about the way I programmed it (I hardcoded some things). I was hoping stack could look through this and point out any potential problems. Here's the script:</p>
<pre><code><?php
require_once 'Bcrypt.php';
class Mysql {
private ... | [] | [
{
"body": "<p>I've tried cleaning it up a bit here, removed instances of setting a variable once and using it directly below where it was set (yes, improves readability, but still). </p>\n\n<pre><code>require_once 'Bcrypt.php';\n\nclass Mysql {\n private $conn;\n private $host = 'host';\n private $d... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T19:37:26.827",
"Id": "16209",
"Score": "5",
"Tags": [
"php",
"sql",
"mysql",
"pdo"
],
"Title": "PHP Login Authentication with BCrypt"
} | 16209 |
<p>I'm a complete PHP beginner and would like some feedback on this registration page I've created. Now, the one thing I know right off that bat that's wrong with it is that there's WAY too much commenting. This was for my benefit to help teach myself as I went along and help avoid confusion as I read back through my ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T20:57:48.890",
"Id": "26383",
"Score": "3",
"body": "Try to separate your PHP and HTML code as much as possible. Also, move away from the old MySQL code (`mysql_query` etc) and towards using something like PDO. \n\n**ALSO** I notice... | [
{
"body": "<p>Ok, this is your form.php code - what the users browse to. I've dropped in comments within the code - and also notice the addition of <code>require_once('pre_header.php')</code> on <code>line 4</code>. This will contain the PHP code at the bottom. </p>\n\n<pre><code><?php\n/*Give all POST varia... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T20:49:54.693",
"Id": "16210",
"Score": "5",
"Tags": [
"php",
"beginner",
"mysql"
],
"Title": "Registration form with validation and avatar-uploading"
} | 16210 |
<p>I made a simple library to help me doing A/B tests in a web app. The idea is simple: I have two or more page options (URL) for a given page and every call to the library method should give me a URL so at the end all options were given the same traffic.</p>
<p>My questions are: </p>
<ul>
<li>Is this 100% thread saf... | [] | [
{
"body": "<p>This part is not thread safe:</p>\n\n<pre><code> lock (NextOption)\n {\n NextOption = new Hashtable();\n }\n</code></pre>\n\n<p>The problem is that the object being used to synchronize is re-assigned. That means a subsequent caller will acquire a different lock.</p>\n\n<p>It's con... | {
"AcceptedAnswerId": "16238",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T21:08:31.997",
"Id": "16211",
"Score": "5",
"Tags": [
"c#",
"multithreading",
"thread-safety"
],
"Title": "Library for doing A/B tests in a web app"
} | 16211 |
<p>This is an ordinary data processing task: read a list of dates and amounts (for example, deposits and withdrawals from a bank account) and report the date on which the lowest balance was recorded and what that balance was. While I do get the correct answer--always a virtue--with the code below, I can't help thinking... | [] | [
{
"body": "<ul>\n<li>recursive part of <code>minBal</code> is <code>mapM_</code></li>\n<li>multiple <code>get</code> is better to refactor into one</li>\n<li><code>get</code> - process - <code>put</code> part of <code>minBal</code> is <code>modify</code></li>\n<li>state monad is not necessary - you can use plai... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T21:58:21.837",
"Id": "16212",
"Score": "4",
"Tags": [
"haskell",
"homework"
],
"Title": "Ordinary Data Processing Task in Haskell: Vague Misgivings"
} | 16212 |
<p>Is there any problem in checking PHP PDO connection this manner?</p>
<p>Is this way reliable?</p>
<pre><code>function pdo_mysql()
{
$mysql_string = "xxxxxxxxxxx";
$mysql_user = "xxxxxxxxxxx";
$mysql_pass = "xxxxxxxxxxx";
try
{
$pdo_mysql = new PDO( $mysql_string, $mysql_user, $mysql_pass );
$pdo_mysql-&g... | [] | [
{
"body": "<p>I'm not quite sure I see the purpose of this function.</p>\n\n<p>It essentially checks if a PDO connection is possible. It does not actually return a connection. In addition to that, it has hard coded credentials, thus killing all flexibility. Also, there's no evident reason why you made it MyS... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T23:53:26.110",
"Id": "16213",
"Score": "5",
"Tags": [
"php",
"mysql",
"pdo"
],
"Title": "Is there any problem in checking PHP PDO connection this manner?"
} | 16213 |
<pre><code>var EVENT_TYPE = "touchstart" // Global Event Type
var H = 360,
S = 1.0,
V = 1.0
var randomColorsList = [],
staticColorsList = [
[r = 255, g = 56, b = 30],
[r = 22, g = 20, b = 32],
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T04:27:27.723",
"Id": "26389",
"Score": "3",
"body": "Care to tell us what the code does? And, perhaps focus your question on one particular piece of code rather than several pages of code?"
}
] | [
{
"body": "<p>You are using a variable named <code>i</code>, but I don't see it being declared(<code>var i</code>). This might cause problems. Same with your RANDOM/STATIC color constants:</p>\n\n<pre><code>var INIT_RANDOM_COLORS = 0,\nMAX_RANDOM_COLORS = 15,\nINIT_STATIC_COLORS = 0,\nMAX_STATIC_COLORS = ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T02:53:03.757",
"Id": "16216",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "Buttons and Random Colours"
} | 16216 |
<p>I'm working on a project in which the previous programmer seems to have loved using the AS keyword in the SELECT part of queries. I really don't like how it's written but if there is no performance difference I won't change existing code.</p>
<p>My tests did give a slight advantage to not using the AS keyword but I... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T13:09:18.930",
"Id": "26399",
"Score": "2",
"body": "Since you are only changing the metadata, i.e. the name of the returned columns, it doesn't affect each row as it is processed. I'd expect the overhead to be inconsequential."
... | [
{
"body": "<p>I wouldn't expect much if any noticeable overhead as all that is doing is aliasing the name of the column in the result set.</p>\n\n<p>The question I would ask however, is <em>why it's being done in the first place?</em> All I can think of is to prevent the code which uses the query breaking if a ... | {
"AcceptedAnswerId": "16235",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T08:55:15.337",
"Id": "16219",
"Score": "1",
"Tags": [
"performance",
"mysql",
"sql"
],
"Title": "Is there a performance difference using AS keyword in SQL?"
} | 16219 |
<p>I'm working now on project, which is need some <strong>read more</strong> functionality and I tried to write this jquery plugin and <a href="https://github.com/matmuchrapna/jquery.readmore/blob/master/jquery.readmore.js" rel="nofollow"><strong>share</strong></a> it in my github account.</p>
<p>Here is the full list... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T09:59:37.730",
"Id": "26395",
"Score": "0",
"body": "Is splitting on sentences really what you need? Other options are word count, letter count(but round on words), lines(use line-height * lines, is tricky) And in all cases I would ... | [
{
"body": "<p>The code is good, only a few ignorable pointers : </p>\n\n<ul>\n<li><p>lowerCamelCase is the standard for JavaScript, so</p>\n\n<ul>\n<li><code>get_link</code> -> <code>getLink</code> </li>\n<li><code>get_first_p</code> -> <code>getFirstParagraph</code></li>\n<li><code>readmore</code> -> <code>rea... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T09:37:28.977",
"Id": "16222",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "jquery.readmore plugin"
} | 16222 |
<p>Following is a chunk of code from my class which generates PDF documents. I am refactoring my code and in the process I have created short methods. But I have to pass 'table i.e PdfPTable' to my methods again and again. How can I avoid this?</p>
<pre><code>PdfPTable orgTable = new PdfPTable(2);
PdfPCell cell = null... | [] | [
{
"body": "<p>Make PdfPTable a property of the class and set it in the constructor.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T13:59:45.517",
"Id": "16226",
"ParentId": "16225",
"Score": "5... | {
"AcceptedAnswerId": "16226",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T13:23:43.093",
"Id": "16225",
"Score": "4",
"Tags": [
"c#",
"pdf"
],
"Title": "Class for generating PDF documents"
} | 16225 |
<p>I need to check the end of a URL for the possible existence of /news_archive or /news_archive/5 in PHP. The below snippet does exactly what I want, but I know that I could achieve this with one <code>preg_match</code> rather than two. How can I improve this code to treat the /5 as an optional segment and capture it ... | [] | [
{
"body": "<p>Consider your first pattern:</p>\n\n<pre><code>~/[0-9A-Za-z_-]+_archive/[0-9]+$~\n</code></pre>\n\n<p>Let's break it down:</p>\n\n<ol>\n<li><code>/</code> a literal string <code>/</code></li>\n<li><code>[0-9A-Za-z_-]+</code> one or more of <code>0-9</code>, <code>A-Z</code>, <code>a-z</code>, <cod... | {
"AcceptedAnswerId": "16240",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T16:48:23.673",
"Id": "16230",
"Score": "3",
"Tags": [
"php",
"regex"
],
"Title": "Capturing optional regex segment with PHP"
} | 16230 |
<p>This is my first jQuery plugin. It is a simple slider that requires very little mark up in html. It works for my purposes but I am not a jQuery expert and I am wondering if there are mistakes or shortcuts that I took in its creation.</p>
<p>Thank you for taking a look at the plugin!</p>
<h1>The HTML</h1>
<pre><... | [] | [
{
"body": "<p>Your code seems solid to me, only a few things my eye caught:</p>\n\n<ul>\n<li>you're using <code>$(this)</code> in multiple places, while your <code>sliderContainer</code> already holds that jQuery object. This object can be then reused instead of making jQuery convert DOM into jQuery several tim... | {
"AcceptedAnswerId": "16237",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T17:59:40.953",
"Id": "16236",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"plugin"
],
"Title": "Review my first jQuery slider plugin"
} | 16236 |
<p>I'm starting to learn how to meld the worlds of C and Haskell. Looking for any feedback on this first function.</p>
<p>The function takes in a pointer to an array of unsigned chars and returns a pointer to 32 unsigned shorts. Or at least I would like it too :).</p>
<p>I am unsure about when the memory used to retu... | [] | [
{
"body": "<p>First, you have way too many comments. They clutter the code, and some of them are completely redundant.</p>\n\n<pre><code>-- | Hash pointer to array of unsigned chars\nhash :: CInt -> Ptr Word8 -> IO (Ptr Word16)\n</code></pre>\n\n<p>The comment provides no information beyond the function'... | {
"AcceptedAnswerId": "16247",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T20:59:37.667",
"Id": "16243",
"Score": "2",
"Tags": [
"c",
"haskell"
],
"Title": "Calling a Haskell MD5 hashing function from C, and returning the result back to C land"
} | 16243 |
<p>So, I needed to make me a register script for my website so pepole can register, and just wanted to know if It's okey.
So, is there any vulns in this script i made?It works perfectly, just that i wanted to have someone to look over it here.
Or if there could be some inprovments that could make it better.</p>
<pre><... | [] | [
{
"body": "<p>Ok, there are a couple of things wrong with your code and your method of organizing the code. I've pointed them out to you in the code below within comments. The comments preceded with <code>#</code> are my comments. </p>\n\n<pre><code><?php\n\n/* Mysql data */\n$MysqlUsername = \"root\";\n$Mys... | {
"AcceptedAnswerId": "16376",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T23:15:02.667",
"Id": "16246",
"Score": "4",
"Tags": [
"php"
],
"Title": "User register script PHP"
} | 16246 |
<p>The following is my wordsearch solving algorithm. I'd greatly appreciate tips on how to improve it (e.g. improve efficiency, better approach, etc.):</p>
<pre><code>public boolean traverse(Grid grid) {
for (int r = 0; r < grid.getRows(); r++) {
for (int c = 0; c < grid.getCols(); c++) {
... | [] | [
{
"body": "<ul>\n<li>You are creating lots of Point() objects. For performance optimization in Java the very first thing is to avoid pressure on the garbage collector.</li>\n<li>You are doing lots of repeated calculations just for traversing the grid (in several directions). Performance wise it would be much be... | {
"AcceptedAnswerId": "16293",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T01:20:30.190",
"Id": "16252",
"Score": "2",
"Tags": [
"java",
"optimization"
],
"Title": "Word Search solving algorithm"
} | 16252 |
<p>I have the below function, it is designed so I can call:</p>
<pre><code>$object->temp('one', 1); //add the key `one` to the temp array with value 1
$object->temp('two', 2); //add the key `two` to the temp array with value 2
$object->temp('three', 3); //add the key `three` to the temp array with valu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T09:16:28.950",
"Id": "26435",
"Score": "0",
"body": "What is you actual reasoning to not split it into different functions? It would be much more readable to future coders. Depending on your object you could even use overloading htt... | [
{
"body": "<p>Here's one way to do it</p>\n\n<pre><code>public function temp($key = null , $value = null) {\n $args = func_get_args();\n if( count($args) === 2 ) {\n $this->temp[$key] = $value;\n } elseif( count($args) === 1 ) {\n return @$this->temp[$key];\n } else {\n re... | {
"AcceptedAnswerId": "16263",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T06:55:14.207",
"Id": "16257",
"Score": "2",
"Tags": [
"php"
],
"Title": "Single function to read one, read all, or set"
} | 16257 |
<p>I sat down to write a demo HTML5-ish page that lets a user to perform following operations on a canvas - draw lines, draw a filled rectangle, and reset the canvas. Each operation is represented by a button, clicking on which the operation is carried out.</p>
<p>My initial attempt ended up as a mingled HTML and Java... | [] | [
{
"body": "<p>The second one is indeed \"better\", in my opinion. Although, \"better\" is a bit hard to define when both versions work. \"More maintainable\" might be a more precise way of putting it.</p>\n\n<p>I might take it a step further, and add a constructor (i.e. class) that wraps the canvas element:</p>... | {
"AcceptedAnswerId": "16264",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T10:23:25.883",
"Id": "16259",
"Score": "2",
"Tags": [
"javascript",
"comparative-review",
"html5",
"canvas"
],
"Title": "Two JavaScript snippets to allow drawing on a canva... | 16259 |
<p>I have this function in my application that I need to simplify in order to improve the code quality:</p>
<pre><code>void FilterValues()
{
List<SecondaryStockRoomDefenition> GridViewItems = new List<SecondaryStockRoomDefenition>();
GridViewItems = StockRooms.ToList();
if (cbo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T17:45:15.573",
"Id": "26798",
"Score": "1",
"body": "One tiny point: you may consider either switching your \"\"s with string.Empty, or (better yet) changing the checks to string.IsNullOrEmpty(string)/string.IsNullOrWhiteSpace(strin... | [
{
"body": "<p>Just a few things from me:</p>\n\n<ol>\n<li><p>Check the way you name variables. Local variables by defacto standard are lower case camel. See here for more details <a href=\"http://msdn.microsoft.com/en-us/library/xzf533w0%28v=vs.71%29.aspx\" rel=\"nofollow\">Microsoft naming conventions</a>.</... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T11:43:39.293",
"Id": "16262",
"Score": "6",
"Tags": [
"c#"
],
"Title": "Filtering values for GridViewItems"
} | 16262 |
<p>I have a N*N upper triangular matrix with property such that, all its diagonal elements are a1,a2,a3,...,aN. I want that a[i][j] (for all j>i) should be</p>
<pre><code>(a[i][j-1] + a[i+1][j]) / 2.
</code></pre>
<p>I have many test cases, and I have to apply this property every time to calculate the answer. What is... | [] | [
{
"body": "<p>I suggest dropping the floating point and doing it fixed point. To do this I\nwould make <code>a[][]</code> of type <code>int</code> or <code>short</code> (depending upon the input\nconstraints) and instead of storing values x and x * 0.5, store 2x and x\nrespectively. At the end of the summatio... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T13:04:28.800",
"Id": "16265",
"Score": "10",
"Tags": [
"c",
"algorithm",
"matrix",
"floating-point"
],
"Title": "How to increase efficiency of matrix operation in C?"
} | 16265 |
<p>I am learning Java Collections Framework. Can someone look at this code for <em>generating all subsets of a given set</em> and tell me any issues with it.</p>
<pre><code>import java.util.*;
public class AllSubsets {
public static void main(String[] args) {
Set<Integer> original = new HashSet<In... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T17:47:18.867",
"Id": "26446",
"Score": "0",
"body": "you use vague algorithm, so no one wish to decrypt and and thus you received no answer. To represent a subset, usually an integer in binary representation is used: 0 in a given po... | [
{
"body": "<p>The first, obvious, issue is that generating the set in memory uses a lot of memory. However, making a lazy version is a bit more advanced, so don't worry about it for now.</p>\n\n<h3>1. Code to the interface, not the implementation</h3>\n\n<pre><code>public static HashSet<HashSet<Integer>... | {
"AcceptedAnswerId": "16270",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T13:18:02.567",
"Id": "16267",
"Score": "3",
"Tags": [
"java",
"collections",
"combinatorics"
],
"Title": "Generating all subsets of a given set"
} | 16267 |
<p>I defined the class <code>Rectangle</code>:</p>
<pre><code>class Rectangle
attr_reader :b, :h
def initialize(b, h)
@b = b
@h = h
end
def area
@b*@h
end
def to_s
"Rectangle #{@b}x{@h}"
end
end
</code></pre>
<p>and its subclass <code>Square</code>:</p>
<pre><code>class Square < Rect... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T00:19:52.773",
"Id": "88673",
"Score": "1",
"body": "Don't close questions if you can migrate them to SO!"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2018-10-11T16:08:16.840",
"Id": "396268",
"Score"... | [
{
"body": "<p>First off, why bother with a separate <code>Square</code> class?</p>\n\n<p>Personally, I'd make a <code>Rectangle</code> class' <code>to_square!</code> method simply set both width and height to <code>Math.sqrt(area)</code>. The result is still a <code>Rectangle</code>, just a square one.</p>\n\n<... | {
"AcceptedAnswerId": "16284",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T13:20:41.093",
"Id": "16268",
"Score": "0",
"Tags": [
"ruby",
"casting"
],
"Title": "(sort of) casting types in Ruby: changing class of an instance"
} | 16268 |
<p>I think this code to parse a contrived message protocol with first byte data length followed by data is a little ugly. Has anyone got any suggestions on how to make it more elegant and more robust?</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LENGTHBYTES 1
v... | [] | [
{
"body": "<p>Below is an alternative example of how messages could be extracted. Instead of a state machine with saved-state inside your splitmessages function, I have moved the saved-state out of the function into a structure that is passed-in. I have also checked for unexpected data at the start of the fu... | {
"AcceptedAnswerId": "16496",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T15:55:49.017",
"Id": "16269",
"Score": "3",
"Tags": [
"c",
"parsing"
],
"Title": "Parse a contrived message protocol with first byte data length followed by data"
} | 16269 |
<p>I have two different set of checkboxes. With the coffescript code below I set the maximum amount of checkable items at 3. I would like to refactor this code, to be cleaner and compact, but I can't get it.</p>
<pre><code>$("div.feature_list :checkbox").click ->
if $("div.feature_list :checked").length >= 3
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T19:17:42.773",
"Id": "26452",
"Score": "1",
"body": "FYI, to enable/disable a button use `.prop('disabled', true_or_false)` instead of setting the attribute."
}
] | [
{
"body": "<p>Step 1: DRY. Encapsulate the \"limit checkboxes\" behavior in a function</p>\n\n<pre><code>limitCheckboxesIn = (container, limit = 3) ->\n checkboxes = $(container).find \":checkbox\"\n checkboxes.on \"click\", (event) ->\n checked = checkboxes.filter \":checked\"\n unchecked = che... | {
"AcceptedAnswerId": "16274",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T19:16:13.827",
"Id": "16271",
"Score": "2",
"Tags": [
"jquery",
"coffeescript",
"jquery-ui"
],
"Title": "Refactor jquery (coffescript) code with checkboxes"
} | 16271 |
<p>This code works fine, but I just don't like all the <code>if else</code>. If I keep adding field to filter, it's going to get messy.</p>
<p>I am not using EF and cannot on this.</p>
<p>Controller code:</p>
<pre><code>var books = bookRepository.GetDogs();
if (!String.IsNullOrEmpty(searchString))
{
if (!S... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T20:38:02.237",
"Id": "26453",
"Score": "0",
"body": "I only ever use the lambda syntax so I might be wrong but isn't `var books = from b in bookRepository.GetDogs() select b;` equivalent to `bookRepository.GetDogs()`?"
},
{
... | [
{
"body": "<p>Just put <code>if</code>, not <code>else if</code> so you can have a cumulative multi criteria search, and one condition in every <code>if</code>.</p>\n\n<p>So every condition is easy to read, and if more than one criteria is filled, they will cumulate fine.</p>\n\n<pre><code>if (!String.IsNullOrW... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T15:12:10.557",
"Id": "16275",
"Score": "4",
"Tags": [
"c#",
"linq",
"asp.net-mvc-3",
"controller"
],
"Title": "Search and filter in MVC3 Razor using Linq"
} | 16275 |
<p>I have the following which searches my graph to see if a vertex is reachable from the first vertex, which everything should be connected to. I do this to ensure there are no disconnected parts.</p>
<p>Unfortunately it is very slow.</p>
<p>Is there something I could do or store to optimize this?</p>
<p>I want to l... | [] | [
{
"body": "<p>Rather than using recursion (which is pretty slow), you can for this using a Set of all reachable nodes, and a Queue of nodes you still haven't searched. This is a basic implementation of Breadth-First Search.</p>\n\n<pre><code>private boolean isNodeReachableFrom(GraphNode start, GraphNode target... | {
"AcceptedAnswerId": "16280",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T20:36:34.040",
"Id": "16278",
"Score": "2",
"Tags": [
"java"
],
"Title": "Can this graph search be optimized?"
} | 16278 |
<p>I started porting an API wrapper from Java to Python for practice. I am looking for ways to improve the readability/maintainability this code.</p>
<p>I have done some reading about "pythonic" style and I am hoping someone could provide some feedback as to how one goes about making their code more pythonic.</p>
<p>... | [] | [
{
"body": "<p>Depends on your definition of \"pythonic\", if you haven't already check out already <a href=\"http://www.python.org/dev/peps/pep-0020/\" rel=\"nofollow\">PEP 20</a>, \"The Zen of Python\" gives some good pragmatic guidelines and <a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\... | {
"AcceptedAnswerId": "16287",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T21:22:28.560",
"Id": "16282",
"Score": "4",
"Tags": [
"python",
"parsing",
"api",
"python-2.x"
],
"Title": "Python wrapper for the Help Scout API"
} | 16282 |
<p>What does this script tell you about how I need to improve as a programmer? I'm somewhat new to both Python and programming, so feel free to minimize your assumptions about my knowledge. </p>
<p>The purpose of this script is to read a .csv of names and emails addresses that are improperly organized -- sometimes th... | [] | [
{
"body": "<h3>Design</h3>\n\n<p>As far as I can tell, what you are actually trying to do is to clean up a CSV file so that it has five fields (title, first name, middle name, last name, and e-mail address), by applying a sequence of heuristics. You then allow the caller to specify flags to turns these heuristi... | {
"AcceptedAnswerId": "16309",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-07T04:05:44.753",
"Id": "16290",
"Score": "6",
"Tags": [
"python",
"optimization",
"performance",
"csv"
],
"Title": "Script that scrubs data from a .csv file"
} | 16290 |
<p>This is the way I handle an Ajax response. I am sure it can be improved.</p>
<pre><code>success: function (json) {
$.each(json, function(index,item){
if (item.field == "article_id") {
$("#article_id").val(item.value);
... | [] | [
{
"body": "<p>Maybe something like this?</p>\n\n<pre><code>success: function (json) {\n var decorators = {},\n handlers = {};\n\n // decorators prepare content for insertion\n decorators.naslov = stripslashes;\n decorators.tekst = stripslashes;\n\n // specialized handlers\n handlers.tag_title = func... | {
"AcceptedAnswerId": "16299",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-07T10:41:08.803",
"Id": "16294",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"ajax"
],
"Title": "jQuery Ajax response"
} | 16294 |
<p>I am currently reading <em>The C Programming Language</em> by Dennis Richie and Brian Kernighan, and I came to implement the function <code>squeeze (s1, s2)</code> as an exercise. <code>squeeze()</code> deletes each character in <code>s1</code> that matches any character in the string <code>s2</code>. While coding <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T13:57:32.127",
"Id": "26783",
"Score": "0",
"body": "Output 2 starts with a ',' not an 'm'"
}
] | [
{
"body": "<p>It would be better to iterate over both the strings only once. Create a third temporary variable, equal to size of first string, and copy characters one-by-one if no match is found in the second string.</p>\n\n<pre><code>char *squeeze (char *destination, char *source) {\n\n char * result = (cha... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-07T13:26:50.097",
"Id": "16301",
"Score": "7",
"Tags": [
"optimization",
"c",
"strings"
],
"Title": "Improving and optimizing squeeze() function"
} | 16301 |
<p>It's my first window program. It simply searches for a specified file in the whole computer.</p>
<p>File Search.h (header file that contains the prototypes of fileSearcher class methods.) </p>
<pre><code>#ifndef UNICODE
#define UNICODE
#endif
#include <Windows.h>
#include <queue>
namespace fileSearch... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-07T21:44:24.373",
"Id": "26488",
"Score": "0",
"body": "Are you against using a Thread pool?"
}
] | [
{
"body": "<p>A few points:</p>\n\n<ul>\n<li><p>Best Practice: There's no need to define <code>UNICODE</code> in <code>File Search.h</code> since it's defined at the top of those files that include it. Consider creating a configuration header that gets included by the <code>.cpp</code> first and let it handle t... | {
"AcceptedAnswerId": "16305",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-07T16:09:45.710",
"Id": "16303",
"Score": "5",
"Tags": [
"c++",
"windows"
],
"Title": "Review my file-searching program"
} | 16303 |
<p>I'm teaching myself Python via Zed Shaw's <a href="http://learnpythonthehardway.org/" rel="nofollow">LPTHW</a> and he suggested to me that I try to condense my code so I can call up bits of it within a function. Right now this is boggling my mind and I can't figure out a way to condense it that doesn't result in an ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-07T18:21:43.790",
"Id": "26484",
"Score": "2",
"body": "You've certainly noticed the amount of duplication in your. Start by looking at similar pieces of code, extracting what is variable and writing functions for those bits with the v... | [
{
"body": "<p>As you've discovered, <code>global</code>s are hard to deal with.</p>\n\n<p>Assuming that you now know what to do with your repeated code, here's one method of dealing with them.</p>\n\n<p>If we start with a function:</p>\n\n<pre><code>INV_GOLD = 9\n\ndef buy_offered_weapon( offered_weapon, price ... | {
"AcceptedAnswerId": "16321",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-07T17:56:08.897",
"Id": "16304",
"Score": "4",
"Tags": [
"python",
"console",
"adventure-game"
],
"Title": "Console weapons shop for adventure game"
} | 16304 |
<p>I need to merge two objects in a code path that is going to be heavily used. The code works, but I am concerned it is not optimized enough for speed and I am looking for any suggestions to improve/replace what I have come up with. I originally started working off an example at the end of this issue: <a href="https... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-08T15:20:44.957",
"Id": "26528",
"Score": "0",
"body": "Your code would be much easier to read if you used `continue` statements."
}
] | [
{
"body": "<p>I think the following is doing the same thing, you'll need to check it. It should be pretty fast, it just references objects that don't exist on the target. I changed names from <code>def</code> and <code>obj</code> to <code>target</code> and <code>source</code> because they make more sense to me.... | {
"AcceptedAnswerId": "16319",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-07T18:53:08.417",
"Id": "16306",
"Score": "7",
"Tags": [
"javascript",
"node.js"
],
"Title": "How to Optimize Merge of Two Objects That Include Arrays of Objects"
} | 16306 |
<p>I've been learning about Monte Carlo simulations on MIT's intro to programming class, and I'm trying to implement one that calculates the probability of flipping a coin heads side up 4 times in a row out of ten flips.</p>
<p>Basically, I calculate if the current flip in a 10 flip session is equal to the prior flip,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T23:59:44.497",
"Id": "26491",
"Score": "1",
"body": "Why is the priorFlip when you get Tails being set to Heads and why are you incrementing the consecCount? I'm not sure how this is going to give you the right probability?"
},
... | [
{
"body": "<p>So a few errors/simplifications I can see:</p>\n\n<ol>\n<li>You're incrementing <code>consecCount</code> if you have either two heads or two\ntails. </li>\n<li>setting the <code>priorFlip</code> value can be done regardless of what\nthe prior flip was </li>\n<li>Your <code>while</code> loop doesn'... | {
"AcceptedAnswerId": "16314",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-05T23:52:10.790",
"Id": "16310",
"Score": "5",
"Tags": [
"python",
"simulation",
"statistics"
],
"Title": "Monte Carlo coin flip simulation"
} | 16310 |
<p>I am trying to append data to a table based on the ajax returned data. </p>
<p>My codes work but it seems ugly. I was wondering if anyone here can help me
to simplfy it. Thanks a lot!</p>
<pre><code> ajax.callback=function(data){
for (var i=0; i<dataObj[0].data.length; i++){
var td=d... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T22:13:00.073",
"Id": "26515",
"Score": "0",
"body": "Store your tr's as one dom fragment and do not append them until after the for loop. Other than that, it's not going to be less ugly without using a templating system or having yo... | [
{
"body": "<p>You could do:</p>\n\n<pre><code>ajax.callback=function(data){\n var elements = [\"ID\", \"test\", \"year\", \"code\", \"Label\", \"contents\", \"test\"];\n\n for (var i=0; i<dataObj[0].data.length; i++){\n var td;\n var tr=document.createElement('tr');\n\n for (var j=... | {
"AcceptedAnswerId": "16323",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T22:08:19.153",
"Id": "16322",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"ajax"
],
"Title": "How to append ajax return data to a table"
} | 16322 |
<p>Can't seem to find one, so trying to build a very simple but fast implementation. Thought I would post on SO for review/feedback, and so that others can just copy/paste for their own use.</p>
<p>I'm using a Dictionary and LinkedList, with a non-granular lock. Basic benchmark included below:</p>
<pre><code>public ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T16:18:22.663",
"Id": "26522",
"Score": "0",
"body": "your lock sections are too big, also if the thread count goes up, two threads can enter `lock` at the same time. which breaks your correctness."
},
{
"ContentLicense": "CC... | [
{
"body": "<p>Another implementation is available <a href=\"http://csharptest.net/browse/src/Library/Collections/LurchTable.cs\" rel=\"nofollow\">here</a>.</p>\n\n<p>The benefit to the approach in the <code>LunchTable.cs</code> is that it does not aggregate an existing dictionary implementation, but rather is b... | {
"AcceptedAnswerId": null,
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-06T15:58:15.317",
"Id": "16326",
"Score": "9",
"Tags": [
"c#",
".net",
"collections",
"hash-map"
],
"Title": "Thread-safe LRU Dictionary in C#"
} | 16326 |
<p>Problem: Given a set of n distinct numbers, find the length of the longest monotone increasing subsequence.
For example, let's take this array <code>[1,2,9,4,7,3,11,8,14,6]</code>
The longest monotone increasing subsequence of this array is <code>[1,2,4,7,11,14]</code>. So the desired result is, the length of the ar... | [] | [
{
"body": "<p>Coding details</p>\n\n<ul>\n<li>You can initialize <code>list</code> like this : <code>int[] list = {1,2,9,4,7,3,11,8,14,6};</code> </li>\n<li><code>for (int j = 1, n = i-1; j <= n; ++j) {</code> // do not loop on limit calculation</li>\n<li>l<code>ength++;</code> // for <code>length = length +... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-08T17:47:29.300",
"Id": "16327",
"Score": "5",
"Tags": [
"java",
"algorithm"
],
"Title": "Java implementation of the longest monotone increasing subsequence"
} | 16327 |
<p>Current best practice for using a <code>lock_guard</code> looks like this:</p>
<pre><code>// introduce scope to take the lock
{
lock_guard lock(sync); // sync is an accessible mutex object
do_protected_stuff(); // may throw, but the mutex is released regardless
}
// no exception, mutex is released in... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-08T19:35:04.683",
"Id": "26540",
"Score": "0",
"body": "Microsoft has a paragraph [at the bottom of their `for loop` page](http://msdn.microsoft.com/en-us/library/b80153d8%28v=vs.71%29.aspx) describing how the compiler determines the s... | [
{
"body": "<h3>Comments on Design</h3>\n<p>I like the idea in general but usually when I introduce a lock in a scope, the scope is usually the whole method so it does not look that ugly:</p>\n<pre><code>void MyClass::myMethod()\n{\n lock_guard lock(sync); // sync is an accessible mutex object\n do_prot... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-08T18:29:39.727",
"Id": "16328",
"Score": "7",
"Tags": [
"c++",
"multithreading"
],
"Title": "Improve my little syntactic hack"
} | 16328 |
<p>I have the following class which is a tool for retrieving MD5 hashes of files that are input into it. They can potentially be very large files and I require cancellation and progress report, hence why i rolled my own solution rather than just passing in a filestream to <code>HashAlgorithm</code>.</p>
<p>I have a pr... | [] | [
{
"body": "<ol>\n<li><p>Before I address your specific issue directly, I'd like to suggest that you review <a href=\"http://msdn.microsoft.com/en-us/library/ms229002(v=vs.100).aspx\" rel=\"nofollow noreferrer\">MSDN's guidelines for C# naming conventions</a>, specifically with <a href=\"http://msdn.microsoft.co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-08T21:06:01.027",
"Id": "16331",
"Score": "8",
"Tags": [
"c#",
"multithreading",
"memory-management",
"asynchronous"
],
"Title": "Code works but memory usage is erratic"
} | 16331 |
<p>This is my first time working with classes and it's still unclear to me. I was wondering if someone can tell me if I did this right.</p>
<blockquote>
<p>Define a new class, Track, that has an artist (a string), a title
(also a string), and an album (see below).</p>
<ol>
<li>Has a method <code>__init__</c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T00:54:32.897",
"Id": "26563",
"Score": "3",
"body": "The `set_album` method is redundant and _unpythonic_: simply assign to the attribute directly in your code. If at any point in the future you need some more complicated behaviour ... | [
{
"body": "<p>In general, looks great! A few things:</p>\n\n<ol>\n<li>This relates to 'new-style' classes in Python - make sure that they inherit from <code>object</code>. It sounds like you are learning about classes now, so I will spare an explanation of what inheritance is since you'll eventually get to it.<... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-08T22:21:33.600",
"Id": "16332",
"Score": "5",
"Tags": [
"python"
],
"Title": "Music track class"
} | 16332 |
<p>I'm new to Python and would like some advice or guidance moving forward. I'm trying to parse Wikipedia data into something uniform that I can put into a database. I've looked at wiki parsers but from what I can see they are large and complex and don't get me much as I don't need 99% of their functionality (I'm not e... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-08T22:37:31.833",
"Id": "26548",
"Score": "1",
"body": "Just saying, a wiki parser is too complex, but a 200 line mega-function isn't? Sounds like you are reinventing the wheel here. Besides that, this would be more suited to Code Revi... | [
{
"body": "<p>Wikipedia pages have this great comment line-- <code><!-- Infobox begins --></code> to tell you where infoboxes start and end. Use that to find the information in the infobox.</p>\n\n<p>You end up with a string, lets call it <code>infobox</code>. </p>\n\n<pre><code># List Comprehension ove... | {
"AcceptedAnswerId": "16336",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-08T22:30:26.147",
"Id": "16335",
"Score": "5",
"Tags": [
"python",
"parsing",
"wikipedia"
],
"Title": "Parsing Wikipedia data in Python"
} | 16335 |
<p>Very simple I want to edit a virtual host files and replace the tags I made with some actual data:</p>
<pre><code>import os, re
with open('virt_host', 'r+') as virtual
file = virtual.read()
file = re.sub('{{dir}}', '/home/richard', file)
file = re.sub('{{user}}', 'richard', file)
file = re.sub('{{do... | [] | [
{
"body": "<pre><code>import os, re\n</code></pre>\n\n<p>Here, make sure you put a colon after <code>virtual</code></p>\n\n<pre><code>with open('virt_host', 'r+') as virtual:\n</code></pre>\n\n<p>Avoid using built-in Python keywords as variables (such as <code>file</code> here)</p>\n\n<pre><code> f = virtual... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T07:53:45.790",
"Id": "16341",
"Score": "3",
"Tags": [
"python"
],
"Title": "How to improve method of opening file in python then writing to another?"
} | 16341 |
<p>I've been studying hard and asking a lot of questions - I finally came a cross an exercise in LYAH that looked like it was easy enough but a perfect candidate for practicing.</p>
<p>The below program has a bunch of helper funcs in there, but the one of interest is <code>neighbors/3</code>. It takes a <code>Pair</c... | [] | [
{
"body": "<p>Run <code>hlint</code> tool on your source to help you with getting rid of redundant brackets, <code>$</code> and other minor suggestions.</p>\n\n<p>In <code>neighbors</code> your using of <code>guard</code> in list monad can be changed to <code>filter</code> function:</p>\n\n<pre><code>neighbors ... | {
"AcceptedAnswerId": "16370",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T08:13:49.190",
"Id": "16342",
"Score": "5",
"Tags": [
"haskell"
],
"Title": "Determine children within edge and return a list of tuple pairs"
} | 16342 |
<p><a href="http://en.wikipedia.org/wiki/Entity%E2%80%93relationship_model" rel="nofollow">Wikipedia Page for <strong>Entity-Relationship Model</strong></a></p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T10:22:28.827",
"Id": "16346",
"Score": "0",
"Tags": null,
"Title": null
} | 16346 |
An ERM (Entity–Relationship Model) is an abstract model of a relational database. Diagrams created with ERM syntax are called entity-relationship diagrams. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T10:22:28.827",
"Id": "16347",
"Score": "0",
"Tags": null,
"Title": null
} | 16347 |
<p>At the moment I am using this to check a boolean property in sharepoint 2007 using C# and .Net Framework 3.5</p>
<pre><code>if (bool.Parse(listItem.Properties["Boolean Property"].ToString()) == false)
</code></pre>
<p>is there any better way of doing it ?</p>
<p><strong>Edit</strong></p>
<p>when my code try to c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T13:02:30.740",
"Id": "26582",
"Score": "0",
"body": "I explained some of the errors that your approach is likely to generate in my answer. My guess is it's either a `NullReferenceException` or a `FormatException`"
},
{
"Con... | [
{
"body": "<p>The <code>.Parse</code> methods will throw exceptions if the value is null, in a bad format, etc.</p>\n\n<p>I suggest always using the <code>.TryParse</code> methods instead:</p>\n\n<pre><code>bool val;\nif(!bool.TryParse(listItem.Properties[\"Boolean Property\"].ToString(), out foo)) {\n val =... | {
"AcceptedAnswerId": "16354",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T11:16:53.843",
"Id": "16349",
"Score": "3",
"Tags": [
"c#",
"sharepoint"
],
"Title": "Better way of parsing string to boolean"
} | 16349 |
<p>I've had some help designing my field boxes and I was hoping to get feedback on the code. The fields will increase in complexity which is why I thought to structure it this way (image upload fields, textbox with WYSIWYG controls etc.</p>
<p>CSS</p>
<pre><code>.error { height: 27px; background-color: red; margin-bo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T12:48:43.187",
"Id": "26580",
"Score": "0",
"body": "You should use [`<input type=\"email\" ...`](http://developers.whatwg.org/states-of-the-type-attribute.html#e-mail-state-%28type=email%29)."
}
] | [
{
"body": "<ol>\n<li><p>If the input with the <code>placeholder=\"Email\"</code> is actually an email address, then the <code>type</code> attribute should be set to <code>email</code>, not <code>text</code>. (Reference: <a href=\"http://www.w3.org/TR/html-markup/input.email.html\" rel=\"nofollow\">http://www.w... | {
"AcceptedAnswerId": "16355",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T11:50:12.307",
"Id": "16350",
"Score": "1",
"Tags": [
"html",
"css"
],
"Title": "HTML CSS Field Layout"
} | 16350 |
<p>I wrote my own exception class, deriving from <code>std::runtime_error</code> to have Error-IDs, timestamps and inner exceptions. It seems to work, but are there any drawbacks?</p>
<p>The only thing I see is the deep-copy in the copy-constructor, which is not efficient, when there are many nested exceptions. But ex... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T14:47:30.697",
"Id": "26602",
"Score": "0",
"body": "First glance: `innerException == NULL;` could be quite a nasty typo."
}
] | [
{
"body": "<p>Not all compilers support <code>#pragma once</code></p>\n\n<pre><code>#pragma once\n</code></pre>\n\n<p>There are C++ equivalent of most C libraries that put the appropriate interface into the standard namespace.</p>\n\n<pre><code>#include <time.h>\n\n// Prefer\n\n#include <ctime>\n</c... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T14:11:42.100",
"Id": "16357",
"Score": "6",
"Tags": [
"c++",
"exception"
],
"Title": "Self-implemented C++ exception class"
} | 16357 |
<p>I'm trying to get my head around object oriented programming, and I'm starting in JavaScript. I have put a working demo of my code on JSFiddle (<a href="http://jsfiddle.net/Grezzo/bhuac/" rel="nofollow">here</a>), but the class is below.</p>
<p>My main concerns are that as soon as the object is called with a constr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T16:05:39.087",
"Id": "26614",
"Score": "0",
"body": "Could you include code in the question, please? \"This site is for code reviews, which are hard to do when the code is behind a link somewhere out there on the internet. If you wa... | [
{
"body": "<p>It's a tricky one, since your class* doesn't really need any methods. Since its purpose is to decrypt a string, it makes sense to do that decryption straight away. Not much need to call any methods on the instantiated object afterwards.</p>\n\n<p>Besides, I don't see much that would make sense to ... | {
"AcceptedAnswerId": "16366",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T15:55:24.743",
"Id": "16361",
"Score": "2",
"Tags": [
"javascript",
"object-oriented",
"classes"
],
"Title": "Is this a good JavaScript class?"
} | 16361 |
<p>I have based my code off several tutorials which has culminated what I think is quite a complicated CSS layout. It has a docked footer. The sidebars are turned on dynamically in my template depending if there is content. The site is designed to work in the following scenarios:</p>
<h2>1 Column</h2>
<ul>
<li>No div... | [] | [
{
"body": "<h2>Drop HTML4 in favor of XHTML or HTML5</h2>\n\n<p>There is no reason to stay with HTML4 any longer. Go with HTML5 or XHTML.</p>\n\n<h2>Class and ID names</h2>\n\n<p>Are your class and ID abbreviations really necessary? <code>.tc1</code> doesn't say anything about what text color the class applies.... | {
"AcceptedAnswerId": "18509",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T16:10:02.697",
"Id": "16364",
"Score": "3",
"Tags": [
"html",
"css"
],
"Title": "Complex CSS layout - Docked Footer and Elastic Content"
} | 16364 |
<p>I am still learning OOP and I need a little help, I don't really know how to properly make this not look so terrible.</p>
<p>Any thoughts?</p>
<pre><code><?php
class Noti {
public static $app;
public static $user;
public static $url;
public static $result;
public static $data;
public s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T18:26:54.330",
"Id": "26624",
"Score": "2",
"body": "A couple of words on what the code is supposed to do would be appreciated. Otherwise it's pretty hard to say tell if the code's good or not. It's obviously something to do with no... | [
{
"body": "<p>Not sure why the properties are marked <code>public</code>, since they're overwritten each time <code>Noti::status()</code> is called. There's no real point in having external code access <code>Noti::$user</code>, for instance (external code can just call <code>Config::get()</code> if it wants the... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T18:20:00.567",
"Id": "16367",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"php5"
],
"Title": "PHP Simple OOP Class"
} | 16367 |
<p>What should I use to cache the result so that it takes less time to search? It currently takes a large number of minutes to complete 10000 test cases with range 1-99999999999999 (18 times 9 - the worst case), even though the search values have been hard-coded for testing purposes (1600, 1501).</p>
<pre><code>Set&l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T19:54:20.983",
"Id": "26632",
"Score": "1",
"body": "What's the purpose of `startRange` and `endRange`? Is that how you would normally pick numbers to search for in `set`, or are they for something else?"
},
{
"ContentLicens... | [
{
"body": "<p>If I'm right the following is the same:</p>\n\n<pre><code>final Set<Integer> set = new TreeSet<Integer>();\n//some logic to populate 1600 numbers\nfor (int cases = 0; cases < totalCases; cases++) {\n final String[] str = br.readLine().split(\" \");\n final long startRange = Lo... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T19:15:19.233",
"Id": "16369",
"Score": "3",
"Tags": [
"java",
"optimization",
"algorithm"
],
"Title": "Caching 1600 integers and searching from treeSet takes a lot of time"
} | 16369 |
<p>I have created a simple <code>ArrayList</code> with some methods from the actual <code>ArrayList</code> in Java.</p>
<p>I am testing this for mistakes, but I am learning Java and my tests are maybe not comprehensive.</p>
<pre><code>public class SJUArrayList<E> {
// Data fields
private E[] theData;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T21:45:49.150",
"Id": "26637",
"Score": "0",
"body": "[How do I address unchecked cast warnings?](http://stackoverflow.com/a/509115/843804)"
}
] | [
{
"body": "<ol>\n<li><p>Consider the following test case:</p>\n\n<pre><code>final SJUArrayList<String> list = new SJUArrayList<String>(4);\nlist.add(\"a\");\nlist.add(\"b\");\nlist.add(\"c\"); // theData contains the following: [a, b, c, null]\nlist.remove(\"c\"); // theData contains the following: ... | {
"AcceptedAnswerId": "16375",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T20:21:46.533",
"Id": "16371",
"Score": "5",
"Tags": [
"java",
"array"
],
"Title": "A simple ArrayList class in Java"
} | 16371 |
<p>I am making a stats page for my Android game, and I have never really used the Android XML layout stuff, so I'm sure things are a little messy and strange. The layout ends up looking pretty good, and I'm just seeing if I can remove some of the repetitive crap and maybe better understand some of the stuff I did that... | [] | [
{
"body": "<p>First of all I tried to change outer <code>TableLayout</code> to <code>RelativeLayout</code> and that's what I've got</p>\n\n<pre><code><?xml version=\"1.0\" encoding=\"utf-8\"?>\n<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n android:layout_width=\"fill... | {
"AcceptedAnswerId": "16397",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T20:54:15.403",
"Id": "16373",
"Score": "2",
"Tags": [
"android",
"xml"
],
"Title": "An XML stats page for my game"
} | 16373 |
<p>I'm implementing a variation of the SuperFastHash in VBA for use in Excel (32-bit version, so no LongLong available) to hash strings.</p>
<p>To get around the limitations of signed 32-bit Long values, I'm doing the addition and bit-shifting using Double types, and then converting from Double to Long in a way that t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T09:44:54.067",
"Id": "26665",
"Score": "0",
"body": "Have you considered using `Decimal` data type? From excel help `Decimal variables are stored as 96-bit (12-byte) signed integers scaled by a variable power of 10`. `Decimal` can ... | [
{
"body": "<p><strong>This is quite possibly the most clever VBA code I have ever seen.</strong></p>\n\n<p>There's not much room for improvement here, except a couple naming nitpicks:</p>\n\n<ul>\n<li>If that's what they stand for, functions <code>shr</code> and <code>shl</code> could afford to be called <code>... | {
"AcceptedAnswerId": "35473",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T22:13:33.910",
"Id": "16377",
"Score": "15",
"Tags": [
"algorithm",
"vba"
],
"Title": "How can I improve this 31-bit SuperFastHash implementation in VBA?"
} | 16377 |
<p>How should I make this more Ruby-like or just "better"?</p>
<pre><code>def password_format_is_valid?(submitted_password)
#Gets regular expression for password format validation from settings and applies it
regex = Regexp.new(Setting['global_admin.password_format_regex'])
if submitted_password =~ regex then
... | [] | [
{
"body": "<p>There is no need to write explicit <strong>return</strong> . You can omit it. Because in Ruby the result of last executed statement in your code is returned automatically.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T04:30:57.940",... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T22:22:08.607",
"Id": "16378",
"Score": "5",
"Tags": [
"ruby",
"validation"
],
"Title": "Validating a password format"
} | 16378 |
<p>I am trying to write a price calculator for proof reading using javascript. It works but I am sure that my code could be improved quite a bit. </p>
<p>The concept is as follows:</p>
<p>There are three factors affecting the price:</p>
<ul>
<li>word count</li>
<li>proof reading type</li>
<li>timeline (how quickly t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T20:24:30.387",
"Id": "26645",
"Score": "0",
"body": "Your calculation is not clear .. can you break it down to simple formula x + y etc ...."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T20:45:20.87... | [
{
"body": "<p>You repeat yourself alot. You always want to keep things DRY (don't repeat yourself). Look at your code. If you see sections that are similar but different in small ways combine the similarities.</p>\n\n<p>e.g. in your <code>hourBasisPrice</code> function you do the same thing for each switch o... | {
"AcceptedAnswerId": "16381",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-09T20:19:04.740",
"Id": "16379",
"Score": "4",
"Tags": [
"javascript"
],
"Title": "Calculate cost based on wordcount and hour basis"
} | 16379 |
<p>I threw this together for a web dev class I am taking at school and I thought I'd throw it up to see what criticism I could get on my JavaScript, design, whatever.</p>
<p>Bonus points if you can tell me how I can fix the bug with users clicking to quickly and more than two cards flipping at a time.</p>
<p>Disclaim... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-11T03:13:24.847",
"Id": "26728",
"Score": "0",
"body": "Always useful to send the code through [jshint](http://www.jshint.com) and see what warnings you get (I see a bunch of missing semi-colons and one implied global). Oh, and it's sp... | [
{
"body": "<p>Haven't had the time to go over all your code in detail, but here are a few ideas.</p>\n\n<p>Overall, my first suggestion would be to separate the various pieces into several more functions. Keep the HTML-manipulation (building, styling, flipping cards) separate from the more abstract parts (score... | {
"AcceptedAnswerId": "16491",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T05:43:47.067",
"Id": "16386",
"Score": "3",
"Tags": [
"javascript",
"html",
"game",
"css",
"playing-cards"
],
"Title": "How'd I do on this card matching game?"
} | 16386 |
<p>Gentlemen!</p>
<p>So what I have here is a function who's main purpose is to check whether an attribute exists and if so add it to another list for a maximum of 3 entries. The first item in the list should always be checked while the rest of the list should be inserted into the new list randomly.</p>
<p>ex:
Old ... | [] | [
{
"body": "<p>This method seems... odd... Why would you need to do this? Anyways, unimportant... Like I mentioned in the other review, the referenced parameters are unnecessary when you could more easily use, and put better use to, properties.</p>\n\n<p>Also, as I mentioned in that other review, there is room f... | {
"AcceptedAnswerId": "16412",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T06:08:52.037",
"Id": "16387",
"Score": "2",
"Tags": [
"php"
],
"Title": "PHP Random List"
} | 16387 |
<p>Gentlemen!</p>
<p>I am hoping to find a more efficient (less hairy) way to do the following code. </p>
<p>The public interface will call calculateListItemValue and pass the following variables</p>
<ul>
<li>$source_list: stdClass() with a structure similar to List JSON below.</li>
<li>$target_list: stdClass() wit... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T07:21:21.970",
"Id": "26710",
"Score": "0",
"body": "it is good to have algorithm along with the code, specifically when the code long."
}
] | [
{
"body": "<p>Well, first off, you should be wary of using referenced parameters. It sometimes makes legibility difficult, but in this case it is not even necessary. The method you are using these referenced variables in is private, therefore the class is the only thing that will ever use these values. Why not ... | {
"AcceptedAnswerId": "16409",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T06:42:20.417",
"Id": "16388",
"Score": "4",
"Tags": [
"php"
],
"Title": "PHP List Iteration"
} | 16388 |
<p>Here's a bit of one of my web forms which is reached by clicking on a link in a calendar. Based on what you click, you end up at this page with a different <code>QueryString</code>. Based on that <code>QueryString</code>, we hide/show and enable/disable controls related to actions associated with the <code>QuerySt... | [] | [
{
"body": "<p>For one thing, everything is just setting booleans. Condense down all those nested <code>if</code> blocks down into boolean statements and use good names, and it'll even make sense in \"plain English\".</p>\n\n<pre><code>protected void Page_Load(object sender, EventArgs e) {\n if (IsPostBack) r... | {
"AcceptedAnswerId": "16443",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T07:25:42.977",
"Id": "16391",
"Score": "2",
"Tags": [
"c#",
"asp.net",
"http"
],
"Title": "Calendar events based on user feedback"
} | 16391 |
<p>What is your opinion on method ordering?</p>
<p>Should it be public methods at the top followed by private methods?</p>
<p>or</p>
<p>Should it be linear order so that methods calling methods stack on top of each other?</p>
<p><strong>Which do you think is better for maintainability / readability?</strong></p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T19:20:18.337",
"Id": "26708",
"Score": "0",
"body": "I think this is slightly off topic but on a personal note, I tend to group my methods by public, private, protected regions. But everyone's different and probably comes down to t... | [
{
"body": "<p>I don't have strong feelings, but I keep methods in calling order. The argument for \"public up top\" seems to be that someone wants to see what methods they can call on an Object as opposed to what a particular method does. However in today's world, this is generally accomplished by an IDE or j... | {
"AcceptedAnswerId": "16417",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T10:21:32.763",
"Id": "16395",
"Score": "0",
"Tags": [
"java"
],
"Title": "Method Ordering - Readability / Maintainability"
} | 16395 |
<p>I have a node template that grabs fields from a content type.</p>
<p>In the node--[contenttype].tpl.php file I have two sections (The second is html/php and grabs variables from the first section or from the content type and simply displayed it).
The first is strictly php and does three things:</p>
<ol>
<li>Grabs... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T13:53:14.047",
"Id": "26684",
"Score": "0",
"body": "According to the FAQ, you should include any pertinent code. If, as this question appears, your question is not about code, or is an abstract question about how best to do somethi... | [
{
"body": "<p>I can't speak specifically to Drupal as I have never used it before. But the following should be helpful in any situation. In order to best answer your specific questions I'm going to have to go through this line by line, which means I need to decipher your code first. Since I'm having to do so an... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T11:05:28.480",
"Id": "16398",
"Score": "3",
"Tags": [
"php",
"drupal"
],
"Title": "Drupal: Placing Code (PHP) within the Drupal System (as well as css)"
} | 16398 |
<p>I'm using twitter mobile and I have a login-dialog. login-Dialog is a modal dialog. To call it the user calls <code>loginDialog.show();</code></p>
<p>I'm not all that comfortable with the coding style I've adopted (i'm very much self schooled in JavaScript) and I'd be interested to hear peoples opinions on the co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T13:47:14.673",
"Id": "26682",
"Score": "0",
"body": "Can't recommend using \"brace on new line\" in JavaScript. JS interpreters will insert a semicolon at the end of a line, if it \"thinks\" it's missing. I see you don't have a newl... | [
{
"body": "<p>First off, I'd retrieve all the elements right away, instead of running <code>$(...)</code> again and again:</p>\n\n<pre><code>var loginDialog = (function($) {\n var dialog, form, button, template;\n\n // Get the elements once, on page load\n $(function () {\n dialog = $(\"#login-dialog\");\... | {
"AcceptedAnswerId": "16402",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T11:13:38.057",
"Id": "16399",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"controller"
],
"Title": "Code structure for a login modal dialog."
} | 16399 |
<p>As I was working with .NET, I started wondering how I would implement the LINQ methods syntax in Javascript. So here is my first try; is there a more elegant, or more performant, way to write this code?</p>
<pre><code>// usage : the functions take a predicate function as input and modify the array accordingly
var ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T11:55:27.403",
"Id": "26670",
"Score": "0",
"body": "So you're rewriting [underscore.js](http://underscorejs.org/)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T12:07:15.573",
"Id": "26672",
... | [
{
"body": "<p>To clarify the use of your global variable \"collection\" as a namespace for your library, you should assign it directly to a value returned by your Immediately Invoked Function Expression:</p>\n\n<pre><code>var collection = (function(){\n ...\n\n function collection(array) {\n return new Col... | {
"AcceptedAnswerId": "16404",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T11:47:18.120",
"Id": "16400",
"Score": "4",
"Tags": [
"javascript",
"optimization",
"library"
],
"Title": "Code review for a collection manipulation tool in Javascript"
} | 16400 |
<p>I have just created my first jQuery plugin. I am looking to suggestions on how to improve it, leading to a code optimization.</p>
<pre><code>(function($) {
var plugin_name = 'W.jQuery.FieldEvents';
var name_space = 'wFieldEvents';
var methods = {
init : function(options) {
return this.eac... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-11T03:06:54.430",
"Id": "26727",
"Score": "3",
"body": "It's always useful to run the code through [jslint](http://jslint.org) or [jshint](http://www.jshint.com). For instance, both caught that `dialog_id` is not defined anywhere but u... | [
{
"body": "<p>You can refactor the init function.</p>\n\n<pre><code>init : function(options) {\n var defaults = {\n 'edit_button' : '',\n 'submit_button':'',\n 'error_message':'value not found'\n };\n options = $.extend({}, defaults, options);\n re... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T09:42:38.843",
"Id": "16401",
"Score": "6",
"Tags": [
"javascript",
"jquery",
"form",
"plugin"
],
"Title": "jQuery plugIn to manage forms"
} | 16401 |
<p>I have the following code that unfortunately is really slow:</p>
<pre><code>private void FilterSessionByDate()
{
SessionsFilteredByDate =
BusinessClient.Instance.Tracker.GetAllMilestonesInSessionObjects().Where(
i => i.CreatedDate >= GetFromDate() && i.CreatedDate <= GetToDate... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T15:36:20.747",
"Id": "26693",
"Score": "1",
"body": "Is that method `.GetAllMilestonesInSessionObjects()` lazy-loading, or does it get **all** Milestones from the DB and then the `.Where()` filters them?"
}
] | [
{
"body": "<p>If BusinessClient.Instance.Tracker.GetAllMilestonesInSessionObjects() is not returning IQueryable, you will be loading up all results from that method before applying the Where filters - on each iteration through the for loop. If that method really does what it says, then you are talking about tr... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T14:43:40.843",
"Id": "16405",
"Score": "7",
"Tags": [
"c#",
"performance",
"sql",
"linq",
"asp.net"
],
"Title": "Getting instant/better result instead of waiting at least ... | 16405 |
<p>I've got a code that is working in my environment.
Nevertheless it is pretty ugly.</p>
<p>This is what I am trying to do.
I get a selectbox from a side with a lot of city names.
I filter some names and push them into an array and hide them. The other ones are also pushed into an array, but shown.</p>
<p>Now I appe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T15:20:31.733",
"Id": "26692",
"Score": "1",
"body": "I suggest throwing your code at [JSLint](http://www.jslint.com/), and thinking about its suggestions."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-... | [
{
"body": "<p>Here's something that seems to work OK (<a href=\"http://jsfiddle.net/5V3hX/\" rel=\"nofollow\">here's a demo</a>)</p>\n\n<pre><code>jQuery(function ($) {\n var select = $(\"select[name=city]\"),\n defaults = select.children(\".default\"),\n others = select.children(\":not(.default)... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T14:53:33.687",
"Id": "16407",
"Score": "4",
"Tags": [
"javascript",
"jquery"
],
"Title": "hide/show options in selectbox"
} | 16407 |
<p>Writing my first ASP.NET Web API web service. Still learing the power of Linq as well. I feel like there is a more ideomatic way of doing this:</p>
<pre><code>public class StylesController : ApiController
{
private Entities db = new Entities();
// GET api/Styles
public IEnumerable<Style> GetStyle... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T17:20:31.490",
"Id": "26705",
"Score": "0",
"body": "From what I can see of this code, you are doing an AND operation. i.e. division = 1 AND year = 2012. Am I correct?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationD... | [
{
"body": "<p>Good layout and white space.</p>\n\n<p>Although the logic works, I think it is very confusing, and not overly obvious. At first glance, it the if statements are very confusing. I would also rename the variables to have an Id or Code to the end of them to keep naming consistent.</p>\n\n<p>I think... | {
"AcceptedAnswerId": "16428",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T16:19:06.643",
"Id": "16410",
"Score": "4",
"Tags": [
"c#",
"asp.net",
"web-services"
],
"Title": "ASP.NET Web API HTTP GET with optional parameters"
} | 16410 |
<p>I have a STI table and want to be able to render a collection using </p>
<pre><code>render @collection
</code></pre>
<p>with every elements of the collection using their own partial or, if they don't have one, the parent partial. You know, partial inheritance.</p>
<p>So I added to my parent model :</p>
<pre><co... | [] | [
{
"body": "<p>This actually looks pretty solid.</p>\n\n<p>Another approach would be to <strong>sub-class</strong> the <strong><a href=\"http://apidock.com/rails/ActionView/PartialRenderer\" rel=\"nofollow\">Renderer</a></strong> and make it responsible for retrieving the base classes' <code>to_partial_path</cod... | {
"AcceptedAnswerId": "33092",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T18:18:57.233",
"Id": "16415",
"Score": "5",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Rails partial inheritance hack"
} | 16415 |
<p>Is there a cleaner way to do the following?</p>
<pre><code>friend_ids = [1,2,3,4,5]
friendIDsQuery = ""
friend_ids.each_with_index do |friend_id, index|
friendIDsQuery += "SELECT id FROM test WHERE user_id = #{friend_id}"
if index != friend_ids.size - 1
friendIDsQuery += " INTERSECT "
end
end
</code></pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-11T10:42:01.403",
"Id": "26739",
"Score": "2",
"body": "you wrote Array#join by hand..."
}
] | [
{
"body": "<pre><code>query = friend_ids.map {|id| \"SELECT id FROM test WHERE user_id=#{id}\"}.join \" INTERSECT \"\n</code></pre>\n\n<p><em>Bam.</em></p>\n\n<p>Edit: Ok, well, not just <em>bam</em>. First of all, if you're using Rails, go with something like NewAlexandria's answer, because it doesn't involve ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T20:29:39.863",
"Id": "16418",
"Score": "2",
"Tags": [
"ruby"
],
"Title": "Cleaner Code for custom query"
} | 16418 |
<p>This code works, but I'm sure it isn't written according to "best practices" for closures. On the other hand, at least it's intuitive to me... </p>
<p>the taskRunner object runs functions on setTimeout, so as not to block the UI for too long. I'm breaking this function into chunks and running one chunk at a time.... | [] | [
{
"body": "<p>You could just bind to <code>stream</code> with <code>i</code> as a passed parameter, Though Im wondering why you are using <code>Array.prototype.push</code> when you could just use <code>stream.push()</code>, unless I've infered wrong, and stream isn't an array:</p>\n\n<pre><code>var tr = new tas... | {
"AcceptedAnswerId": "16424",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T20:26:28.593",
"Id": "16422",
"Score": "0",
"Tags": [
"javascript",
"image",
"closure"
],
"Title": "Processing image blocks using a task runner"
} | 16422 |
<p>I have created a simple array-based Stack class with some methods like the actual Stack in Java.</p>
<p>I am testing this for mistakes, but since I am learning Java, my tests may not be as comprehensive as they should.</p>
<pre><code>import java.util.*;
public class SJUStack<E> {
// Data Fields
priv... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T21:35:43.623",
"Id": "26803",
"Score": "4",
"body": "Other suggestion - try making this class actually implement the `Stack` interface."
}
] | [
{
"body": "<p><code>topOfStack</code> is always one less than size, so you don't need that variable. Just replace all instances with <code>size-1</code>. Similarly, <code>capacity</code> could be replaced with <code>theData.length</code>.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",... | {
"AcceptedAnswerId": "16464",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-11T02:54:33.433",
"Id": "16426",
"Score": "8",
"Tags": [
"java",
"array",
"homework",
"stack"
],
"Title": "Simple array-based Stack class in Java"
} | 16426 |
<p>How can I refactor this redundant code?</p>
<pre><code>$("#txtShippingAddressFullName").change(function () {
$("#txtBillingAddressFullName").val($(this).val());
})
$("#txtShippingAddress").change(function () {
$("#txtBillingAddress").val($(this).val());
})
$("#txtShippingPostalCode").change(function () {
... | [] | [
{
"body": "<p>Since I don't know your markup, I don't know for sure if this will work, but it might</p>\n\n<pre><code>$(\"input[id*=Shipping]\").change(function (event) {\n var billingId = this.id.replace('Shipping', 'Billing');\n $(\"#\" + billingId).val($(this).val());\n});\n</code></pre>\n\n<p>Basically, g... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-11T03:11:40.310",
"Id": "16427",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"form"
],
"Title": "Synchronizing billing fields with the corresponding shipping fields"
} | 16427 |
<p>The problem presented to me:</p>
<blockquote>
<p>Declare a two-dimensional array of ints in main. Write a method to read in the size of each dimension, allocate memory for the array and return it (DON'T DO THIS IN MAIN, BUT CALL THIS METHOD IN MAIN).<br>
Write another method to initialize each element to the su... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-11T07:53:12.153",
"Id": "26730",
"Score": "0",
"body": "are you sure that this is the expected format for printing the array?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T21:37:46.727",
"Id": "268... | [
{
"body": "<p>You need to read input (from the command line) using the Scanner class for the dimensions of the array. In this line, you chose 5 and 6:</p>\n\n<pre><code>int[][] array = new int[5][6];\n</code></pre>\n\n<p>Everything looks good except for that method (<code>getArray</code>). In that method, yo... | {
"AcceptedAnswerId": "16436",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-11T07:03:47.273",
"Id": "16432",
"Score": "5",
"Tags": [
"java",
"array",
"homework"
],
"Title": "Printing a 2D array"
} | 16432 |
<p>I am currently using this code, but I am pretty sure there is a better way of doing it:</p>
<pre><code>private string ReturnEmployeeName(string userName)
{
try
{
// Username coming is RandomDomain\RandomLengthUsername.whatever
string[] sAMAccountName = userName.Split('\\');
retur... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-11T09:36:33.510",
"Id": "26734",
"Score": "1",
"body": "If you're talking about catching exceptions, you should also show us your `catch` block."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-11T09:46:50.8... | [
{
"body": "<p>\"Fast\" is not too relevant here, since it's such a simple method.<br>\nAnd the canned response also applies: if you want to improve the speed, first do some benchmarking to know where the bottlenecks <strong>really</strong> are.</p>\n\n<p>But here my proposal of a better way:</p>\n\n<pre><code>p... | {
"AcceptedAnswerId": "16438",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-11T08:32:07.163",
"Id": "16437",
"Score": "4",
"Tags": [
"c#",
"performance",
"strings",
"error-handling",
"sharepoint"
],
"Title": "Splitting a string of random length"
} | 16437 |
<p>I am trying to write a generic JavaScript subroutine to set the periodicity in the week:</p>
<pre><code>var items = {"0": "none", "1":"Daily", "2": "Every weekday (Monday to Friday)", "3": "Weekly"};
</code></pre>
<p>I would like to improve this to make it more generic and readable if possible.</p>
<pre><code>var... | [] | [
{
"body": "<ol>\n<li>Use <code>prop()</code> instead of <code>attr()</code>.</li>\n<li>See the first point.</li>\n<li>You're declaring <code>var selectDay = function(idValue, element)</code>, your <code>element</code> argument is probably a typo? You don't need it.</li>\n<li>See the first point.</li>\n<li>Use <... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-11T11:59:14.120",
"Id": "16439",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"datetime"
],
"Title": "Setting periodicity in the week in Google Calendar"
} | 16439 |
<p>I've spent a few days making the transition from WinForms to WPF, and do not have much time for tutorials as the work needs to be done quickly. I was wondering if anyone could take a look at a sample of my code and point out any conventions that I'm missing (and that are commonplace in modern WPF usage). I've pick... | [] | [
{
"body": "<p>All in all, your code is quite well-structured. Here are a couple of suggestions for improvement:</p>\n\n<ol>\n<li><p>Consider moving your styles to a <em><a href=\"http://www.codeproject.com/Articles/35346/Using-a-Resource-Dictionary-in-WPF\">resource dictionary</a></em>:</p>\n\n<pre><code><Wi... | {
"AcceptedAnswerId": "16446",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-11T17:19:37.943",
"Id": "16445",
"Score": "11",
"Tags": [
"c#",
".net",
"wpf",
"xaml"
],
"Title": "Grid UI layout for a database"
} | 16445 |
<p>A question was asked over at math.SE (<a href="https://math.stackexchange.com/questions/200835">here</a>) about whether or not there are infinitely many superpalindromes. I'm going to rephrase the definition to a more suitable one for coding purposes:</p>
<blockquote>
<p><strong>Definition</strong>: A <em>super... | [] | [
{
"body": "<h1>Things you did well</h1>\n\n<ul>\n<li><p>You defined <code>i</code> within your <code>for</code> loops, and abided by the <a href=\"https://en.wikipedia.org/wiki/C99\" rel=\"nofollow\">C99 standards</a>.</p></li>\n<li><p>You used an external library instead of writing your (more likely inefficien... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-11T23:56:45.323",
"Id": "16451",
"Score": "12",
"Tags": [
"optimization",
"c",
"primes",
"palindrome",
"depth-first-search"
],
"Title": "Depth-first search method for searchi... | 16451 |
<p>I have two choices of implementing a method, the first one is a generic type where the client code does not have to cast</p>
<pre><code> public T GetControl<T>(string controlName) where T : Control
{
return (T)ControlManager.GetControl( controlName);
//I simplify the logic here, in my c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T08:31:33.890",
"Id": "26770",
"Score": "2",
"body": "I personally prefer the first but I've also often had a tendency to over-use generics (got a little excited when I first started using them) and have at times caused myself more g... | [
{
"body": "<p>In my opinion the generic method is better for two reasons. First, it's cleaner, both for the client calling it because they don't have to cast and for the process of casting because it is only done in one place. Secondly, the client that's asking for the control knows the type of the control in t... | {
"AcceptedAnswerId": "16461",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T03:11:14.510",
"Id": "16452",
"Score": "10",
"Tags": [
"c#",
"casting",
"generics"
],
"Title": "Cast inside the method or let the client code cast, which one is better?"
} | 16452 |
<p>I'm currently writing some code in PyQt4 that takes a value and a control and binds the value to the control. Once the user saves the form it will unbind all the values and save it back to a custom object (in this case <a href="http://www.qgis.org/api/classQgsFeature.html" rel="nofollow">QgsFeature</a>).</p>
<p>At... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T04:46:50.070",
"Id": "62825",
"Score": "0",
"body": "This post might help you [Pythonic way to avoid a mountain of if…else statements](http://stackoverflow.com/questions/5640598/pythonic-way-to-avoid-a-mountain-of-if-else-statements... | [
{
"body": "<p>To expand a little further on part of sky py's answer, you could try something like the following</p>\n\n<pre><code>class BaseControlHandler:\n def __init__( self, control ):\n self.control = control\n def bind( self, value ): \n raise SuitableException()\n def unbind( self ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T04:37:55.293",
"Id": "16454",
"Score": "5",
"Tags": [
"python",
"pyqt"
],
"Title": "Binding a value to a control"
} | 16454 |
<p>I don't like how this config has so much duplication. Any suggestions on how to at least shorten it somewhat? Normally we only have one server block as the staging server is separate from production, but the client has gotten their own server so we'll need to stage on that.</p>
<pre><code>upstream upgrade-release{
... | [] | [
{
"body": "<p>My little attempt basically takes items that are repeated and puts them into their own separate conf files and just include them into the main conf files. On my servers, I structure them as such:</p>\n\n<pre><code>global\n include1.conf\n include2.conf\n include3.conf\nsites-available\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T05:54:30.730",
"Id": "16457",
"Score": "2",
"Tags": [
"nginx"
],
"Title": "Staging/release nginx config"
} | 16457 |
<p>I've read a lot about using MVC in game development and it seems to be a good way (speaking of testing, code reusing, etc ...)</p>
<p>I created a XNA project and tried to implement MVC. But I'm not sure if I'm doing it right.</p>
<p>I seperated the game into three blocks:</p>
<ul>
<li>Renderers (the "View")</li>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T09:22:08.147",
"Id": "26773",
"Score": "2",
"body": "Please include code in the question. \"This site is for code reviews, which are hard to do when the code is behind a link somewhere out there on the internet. If you want a code r... | [
{
"body": "<p>To answer your questions, 1) I would make the World a singleton, therefore both eliminating the need for quite a few params and the need to put it as a static field somewhere. However, make sure that retrieving the instance is a lightweight method, because it will happen a lot.\n As for the gam... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T08:14:06.903",
"Id": "16460",
"Score": "22",
"Tags": [
"c#",
"game",
"mvc",
"xna"
],
"Title": "MVC in XNA game development - rudimentary MVC GameEngine"
} | 16460 |
<p>I've written the following function to parse a configuration file. I did my best to make it simple, but it's still over 30 lines and has too much indentation caused by a series of <code>if</code> statements.</p>
<p>Any suggestions make it easier to read are welcome.</p>
<pre><code>int
parse_config (FILE * conf_fil... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T14:15:52.463",
"Id": "26784",
"Score": "0",
"body": "Does it work? What is it supposed to do? Note that you have `init` called with `envz` and `envz_len` uninitialized, and the function falls off the end without a return value. Als... | [
{
"body": "<p>Rather than 'removing' <code>if</code>s, it may be better to move them around!</p>\n\n<p>But <em>please</em>, put <code>{}</code> for every <code>if</code>, even if it has only one statement (another if). It makes it a lot easier to read.</p>\n\n<ol>\n<li><p>Treat the <code>!is_comment</code> as a... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T10:07:21.707",
"Id": "16462",
"Score": "2",
"Tags": [
"c",
"parsing"
],
"Title": "Parsing a configuration file in C"
} | 16462 |
<p>It's common pattern when you need to assign a variable inside a block</p>
<pre><code>def query(sql)
logger.debug "Db: Executing query #{sql}"
result = nil
ts = Benchmark.realtime do
result = @db.exec sql
end
logger.debug "Db: Query completed in #{ts}"
result
end
</code></pre>
<p>Is there a more ele... | [] | [
{
"body": "<p>I am afraid your code cannot be simplified further due to the imperative nature of <code>Benchmark.realtime</code> (it would have been better if it also returned the result of the block). Anyway, I think the best solution is to abstract it and write a wrapper method. For example:</p>\n\n<pre><code... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T12:56:52.293",
"Id": "16465",
"Score": "2",
"Tags": [
"ruby"
],
"Title": "Assigning variables in a block"
} | 16465 |
<p>I'm binding a handler to the keyup event of all input and textareas in a document:</p>
<pre><code>$(document).on('keyup','input,textarea',$.debounce(600, editor.handleGlobalChange));
</code></pre>
<p>I don't want the handler to fire on a specific input field. So I want to unbind the keyup event:</p>
<pre><code>$(... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-13T05:33:55.667",
"Id": "26824",
"Score": "1",
"body": "Note that for the data-nokeyup solution the selector string should be `input:not([data-keyup]), textarea:not([data-keyup])`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [
{
"body": "<p>I'm still not 100% on JQuery yet, but why are you selecting the entire document? Just select the textareas and inputs, then use <code>not()</code> to remove the desired field from the selectors.</p>\n\n<pre><code>$fields = $( 'input' ).add( 'textarea' ).not( '#afield' );\n$fields.on( 'keyup', $.de... | {
"AcceptedAnswerId": "16473",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T12:59:32.387",
"Id": "16466",
"Score": "7",
"Tags": [
"javascript",
"jquery"
],
"Title": "Removing jQuery event handler from single element bound by delegate"
} | 16466 |
<p>I am trying to get into C stuff, and I thought it would be a good idea to try and implement a circular buffer.</p>
<p>I have defined my struct like this:</p>
<pre><code>typedef struct
{
int8_t* buffer;
int8_t* buffer_end;
int8_t* data_start;
int8_t* data_end;
int64_t count;
int64_t si... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T14:24:16.930",
"Id": "26785",
"Score": "0",
"body": "`RB_pop` does not check for an empty buffer and has no way of indicating that the buffer is empty."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-27T... | [
{
"body": "<p>This looks nice. It is very readable and is probably fast.</p>\n\n<p>Sometimes ring buffer wrap is implemented by using the following kind of remainder stuff and offsets:</p>\n\n<pre><code>end_offset = (end_offset + 1) % size;\n</code></pre>\n\n<p>But I like your way of doing it without offsets a... | {
"AcceptedAnswerId": "20517",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T13:13:02.070",
"Id": "16468",
"Score": "12",
"Tags": [
"c",
"circular-list"
],
"Title": "Circular RingBuffer"
} | 16468 |
<p>I'm trying to reproduce the Google Schemer (schemer.com) effect they use with their buttons for indicating a user wanting to do something/already doing something. I more or less got it replicated but it seems like the amount of code is a bit much.</p>
<p><a href="http://jsfiddle.net/m0nd/YzEAu/" rel="nofollow">JSFi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T17:05:54.463",
"Id": "26794",
"Score": "0",
"body": "The HTML and CSS seem fine at first glance, but the JS is indeed far too long and needs to be refactored and improved."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creatio... | [
{
"body": "<p>If we consider these two buttons a state machine, we see that there are six simple states (not including hover).</p>\n\n<ol>\n<li>\"want\" / \"did\"</li>\n<li>\"want again\" / \"did\" (active)</li>\n<li>\"want\" (active) / \"done\"</li>\n<li>\"want again\" / \"done\" (active)</li>\n<li>\"want aga... | {
"AcceptedAnswerId": "16490",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T16:49:25.777",
"Id": "16476",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Reproducing Google Schemer buttons effect"
} | 16476 |
<p>For questions about cryptographic concepts and protocols that do not involve a code review, consult <a href="https://crypto.stackexchange.com/help/on-topic">Cryptography SE</a>.</p>
<p>For trivial ciphers, <a href="/questions/tagged/caesar-cipher" class="post-tag" title="show questions tagged 'caesar-cipher'... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T17:24:16.733",
"Id": "16478",
"Score": "0",
"Tags": null,
"Title": null
} | 16478 |
Questions relating to cryptographic topics such as encryption/decryption and hashing. (Not for use with trivial ciphers.) | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T17:24:16.733",
"Id": "16479",
"Score": "0",
"Tags": null,
"Title": null
} | 16479 |
<p>I have this class that has these two methods that are so closely related to the each other. I do not want to pass the flags so I kept them separate. I was wondering if there is a way to rewrite it so that I do not have to repeat so closely!</p>
<pre><code> class Test extends Controller
{
public static ... | [] | [
{
"body": "<p>You have two methods, one is nonFormattedData and other one is formattedData.\nI don't see the arguments for formattedData are being used. </p>\n\n<p>The difference between these two methods are how the result is returned. formatdata method returns <code>array(\"data\" => $rs)</code> and nonFormat... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T17:27:45.357",
"Id": "16480",
"Score": "2",
"Tags": [
"php",
"php5",
"cakephp"
],
"Title": "methods in the class so close in what they do"
} | 16480 |
<p>I'm pretty new to JQuery, maybe a week's worth of experience, but I'm having a lot of fun so far. One of the things I thought I would give a shot is attempting to implement a custom CMS for my current project. And it's going fairly well. So well in fact, that I thought I would start adding some nifty little features... | [] | [
{
"body": "<p>I'd probably make an object with the various formatting functions, like:</p>\n\n<pre><code>var formatting = {\n addImage: function () { ... },\n bold: function () { ... },\n ...\n};\n</code></pre>\n\n<p>And then have an event handler like:</p>\n\n<pre><code>$( '#toolbar' ).on( 'click', 'a', fun... | {
"AcceptedAnswerId": "16494",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T21:04:50.230",
"Id": "16483",
"Score": "0",
"Tags": [
"javascript",
"jquery"
],
"Title": "Multi-Functional Event Delegate"
} | 16483 |
<p>I have the following code: </p>
<ol>
<li>The HTML part consist of two containers. Both containers have a list of hour and day weeks.</li>
<li>This code is used to manage these lists of inputs.</li>
</ol>
<p>The JavaScript code works but I am wondering if it is possible to improve it, because the JavaScript cod... | [] | [
{
"body": "<p>Considering the complexity of your GUI I'd say your code is already quite trim. If you wish to cut it down I'd go about simplifying the user interface, personally I found it confusing - but then again I am using it out of context.</p>\n\n<p>Whilst it's great from a code view point to reuse interfa... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T23:40:37.390",
"Id": "16492",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"datetime",
"underscore.js"
],
"Title": "Code to manage weekdays and hours"
} | 16492 |
<p>I wrote a class that uses RestSharp to access Rest and HTTP API web services. I tested it and it works however I was wondering if any changes could be made to it to make it better.</p>
<pre><code>public class RequestHandler
{
//Client to translate Rest Request intot HTTP request and process the result.
priv... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-13T01:04:42.273",
"Id": "26812",
"Score": "1",
"body": "I don't see where secret key and account id are used other than assigning them to read only fields in the class."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate"... | [
{
"body": "<p>Depend on the <code>IRestClient</code> interface rather than the <code>RestClient</code> implementation and make the field <code>readonly</code> as it is only set via the constructor:</p>\n\n<pre><code>private readonly IRestClient client;\n</code></pre>\n\n<p>Invert your dependancy on <code>RestCl... | {
"AcceptedAnswerId": "17534",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-12T23:56:09.163",
"Id": "16493",
"Score": "3",
"Tags": [
"c#",
"generics"
],
"Title": "Review of a generic request handler class (RestSharp)"
} | 16493 |
<p>This is a CodeEval challenge taken from <a href="https://www.codeeval.com/public_sc/41/" rel="nofollow">here</a>:</p>
<blockquote>
<p><strong>Challenge description:</strong></p>
<p>Imagine we have an immutable array of size N which we know to be
filled with integers ranging from 0 to N-2, inclusive. Suppos... | [] | [
{
"body": "<p>Apparently according to this post <a href=\"https://stackoverflow.com/questions/5965767/performance-of-stringtokenizer-class-vs-split-method-in-java\">String tokeniser performance</a> using indexOf is alot quicker (I personally have no idea on that front). So taking what the chap posted in his so... | {
"AcceptedAnswerId": "16500",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-13T04:40:02.600",
"Id": "16497",
"Score": "1",
"Tags": [
"java",
"programming-challenge"
],
"Title": "Array absurdity challenge"
} | 16497 |
<p>I would like to write a python or c++ function to print numbers like the following examples (with n as input parameter):</p>
<p>When n = 3, print:</p>
<pre><code>1 2 3
8 0 4
7 6 5
</code></pre>
<p>When n = 4, print:</p>
<pre><code>4 5 6 7
15 0 1 8
14 3 2 9
13 12 11 10
</code></pre>
<p>I have an answer in... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-13T14:37:28.987",
"Id": "26841",
"Score": "1",
"body": "Have no idea why this has been moved here. Much more suited to stack overflow. There are also many more people on SO that can help maybe you should rephrase the question."
},
... | [
{
"body": "<p>Using a 2D array to store the matrix, we can simplify the function greatly. This uses Python 2 syntax.</p>\n\n<pre><code>def print_matrix(n):\n mat = [[0]*n for _ in xrange(n)]\n\n k = 0 # value to write\n for level in reversed(xrange(n, 0, -2)):\n start = n/2 - level/2\n pr... | {
"AcceptedAnswerId": "16505",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-13T13:14:44.300",
"Id": "16503",
"Score": "10",
"Tags": [
"python",
"algorithm"
],
"Title": "Write a function to print numbers"
} | 16503 |
<p>Is my following (very basic) class considered good use for PDO integration?
Or is there a better, more efficient way?</p>
<pre><code>class Page {
public $title;
public $db;
public function __construct($title) {
$this->title = $title;
}
public function connect($host, $dbname, $usern... | [] | [
{
"body": "<p><strong>Unused properties</strong></p>\n\n<p>You shoult not set <code>$this->title</code> in the <code>__construct()</code> method unless you are planning on using it.It would be better if you set this value in the particular method that is planning on using this data.</p>\n\n<p><strong>Visibil... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-13T18:13:19.243",
"Id": "16506",
"Score": "2",
"Tags": [
"php",
"object-oriented"
],
"Title": "Basic Database Class with PDO functionality"
} | 16506 |
<p>I'm hoping that the more experienced devs here can help me improve these methods. I'm building a basic MVC framework for myself (as a learning project,) and I'd really appreciate your insights. Things I'm looking for specifically are:</p>
<ol>
<li><strong>Efficiency:</strong> can these methods be improved (particul... | [] | [
{
"body": "<p>Large wall of text incoming. Go to the bathroom, grab a drink, etc...</p>\n\n<hr>\n\n<p><strong>Try/Catch</strong></p>\n\n<p>The first thing I would refactor is your try/catch statement. Its just way too large, though that may just be the internal comments (which I'll get to next). Try blocks shou... | {
"AcceptedAnswerId": "17617",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-13T18:20:41.627",
"Id": "16507",
"Score": "5",
"Tags": [
"php",
"mvc",
"url-routing"
],
"Title": "The Router - dispatch after parseURL"
} | 16507 |
<p>I have a Windows-service and this service will connect to an ftp server and do download, upload, and rename operations.</p>
<p>My service runs every 30 seconds, so the ftp server will be busy during these operations.</p>
<p>My question is: is my code useful for this job? Because my download/upload/rename functions... | [] | [
{
"body": "<p>A few things:</p>\n\n<ol>\n<li><p>I would supply all the variables that you have hard coded into the method i.e. localPath, filename, ftp server, networkcredentials. Otherwise how can you re-use this method for other operations? </p></li>\n<li><p>I would probably avoid making the method static u... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-13T19:55:45.567",
"Id": "17506",
"Score": "3",
"Tags": [
"c#",
"ftp"
],
"Title": "Is this FTP download code useful?"
} | 17506 |
<p>I currently use setInterval and a wait flag to process this collection. Is there a cleaner way?</p>
<pre><code>var wait = false;
var processInterval = setInterval(function(){
if(!wait){
var currentVideo = videos.shift();
if(currentVideo){
wait = true;
validateSongById(c... | [] | [
{
"body": "<p>You're basically there, I would say. If the <code>validateSongById</code> function works as expected, it'll call its callback when it's done, and you then do it again for the next video.</p>\n\n<pre><code>function processVideos(videos, callback) {\n var results = [], i = 0;\n function proce... | {
"AcceptedAnswerId": "17512",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-13T23:22:49.473",
"Id": "17510",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"asynchronous"
],
"Title": "Processing a collection of objects, one at a time, with an asynchronou... | 17510 |
<p>What I can think of improving is:</p>
<ul>
<li>Show stack on screen to fail gracefully i.e. improved catch part of try..catch</li>
<li>Make the try part shorter to improve readability</li>
<li>Make imports with * to improve readability so you don't have to import the same package twice</li>
</ul>
<p>Source code:</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-14T01:53:21.897",
"Id": "27855",
"Score": "0",
"body": "You might want to consider putting some spacing and indentation around your code segments to make it easier for people to read."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<blockquote>\n <p>Make imports with * to improve readability so you don't have to import the same package twice</p>\n</blockquote>\n\n<p>I disagree with that:</p>\n\n<ul>\n<li><p>Most people use IDEs to develop and view Java code, and any half-decent IDE is able to \"fold\" imports to save screen re... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-14T01:09:31.213",
"Id": "17514",
"Score": "1",
"Tags": [
"java",
"search"
],
"Title": "Kindly review this class"
} | 17514 |
<p>Examples: </p>
<pre><code>char test1[] = " ";
char test2[] = " hello z";
char test3[] = "hello world ";
char test4[] = "x y z ";
</code></pre>
<p>Results:</p>
<pre><code>" "
" olleh z"
"olleh dlrow "
"x y z "
</code></pre>
<p>The problem:</p>
<blockquote>
<p>Reverse eve... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-14T05:01:04.830",
"Id": "27859",
"Score": "0",
"body": "I'd skip the spaces in the main loop, instead of having them in the start index calculations."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-15T00:17... | [
{
"body": "<p>If using C++ is an option for you (which your tags suggest), then you might consider using <a href=\"http://en.cppreference.com/w/cpp/algorithm/swap\"><code>std::swap</code></a> for swapping the characters. You might also want to use <a href=\"http://en.cppreference.com/w/c/string/byte/isspace\"><... | {
"AcceptedAnswerId": "17557",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-14T04:46:50.480",
"Id": "17517",
"Score": "8",
"Tags": [
"c",
"strings",
"interview-questions"
],
"Title": "Reversing every word in a string"
} | 17517 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.