body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I am currently writing a game in C++ and have some variables that I want to be accessible from everywhere. For the examples, I will have the shared variable as an object of the class <code>Input</code>.</p>
<p>At the moment I am implementing it like this:</p>
<p><strong>input.h:</strong></p>
<pre><code>#ifndef IN... | [] | [
{
"body": "<p><strong>Your doubt is correct, don't use global variables.</strong></p>\n\n<p>(Note: For this post, I mean <em>variable</em> in its true meaning, i.e. objects that may change.)</p>\n\n<p>I can't say for sure which technique is the correct one without seeing your code, but normally you want to pass... | {
"AcceptedAnswerId": "29133",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-29T13:54:01.423",
"Id": "29130",
"Score": "8",
"Tags": [
"c++"
],
"Title": "Is this code with global variables good practice?"
} | 29130 |
<p>I have a method that calls a "bridge" for <code>TraderMarketInfo</code>. When info is received, it checks if info <code>IsSet</code> and raises an event. I want to make this method async. C# .NET4.0 VS2012.</p>
<p>Original method:</p>
<pre><code>public void RequestMarketInfo()
{
TraderMarketInfo marketInfo = b... | [] | [
{
"body": "<p>You need to be very careful when making code like this multithreaded. Your implementation will compile, and will execute the <code>GetMarketInfoAll()</code> method on another thread, but it may not do what you want. There are at least two things to consider:</p>\n\n<ul>\n<li><p><strong>Synchroni... | {
"AcceptedAnswerId": "29158",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-29T16:18:09.850",
"Id": "29137",
"Score": "1",
"Tags": [
"c#",
".net",
"task-parallel-library",
"async-await"
],
"Title": "Converting a method to async"
} | 29137 |
<p>When creating multiple constructors, I usually do the following;</p>
<pre><code>public ConstructorName(int count)
{
this(count, 0);
}
public ConstructorName(String count)
{
this(Integer.parseInt(count), 0);
}
public ConstructorName(int count, int other)
{
// Do something here
}
</code></pre>
<p>Howev... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-29T19:24:40.703",
"Id": "45962",
"Score": "1",
"body": "The first option will be slightly more efficient. Less switching scopes = less time wasted unnecessarily popping stuff on and off the stack."
}
] | [
{
"body": "<p>If there is more than one way to construct an instance, then <em>static factory methods</em> backed by one private constructor, can really help readability, since they can be named differently.</p>\n\n<pre><code>Range halfOpen = Range.largerThan(5);\nRange closed = Range.between(7, 12);\n</code></... | {
"AcceptedAnswerId": "29147",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-29T18:12:13.423",
"Id": "29142",
"Score": "4",
"Tags": [
"java",
"constructor"
],
"Title": "Constructor Chaining in Java"
} | 29142 |
<p>In a simple webapp I have been using as a playground, I am playing with using rxjava to perform a number of operations in a reactive manner. I have been using reactivemongo to connect to my Mongo database, but I find that for anything more than a trivial CRUD operation I often end up trying to reduce a <code>Future... | [] | [
{
"body": "<p>It could be the case that using Scala.Rx's reactive variables simplify your use case since they propagate change state as they happen. In particular, chaining those smart Var's together might help you simplify the task. Please have a look at: </p>\n\n<p><a href=\"https://github.com/lihaoyi/scala.r... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-29T18:56:01.093",
"Id": "29145",
"Score": "2",
"Tags": [
"scala"
],
"Title": "rxjava observables and scala futures"
} | 29145 |
<p>I'm using Twitter Bootstrap and I'm working on a page that has several tabs that all have carousels in them (each with a ton of images) I've managed to write an AJAX script that pulls the images from a JSON file I've created (for one of the carousels). I'm planning on making similar JSON file for the rest, but what ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-29T20:57:22.840",
"Id": "45969",
"Score": "0",
"body": "When do you decide to load the AJAX? Is it when the user clicks on a link? Or when the page loads?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-31T... | [
{
"body": "<p>Depending on when you want to make the ajax request, you'll need to modify the first line of my example. Currently it just gets all of them. You might want to change it so that it gets only the div that was clicked, or whatever. Anyways here's one way you could do that:</p>\n\n<pre><code>$('div[id... | {
"AcceptedAnswerId": "29151",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-29T20:11:52.217",
"Id": "29150",
"Score": "2",
"Tags": [
"ajax",
"html5"
],
"Title": "Simplifying an ajax script in my HTML"
} | 29150 |
<p>I have a rather simple task in trying to extract keywords from <code>input.dat</code> which looks like:</p>
<pre><code>func1
{
yes true;
keyword123 (1.1 0 -0.3);
gamma (0 1 0);
dir (1 0 0);
func2
{
yes false;
keyword123 (1.1 0 -0.3);
... | [] | [
{
"body": "<p>This is how I would implement it:</p>\n\n<pre><code>#!/usr/bin/perl\nuse warnings;\nuse strict; \n\nmy $file = 'input.dat';\nopen my $IN, '<', $file or die $!;\n\nmy $uniq;\nwhile (my $line = <$IN>) {\n next unless $line =~ /^\\s*keyword123/;\n if (defined $uniq and $line ne $uni... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-29T23:47:21.210",
"Id": "29153",
"Score": "0",
"Tags": [
"regex",
"perl"
],
"Title": "Structured instructions for simple extraction script"
} | 29153 |
<p>I'm doing this in Hadoop Java where I'm reading a String. The string is huge that has been tokenized and put in an array. It has key-value pairs but they are not in any order. I want this order to be rigid so I can load that as a table. So in SQL, if I select a column (after loading this in a table), all the keys of... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-28T06:30:27.350",
"Id": "67669",
"Score": "0",
"body": "I notice that the indentation of your original post has been fixed manually; I have written a bookmarklet to do this automatically. Would you mind if I use the original version a... | [
{
"body": "<p>I'd put token names and positions in a <code>Map</code> like this:</p>\n\n<pre><code>Map<String, Integer> tokenIndexes = new HashMap<String, Integer>();\ntokenIndexes.put(\"token1\", 0);\ntokenIndexes.put(\"token2\", 2);\ntokenIndexes.put(\"token3\", 4);\n// ...\n</code></pre>\n\n<p>an... | {
"AcceptedAnswerId": "29156",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-29T23:56:21.573",
"Id": "29154",
"Score": "4",
"Tags": [
"java",
"algorithm",
"strings",
"hadoop"
],
"Title": "Efficient way to copy unordered String into ordered String"
} | 29154 |
<p>I'd like to get some feedback on whether this is idiomatic elisp, whether it's any good, and any small modifications that would be useful. Thanks</p>
<pre><code>(defun jump-to-register-other-window (register-name)
"Open a register in the other window if file"
;; Should also display register contents if registe... | [] | [
{
"body": "<p>The first things which jump into my face are the broken indentation and a dangling parenthesis. Please fix them, otherwise the code is not very readable.</p>\n\n<p>More to the point, I think it is better to replace the body with</p>\n\n<pre><code>(switch-to-buffer-other-window (register-buffer reg... | {
"AcceptedAnswerId": "29160",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T00:54:49.347",
"Id": "29157",
"Score": "1",
"Tags": [
"lisp",
"elisp",
"emacs"
],
"Title": "A small emacs-lisp snippet for opening a register in another window"
} | 29157 |
<p>I wanted to write the best implementation I could think of the following really, super simple and stupid <code>OOP</code> model in <code>php</code>.</p>
<p>
<pre><code>class Number {
private $number = false;
function __construct($n) {
if(is_int($n)) {
$this->number = $n;
}
... | [] | [
{
"body": "<p>Here's a few things that caught my eye:</p>\n\n<ul>\n<li>I'm assuming this is just a sketch of an unfinished class, or perhaps a learning excersize? As it stands, your class is unnecessary, and I would advise against using it. Since it just wraps a built in int, built in ints might as well be used... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T05:23:55.193",
"Id": "29162",
"Score": "1",
"Tags": [
"php",
"object-oriented"
],
"Title": "Review a simple PHP OOP model"
} | 29162 |
<p>I am practising recursion and have written the small code for summing a+b as below:</p>
<pre><code>#include <stdio.h>
int b=6;
static int cnt;
void main(void)
{
int a=9,sum;
sum=succ(a);
printf("Sum returned : %d\n",sum);
}
int succ(x)
{
cnt++;
return(cnt<=b ? succ(x+1) : x++);
}
... | [] | [
{
"body": "<p>First of all, <code>main</code> should be declared <code>int main</code>.</p>\n\n<p>Second, I would advise passing the <code>cnt</code> (which I have called <code>iteration_number</code>) as a parameter as well. Also, you should avoid using a global (<code>b</code>). If you define a helper functio... | {
"AcceptedAnswerId": "29168",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T08:48:58.440",
"Id": "29166",
"Score": "4",
"Tags": [
"c",
"recursion"
],
"Title": "Recursive a+b function"
} | 29166 |
<p>I had made some pages and they work but I'm not sure if I coded it in best way so I want your suggestions and ideas to make my code better.</p>
<p><code>connection.php</code></p>
<pre><code> <?php
$mysql_host = 'localhost';
$mysql_user = 'root';
$mysql_pass = 'root';
$mysql_da... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T08:49:40.280",
"Id": "46003",
"Score": "5",
"body": "First of all start using mysqli_* or PDO functions to wrok with database. Mysql_* functions are depracted as of PHP 5.5 and will be removed soon"
},
{
"ContentLicense": "C... | [
{
"body": "<p>Ok, where to start.</p>\n\n<p>mysql_* functions are bad. Burn them, throw them away but don't use them. Use mysqli_ instead or even better PDO.</p>\n\n<p>Ever heard of SQL injections? I think so since you are using <code>mysql_real_escape_string</code>. A simple search on the interwebz for <code>h... | {
"AcceptedAnswerId": "29265",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T08:48:16.907",
"Id": "29167",
"Score": "1",
"Tags": [
"php",
"mysql"
],
"Title": "Basic news/blog post system"
} | 29167 |
<p>I have the following condition statement in Groovy:</p>
<pre><code>if ( condition_1 ) {
//some actions
} else if ( condition_2 ) {
//some another actions
} else {
assert false, 'Assertion description'
}
</code></pre>
<p>Code Narc gives me a warning about using boolean <code>false</code> constant in the... | [] | [
{
"body": "<p>Throwing an assert error is probably heavier than throwing an Exception (as Groovy will parse the assert inputs to give you a pretty output string)</p>\n\n<p>And unless you are going to be running this hundreds of times per second, I wouldn't worry about it either way...</p>\n\n<p>A way of using a... | {
"AcceptedAnswerId": "29173",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T10:22:59.430",
"Id": "29171",
"Score": "1",
"Tags": [
"groovy",
"constants"
],
"Title": "Boolean constant for assert in if..else block"
} | 29171 |
<p>I am trying to download files using jsp but then downloaded files are not readable.
Suppose if i download pdf files then it can not opened,if i download jpg files then it can not opened and similarily for the video files too.</p>
<p>Please point out the mistakes where i have made</p>
<pre><code> <%@ page imp... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T12:08:42.730",
"Id": "46019",
"Score": "4",
"body": "Locate the errors yourself, then report them on Stack Overflow. We (and them) don't serve as a compiler."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013... | [
{
"body": "<p>Some observations:</p>\n\n<ul>\n<li><p>Don't use <code>FileReader</code>, that's meant to be used for char streams, where undesireable transformations could happen due to default charsets and the like. Binary streams are the correct choice for your case.</p></li>\n<li><p>Your first try-catch sente... | {
"AcceptedAnswerId": "29175",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T11:44:55.140",
"Id": "29174",
"Score": "-2",
"Tags": [
"java",
"servlets",
"file",
"jsp"
],
"Title": "file downloading using jsp but not readable"
} | 29174 |
<p>I am trying to write up a pixel interpolation (binning?) algorithm (I want to, for example, take four pixels and take their average and produce that average as a new pixel). I've had success with stride tricks to speed up the "partitioning" process, but the actual calculation is really slow. For a 256x512 16-bit gra... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T13:49:30.533",
"Id": "46037",
"Score": "0",
"body": "Are you sure that what you are doing is binning? Sounds more like interpolation to me. In any case, ``numpy`` and ``scipy`` have both binning and interpolation functions of differ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T13:24:55.880",
"Id": "29178",
"Score": "1",
"Tags": [
"python"
],
"Title": "Pixel interpolation (binning?) algorithm"
} | 29178 |
<p>I want to use the enum on the client for a dropdown list. Does this make sense, or is there a smarter way of doing this?</p>
<pre><code>public class clientEnum
{
public string Value { get;set;}
public int Key { get; set; }
}
public static List<clientEnum> EnumToclientEnum <T>(T enumType) wher... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T13:21:42.997",
"Id": "46263",
"Score": "0",
"body": "I assume localization is no problem for this application?"
}
] | [
{
"body": "<p>Your code won't work, I get an error at following line:</p>\n\n<pre><code>var number = (byte)Enum.Parse(enumType, name);\n</code></pre>\n\n<p>This is the error:</p>\n\n<blockquote>\n <p>InvalidCastException: Specified cast is not valid.</p>\n</blockquote>\n\n<p>You should leave the cast to a byte... | {
"AcceptedAnswerId": "29181",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T13:50:27.517",
"Id": "29179",
"Score": "2",
"Tags": [
"c#",
"json",
"enum",
"converting"
],
"Title": "Converting a c# enum into a list to be sent to the client"
} | 29179 |
<p>This question has become long after many updates. <a href="https://codereview.stackexchange.com/questions/29183/review-implementation-of-stack-by-using-array-in-c#comment46116_29183">Click here</a> to go down.
<hr>
I have implemented stack using arrays in C. Please give me suggestions on how to improve it. The purpo... | [] | [
{
"body": "<p>Most of the code is a driver program. The only really interesting part here is</p>\n\n<pre><code>arr[(*length)++] = data;\n</code></pre>\n\n<p>and</p>\n\n<pre><code>return arr[--(*length)];\n</code></pre>\n\n<p>as well as the range-checking. I won't look too closely at the driver code.</p>\n\n<p>M... | {
"AcceptedAnswerId": "29195",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T16:28:47.550",
"Id": "29183",
"Score": "0",
"Tags": [
"c",
"array",
"stack"
],
"Title": "Review implementation of stack by using array in C"
} | 29183 |
<p>Could you tell me how to make it quality code?</p>
<pre><code><?php
class Game {
public function __construct() {
session_start();
}
public function play(){
return '<input type="button" value="Play" onclick="window.location = \'?play=1\'">';
}
public function start($msg=n... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T17:41:25.337",
"Id": "46057",
"Score": "0",
"body": "One point I know is about the non-existence of documentation (comments) on it, but was a test for 1 hour which I didn't give the concern for it."
},
{
"ContentLicense": "C... | [
{
"body": "<ul>\n<li>Indentation is important</li>\n<li>dont use the same bee object again and again</li>\n<li>embrace braces (after every if, else, and so on keyword comes a brace pair)</li>\n<li><p>after if or switch should be a space or/and there should bespaces inside e.g.<br>\n<code>if( X ) {</code> or <co... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T17:37:04.600",
"Id": "29190",
"Score": "4",
"Tags": [
"php",
"game"
],
"Title": "Basic \"bee game\" labeled as messy"
} | 29190 |
<p><strong>A little background</strong><br/>
I'm an intern at a large engineering company, and I'm also the only CS major in the entire building. The people on my team don't have technical backgrounds, but hired me to start developing an internal application. </p>
<p><strong>About my program</strong><br/>
I'm trying t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T21:51:35.813",
"Id": "46085",
"Score": "0",
"body": "How big is the CSV file (# of lines)? How often does the CSV change? Can the part number show up in any \"column\" in the file? It also looks like there is some sort of hierarc... | [
{
"body": "<p><strong>Some beginner mistakes...</strong></p>\n\n<p>The functionality of the classes should make sense logically. Instead of bringing out the terminologies, I prefer to think from a layman's interpretation of a class. Why should your <code>PartList</code> know what is a <code>CSVReader</code>? An... | {
"AcceptedAnswerId": "29285",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T17:39:57.037",
"Id": "29191",
"Score": "7",
"Tags": [
"java",
"object-oriented",
"csv"
],
"Title": "Intern with no mentor struggling with refactoring and OOP"
} | 29191 |
<p>We are working to translate our site into different languages. Currently, we pull 80% of a page from a database that is already translated. We drop in a language id and output the appropriate content. </p>
<p>What I need to store and access are the bits and pieces of text that need to appear on every page, but won'... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-18T05:24:18.017",
"Id": "62421",
"Score": "0",
"body": "There are several i18n packages out there.\n\nhttps://github.com/jmohler1970/PHP-Language-File-in-ColdFusion\n\nis one of them.\n\n**Disclaimer:** I wrote it"
}
] | [
{
"body": "<p>You could create a language layer and the code only knows the reference. PHPBB has a good example of this in their templating system.</p>\n\n<p>That way the button on a form, for example, is always something like template_var['login']. There is a replace going on based on a language pack file. The... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T19:17:27.577",
"Id": "29197",
"Score": "0",
"Tags": [
"i18n",
"coldfusion",
"cfml"
],
"Title": "How to store and access translated language text pieces?"
} | 29197 |
<p>I created this small function just to practice C code. It's a simple random string generator.</p>
<pre><code>#include <string.h>
#include <time.h>
char *randstring(int length) {
static int mySeed = 25011984;
char *string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789,.-#... | [] | [
{
"body": "<p>the code doesn't look that wrong, but</p>\n\n<ul>\n<li>the caller should allways check for errors</li>\n<li><code>if (length < 1)</code> test unnecessary</li>\n<li><code>srand(time(NULL)</code> should be done outside</li>\n<li>error catching (<code>malloc</code>) should open no new block</li>\n... | {
"AcceptedAnswerId": "29200",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T19:30:21.933",
"Id": "29198",
"Score": "9",
"Tags": [
"c",
"strings",
"random",
"generator"
],
"Title": "Random String generator in C"
} | 29198 |
<p>I have two solutions (in Jython) to take two pictures and copy and paste alternate sections of one picture to the other, like so:</p>
<p><img src="https://i.stack.imgur.com/dp427.png" alt="pic1"><img src="https://i.stack.imgur.com/BJlty.png" alt="pic2"><img src="https://i.stack.imgur.com/XihbZ.jpg" alt="newpic"></p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-31T20:15:57.143",
"Id": "46180",
"Score": "3",
"body": "Minor point (not worth an answer): You an rewrite `(y>=0 and y<20)` to `0 <= y < 20`."
}
] | [
{
"body": "<p>The second one is more efficient. Simply because in the first one you are calculating the <code>if</code> <code>w * h</code> times but in the second you are calculating it <code>h</code> times.</p>\n\n<p>Also it can be made more readable and efficient just by using this. It eliminates <code>leaf</... | {
"AcceptedAnswerId": "29207",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-31T04:25:12.210",
"Id": "29206",
"Score": "2",
"Tags": [
"image",
"jython"
],
"Title": "Copying sections of one picture to another"
} | 29206 |
<p>Here is my code for removing duplicated values from an array. I think I tested it with the most possible cases. Any suggestions or bugs? </p>
<pre><code>class duplicate {
public static int[] removeDuplicates(int[] arr) {
int end = arr.length;
for (int i = 0; i < end; i++) {
for... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-31T09:59:02.837",
"Id": "46113",
"Score": "2",
"body": "Use Set(Eg HashSet). Duplicate values are not allowed in it. Just iterate over the array and add it to the Set.If you want result in an array copy the set to the target array."
... | [
{
"body": "<p>Suggestion: </p>\n\n<pre><code>public static Integer[] removeDuplicates(Integer[] arr) {\n return new HashSet<Integer>(Arrays.asList(arr)).toArray(new Integer[0]);\n}\n</code></pre>\n\n<p>Another solution might be:</p>\n\n<pre><code>public static int[] removeDuplicates(int[] arr) {\n Set&l... | {
"AcceptedAnswerId": "29216",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-31T08:40:45.660",
"Id": "29210",
"Score": "11",
"Tags": [
"java",
"array"
],
"Title": "Removing duplicate values from an array"
} | 29210 |
<p>After I had my <a href="https://codereview.stackexchange.com/questions/29183/review-implementation-of-stack-by-using-array-in-c">code for stack implementation by array</a> reviewed I wrote stack implementation by using pointers. Here's my code. Any suggestions for improvement are welcome. </p>
<p><strong>I'll be ad... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-31T10:40:52.117",
"Id": "46114",
"Score": "0",
"body": "Is this meant to be reviewed as library style code or as a one-off intellectual oversize? In other words, would you like for us to critique the external-developer usability of thi... | [
{
"body": "<p>First of all, you should put the implementation in a separate implementation file and expose access to it through a header.</p>\n\n<p>Second, your <code>stack_node</code> is an implementation detail and should not be exposed to client code. Instead, create a <code>struct stack</code> that contains... | {
"AcceptedAnswerId": "29242",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-31T09:23:56.027",
"Id": "29213",
"Score": "1",
"Tags": [
"c",
"stack",
"pointers"
],
"Title": "Review implementation of stack by using pointers in C"
} | 29213 |
<p>The following code makes jQuery trigger a new <code>target</code> event on elements when they become the target of the <a href="http://en.wikipedia.org/wiki/Fragment_identifier" rel="nofollow">fragment identifier</a>.</p>
<p>For a very basic example, the following <code>target</code> event handler:</p>
<pre><code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-26T12:14:26.957",
"Id": "67357",
"Score": "0",
"body": "No, probably not — you could use a straight transition. The question's about the jQuery plugin."
}
] | [
{
"body": "<p>to start with a terrible pun; I would avoid <code>void</code> where possible,<br> <code>history.replaceState( '', '', location.href.split( location.hash )[ 0 ] );</code> makes more sense to me. Also for your return statements I would rather see</p>\n\n<pre><code>return link.hash ? link.href.split... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-31T09:42:36.427",
"Id": "29214",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"css",
"plugin",
"dom"
],
"Title": "Custom event to match CSS :target pseudo-class"
} | 29214 |
<p>I have a question about the best way to design / redesign my software. I have a program that uses a web services to perform certain tasks. Each task is a different set of request / response classes on the server end and a general function call from the Main Hook.</p>
<pre><code>RequestObject req = new RequestObject... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-31T11:46:36.527",
"Id": "46121",
"Score": "2",
"body": "Is this the real example? If it is, then i fail to see what is the purpose of `Method1`, `Method2`, etc. and why cant you have a single `WebServiceInterface`, which will handle al... | [
{
"body": "<p>I think what you should do, is instead of spawning those <code>Method</code> classes you should implement a proper wrappers for com requests/responses, and then find the way to treat those wrappers the same way without the need to know, whats inside them. From the code you provided, i cant quite s... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-31T09:58:54.873",
"Id": "29217",
"Score": "1",
"Tags": [
"c#",
"object-oriented",
".net"
],
"Title": "Web service performing different tasks"
} | 29217 |
<p>I wrote this Jqeury to make it work with asp.net update panel. I know i do little bit of hacking to make it work just. I want to get some help in how to optimize and remove the hacks from my script.</p>
<pre><code><script type="text/javascript">
//get all elemnt with class .resource-download
$.each($... | [] | [
{
"body": "<p>Some notes in no particular order:</p>\n\n<p><strong>1</strong></p>\n\n<pre><code>//get all elemnt with class .resource-download\n$.each($(\".resource-download\"), function () {\n var fileExtension = getFileExtension(this.href);\n if (fileExtension == \"\" || fileExtension != \"pdf\") {\n ... | {
"AcceptedAnswerId": "29228",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-31T13:45:48.477",
"Id": "29223",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"asp.net"
],
"Title": "How to optimize jQuery to run on asp.net web form updatepanel?"
} | 29223 |
<p>To get more familiar with Java, I decided to make a Tetris clone.</p>
<p>As I finished the <code>Tiles</code> beans class, I went to the <a href="http://en.wikipedia.org/wiki/Tetromino" rel="nofollow noreferrer"><code>Tetromino</code></a> class, which is basically made of different sets of 4 <code>Tiles</code> objec... | [] | [
{
"body": "<p>From an Object Oriented perspective, it's better to create extending classes, as in your second suggestion. This makes it easier to add more implementations in the future, to override existing implementations to create even more specialized behavior, etc.</p>\n\n<p>In your case, however, since the... | {
"AcceptedAnswerId": "29272",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-07-31T13:55:08.153",
"Id": "29224",
"Score": "0",
"Tags": [
"java",
"object-oriented",
"design-patterns"
],
"Title": "Creating tetrominoes in game"
} | 29224 |
<p>Given a table, I want to explore all possible <strong>transition</strong> between the elements in the table.
ex: for a table with size 3 [0,1,2], the output of the algorithm should be 0->1, 1->0, 0->2, 2->1, 1->2, 2->0.
I guess this can be regarded as traversing a complete graph.</p>
<p>I have an implementation of... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-25T09:30:32.147",
"Id": "46140",
"Score": "0",
"body": "if you get the habit to use 'yield' in Python, you will end with much more Prolog like code, very similar to what @Mat shows"
},
{
"ContentLicense": "CC BY-SA 3.0",
"C... | [
{
"body": "<p>Consider describing what a transition is:</p>\n\n<pre><code>list_transition(List, (E1->E2)) :-\n select(E1, List, Rest),\n member(E2, Rest).\n</code></pre>\n\n<p>Example query:</p>\n\n<pre><code>?- list_transition([0,1,2], T).\nT = (0->1) ;\nT = (0->2) ;\nT = (1->0) ;\nT ... | {
"AcceptedAnswerId": "29230",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-25T08:14:13.307",
"Id": "29229",
"Score": "5",
"Tags": [
"algorithm",
"graph",
"prolog"
],
"Title": "Complete graph traversal algorithm in Prolog"
} | 29229 |
<p>I had posted <a href="https://salesforce.stackexchange.com/questions/14324/recursive-functions-apex">a question</a> some time back for the best way of doing an account hierarchy, and this is the way implemented at last.</p>
<p>Can someone point out any obvious flaw in this (other than SOQL)?</p>
<p>The use case is... | [] | [
{
"body": "<p>Nothing jumps out at me as a huge problem since you are checking the number of queries executed in the trigger's context. I do agree with the original suggestion of preferring batch Apex, though scheduling Apex from within a trigger can be dangerous. If you don't need these values updated immediat... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-31T21:28:43.500",
"Id": "29245",
"Score": "2",
"Tags": [
"salesforce-apex"
],
"Title": "Account hierarchy"
} | 29245 |
<p>For a university project I'm trying to build a system that has a general architecture of:</p>
<p>Client app <=====> Client library < - - > Server library <=====> Server app</p>
<p>I'm trying to make the client and server as general (in the context of a java application, cross-platform compatibility is a c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T10:11:27.283",
"Id": "46201",
"Score": "0",
"body": "I suspect the issue is one of the client library needing to notify the application that it's ceased talking to the server. I just need to figure out a decent mechanism for doing ... | [
{
"body": "<p>Tidbits for you:</p>\n\n<pre><code>private UpstreamChannel upstream = null;\nprivate boolean ending = false;\n</code></pre>\n\n<p>Instance variables are initialized to <code>null</code> by default, and boolean values are set to <code>false</code> by default.... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-31T22:04:57.093",
"Id": "29247",
"Score": "2",
"Tags": [
"java",
"multithreading",
"socket"
],
"Title": "Proper cleanup in multithreaded client/server code"
} | 29247 |
<p>I am new to JavaScript. I know that many inheritance and initialization methods have been written and use some advance features like <code>Object.create</code>:</p>
<p><a href="http://ejohn.org/blog/simple-javascript-inheritance/" rel="nofollow">Simple JavaScript Inheritance</a></p>
<p><a href="http://aaditmshah.... | [] | [
{
"body": "<p>I'm the author of <a href=\"http://aaditmshah.github.io/why-prototypal-inheritance-matters/\" rel=\"nofollow noreferrer\">Why Prototypal Inheritance Matters</a>. It's good that you're taking an interest in prototypal inheritance. So let's review your code. I'll start with your use case and then di... | {
"AcceptedAnswerId": "29956",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T03:32:34.223",
"Id": "29251",
"Score": "1",
"Tags": [
"javascript",
"inheritance"
],
"Title": "Please check if these two methods for inheritance and initialization are good or bad"... | 29251 |
<p>I have written this big function to do some formatting in my python code. Would you be able to suggest anyways to make this smaller ? </p>
<pre><code>def disfun(String1,String2,String3):
if String3 == "A" or String3 == "B":
if String3 == "A":
pass
elif String3 == "B":... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T12:26:42.750",
"Id": "46209",
"Score": "0",
"body": "I am at a loss why you'd call \"String3\" something that's clearly the type of banner, and \"String2\" to something that on one of the branches is `join`ed (so it's in fact a coll... | [
{
"body": "<p>Ok, the first thing is that the names are not at all descriptive. <code>disfun</code>? What does that mean? Maybe something like <code>generateReport</code>? What are the purposes of <code>String1</code> and <code>String2</code>? Why does <code>String2</code> get printed before <code>String1</code... | {
"AcceptedAnswerId": "29253",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T04:43:04.800",
"Id": "29252",
"Score": "1",
"Tags": [
"python"
],
"Title": "python function compression"
} | 29252 |
<p>I'm trying to improve my functional skills and seeing where it fits and where it might not. Please review the code and see where functional practices might be applied. I'm specifically looking at trying to get rid of the state variables.</p>
<pre><code>private int GetFirstLineFrameCount(XDocument doc)
{
var sub... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T19:32:10.837",
"Id": "46232",
"Score": "0",
"body": "do you mean get rid of _xmlns and _xmlnsEc? If so just pass them in as parameters to the method."
}
] | [
{
"body": "<p>A refactored functional programming that is <code>evil</code>.</p>\n\n<pre><code>public static class ObjectExtension\n{\n public static Tout IfNotNull<Tin, Tout>(this Tin source, Func<Tin, Tout> func)\n where Tout : class\n where Tin : class\n {\n if (source ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T12:44:00.207",
"Id": "29264",
"Score": "6",
"Tags": [
"c#",
"functional-programming"
],
"Title": "Getting the first line frame count"
} | 29264 |
<p>I'm cloning a fairly complex div/ page and changing various things in it before appending it to the DOM. The current method seems long-winded, and I was hoping if there was a simpler way of doing it?</p>
<pre><code>$.each(results.jobs, function(i, result){
var theID = result.id,
theTitle = result.title,
theDescri... | [] | [
{
"body": "<p>This seems a textbook case for using Angular.</p>\n\n<p>Assuming you do not have the time to invest in Angular, you could consider the following:\nIf you named all your divs after your <code>result</code> properties ( for example <code>'#job-agency'</code> -> <code>#job-company</code> ), then you ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T13:28:24.160",
"Id": "29266",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"ajax"
],
"Title": "DOM cloning in a loop"
} | 29266 |
<p>I'm trying to clean some incoming <code>$_GET</code> parameters. I've not done this before, so I'd love feedback.</p>
<p>I'm especially concerned with the array. While all the other parameters control simple logic, the array will be saved into the database and potentially output to users.</p>
<p>Please also feel... | [] | [
{
"body": "<p>My 2 cents:</p>\n\n<p><code>$int = abs( intval( $int ) ); // positive number</code></p>\n\n<p>Silently fixing input values is evil, perhaps required, but still evil.</p>\n\n<pre><code>function gfahp_sanitize_array( $array ) {\n $array = array_walk_recursive( $array, \"gfahp_sanitize_string\" )... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T16:49:15.593",
"Id": "29269",
"Score": "0",
"Tags": [
"php",
"url"
],
"Title": "Am I sufficiently cleaning incoming $_GET parameters, especially in the array?"
} | 29269 |
<p>Are there any ways I could improve speed and less code? The elevator that uses this script works fine. Could anything be better?</p>
<pre><code>print(" Teknikk xPower 9700 PRE DEV V1 Intialised")
-- Develoment sample, May have functions added or removed. --
local Floor = script.Parent.Floor
local Floors = script.... | [] | [
{
"body": "<h1>Indentation</h1>\n\n<p>It's in some places, but in the places it's not in, it's pretty bad.</p>\n\n<p>You should always make sure your code is indented so, when looking over your code, you can see what goes where.</p>\n\n<p>For example, your <code>Start</code> function has bad indentation. Genera... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T18:47:12.433",
"Id": "29275",
"Score": "4",
"Tags": [
"game",
"lua"
],
"Title": "Elevator code for a game called ROBLOX"
} | 29275 |
<p>I have been working to create an easy-to-use set of methods to encrypt configuration objects for my client application. It will contain username and passwords to databases and similar vaults of data, so it's rather important that I've got the fundamentals correct.</p>
<p>I'm fairly new to this form of encryption, a... | [] | [
{
"body": "<ol>\n<li><p><code>CalculatePasswordHash</code> is inadvertently reimplementing (and probably not as well) a standard primitive. You should use <code>System.Security.Cryptography.Rfc2898DeriveBytes</code> instead.</p></li>\n<li><p>The code</p>\n\n<pre><code> var desc = crypto.CreateEncryptor();\n ... | {
"AcceptedAnswerId": "29304",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T18:58:13.213",
"Id": "29278",
"Score": "1",
"Tags": [
"c#",
".net",
"security",
"cryptography"
],
"Title": "Am I interfacing in a secure manner with rijndael?"
} | 29278 |
<p>Apex is a language native to force.com/Salesforce and has a lot of common ground with Java. It is a case insensitive, object oriented language. </p>
<ul>
<li><a href="http://apexdevnet.com/page/Apex_Code%3a_The_World%27s_First_On-Demand_Programming_Language" rel="nofollow">The World's First On-Demand Programming La... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T19:03:00.137",
"Id": "29279",
"Score": "0",
"Tags": null,
"Title": null
} | 29279 |
A proprietary Java-like programming language for the Force.com Platform. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T19:03:00.137",
"Id": "29280",
"Score": "0",
"Tags": null,
"Title": null
} | 29280 |
<p>Excerpt from <a href="http://www.force.com/why-force.jsp" rel="nofollow">Force.com website</a>:</p>
<blockquote>
<p><strong>What is Force.com?</strong></p>
<p>Force.com is a platform for creating and deploying applications for the social enterprise. Because there are no servers or software to buy or manage, ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T19:06:23.853",
"Id": "29281",
"Score": "0",
"Tags": null,
"Title": null
} | 29281 |
A platform for creating and deploying applications for the social enterprise. Essentially Salesforce.com without CRM. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T19:06:23.853",
"Id": "29282",
"Score": "0",
"Tags": null,
"Title": null
} | 29282 |
<p>Salesforce as a company provides multiple cloud-based systems, but are mainly known for their CRM system. Their main products are built on the Force.com platform, which is an MVC-style framework that can be extended through custom <a href="http://codereview.stackexchange.com/tags/apex-code/info">Apex code</a>.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T19:09:56.240",
"Id": "29283",
"Score": "0",
"Tags": null,
"Title": null
} | 29283 |
A Platform-as-a-Service development environment delivered on Salesforce.com - the platform is more correctly referred to as Force.com. A dedicated Salesforce Stack Exchange public beta is available for all your Salesforce questions at http://salesforce.stackexchange.com/. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T19:09:56.240",
"Id": "29284",
"Score": "0",
"Tags": null,
"Title": null
} | 29284 |
<p>I've been working with jQuery, mostly consuming plugins and using bits and pieces here and there for other functionality. Anyways, I wrote some standalone functionality in jQuery for a project and decided to convert it to a plugin as an exercise for myself. Note, it's not a full blown plugin, I don't inject markup o... | [] | [
{
"body": "<p>Overal, I think this is very good code, I only have a few pointers.</p>\n\n<ul>\n<li><p>Unused variables ( <a href=\"http://www.jshint.com/\">jshint</a> ).</p>\n\n<ul>\n<li>scrollOffset</li>\n<li>continuousScrollSpeed</li>\n<li>autoScroll</li>\n<li>autoScrollSpeed</li>\n<li>autoScrollDirectionChan... | {
"AcceptedAnswerId": "37965",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T23:20:23.390",
"Id": "29288",
"Score": "9",
"Tags": [
"javascript",
"jquery",
"plugin"
],
"Title": "First jQuery Plugin - SmoothSlider"
} | 29288 |
<p>I am writing a unit test for a Dispatcher that will route a HTTP request to a specific Controller and invoke a specific method on that Controller. It will also trigger various events at different steps of the process. The majority of what is going on is carried out by dependencies injected at construction time; the ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2018-07-17T09:28:26.323",
"Id": "384186",
"Score": "0",
"body": "Yes you’re right about your fears. Your user land code should not have test exceptions, and your code shouldn’t need any mock really. You should be able to set it up easily by cr... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-01T23:59:37.127",
"Id": "29289",
"Score": "3",
"Tags": [
"php",
"object-oriented",
"unit-testing"
],
"Title": "Unit testing event triggering"
} | 29289 |
<p>I am currently writing my first actual C++ project. I like Chess and I would like to see how good I'm doing on a monthly basis, so the idea is to read the log files (.pgn files) from the games and tell me how many games I won and such.</p>
<p>My question specially relates to Games.cpp where I'm not sure I have done... | [] | [
{
"body": "<p><strong>Games.cpp</strong></p>\n\n<ul>\n<li><p>It's not necessary to have member functions access <code>private</code> data members by their getters. These particular functions already have full access to the class.</p></li>\n<li><p>Too many of your member functions begin with <code>get</code>, y... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T00:28:04.347",
"Id": "29290",
"Score": "4",
"Tags": [
"c++",
"game",
"c++11",
"parsing"
],
"Title": "Reading .pgn files to display statistics about Chess games"
} | 29290 |
<p>I'm not sure what I'm doing wrong, but I run the code using a Web Vulnerability software and I get a lot of XSS attacks against the code. Is there something I could do better?
<pre><code>// connect to database
include("dbconnect.php");
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email =... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T10:48:07.630",
"Id": "46257",
"Score": "0",
"body": "In addition to the answer, it's redundant to escape parameters you bind into a prepared statement."
}
] | [
{
"body": "<p>XSS attacks affect the whole web, regardless of the stack you're using, you always have to be careful. Based on the redirect url you provided and the queries you execute, I'm assuming you're building an on-line address book. If a client were to fill in the form, saying his name were:</p>\n\n<pre><... | {
"AcceptedAnswerId": "29295",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T05:05:04.207",
"Id": "29294",
"Score": "2",
"Tags": [
"php",
"mysqli"
],
"Title": "How can I make this code safer against XSS attacks?"
} | 29294 |
<p>I am fairly new to coding TSQL script and am looking for some second view on my script.
The goal here is to to pull in some data and amongst that data to show a field with a counting the number of working days since the order date only (i.e. minus weekend days and UK bank holidays). The <code>SELECT</code> script be... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-31T20:52:51.813",
"Id": "53851",
"Score": "0",
"body": "I added two tags I assumed on the SQL-Server tag over sybase. if it is Sybase I will replace SQL-Server with a Sybase Tag, just let me know"
}
] | [
{
"body": "<p>I did notice in your Function you subtract a day from Saturday if it is an End Date, but not 2 days from the end date if it is Sunday, and not 2 days from the start date if it is Sunday or 1 day from the start date if it is Saturday. </p>\n\n<p>I assume that you want to do these things to make su... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T09:07:51.503",
"Id": "29297",
"Score": "5",
"Tags": [
"sql",
"beginner",
"sql-server",
"datetime",
"t-sql"
],
"Title": "Selecting the number of working days minus weekend ... | 29297 |
<p>I am using <code>if</code> statements within my functions to validate form fields and then on the <code>isset</code> event.</p>
<p>I want to be able to create many different functions to validate various fields groups, and it seems that this statement could grow very long:</p>
<pre><code>if (($namecheck === TRUE) ... | [] | [
{
"body": "<p>If I understand your problem well, the problem is that you don't want an if clause to become too long and that you have a problem with empty parameters. Your way of checking seems right to me, for the other part I asked myself if you can't just add something like this to the functions namecheck() ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T11:49:56.457",
"Id": "29299",
"Score": "1",
"Tags": [
"php",
"algorithm"
],
"Title": "Validating form fields"
} | 29299 |
<p>I've written the following extension to determine the MIME type of a base64 string. It's worked in my local tests, but can anyone point out issues or alternate methods?</p>
<pre><code>public static AttachmentType GetMimeType(this string value)
{
if(String.IsNullOrEmpty(value))
return new AttachmentType... | [] | [
{
"body": "<p>Your attachment types look like static data to me, so I'd personally make <code>AttachmentType</code> an immutable class and define your common bits as <code>static</code> members. I also like making things like this implement an <code>interface</code> for ease of mocking during unit testing. So I... | {
"AcceptedAnswerId": "29303",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T13:15:41.880",
"Id": "29301",
"Score": "8",
"Tags": [
"c#",
"base64"
],
"Title": "Checking MIME Type from a base64 string"
} | 29301 |
<p>Following is the code to update content via ajax. Please review all aspects of the code.</p>
<pre><code>var ajaxUpdate = {
init: function(){
ajaxUpdate.enableHistory();
},
_this:null,
enableHistory: function(){
History.Adapter.bind(window,'statechange',function() { // Note: We are us... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T18:53:52.120",
"Id": "46271",
"Score": "2",
"body": "What exactly is your question? Does the code work for you? Are you asking us to review it? Are there any specific areas you want the reviews to focus on?"
},
{
"ContentLic... | [
{
"body": "<p>A couple things right off the bat:</p>\n\n<ol>\n<li><p>You use <code>jQuery('#maincontainer')</code> multiple times. You should consider caching that somewhere. Either as part of your object or a separate variable.</p>\n\n<pre><code>// Wherever you use jQuery('#maincontainer'), use ajaxUpdate.main... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T13:16:30.027",
"Id": "29302",
"Score": "3",
"Tags": [
"javascript",
"html",
"ajax"
],
"Title": "Code to update content via ajax"
} | 29302 |
<p>Here is the script:</p>
<pre><code>function opening(){
setTimeout(function () {
var opening = $('#stage');
opening.find('h1').fadeIn('slow', function(){
setTimeout(function () {
opening.find('.logo').fadeIn('slow', function(){
setTimeout(function (... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T10:21:26.770",
"Id": "46459",
"Score": "0",
"body": "Are you interested only in pure JS or also in transcompiling solutions?"
}
] | [
{
"body": "<pre><code>// Put everything in one function, but break it up internally\nfunction opening() {\n // A tiny, internal helper function\n // I've switched the order of arguments compared to setTimeout\n // because it makes for nicer code (no dangling argument after\n // a function body)\n function ... | {
"AcceptedAnswerId": "29315",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T14:51:47.360",
"Id": "29306",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Trying to simplify a setTimeout sequence"
} | 29306 |
<p>I am writing my first programs in Python and want to be sure my code is good and not too C++-like. Consider the problem of finding all common 'associations' for set of 'keys'.</p>
<p>Data format is</p>
<ul>
<li>first line: integer <code>N</code></li>
<li><code>N</code> lines: key: <code>association 1 ... associati... | [] | [
{
"body": "<p>Your code looks pretty good for a newcomer to the language. Some comments:</p>\n\n<ul>\n<li>I don't quite understand why you need <code>uni</code>.</li>\n<li>References to <code>t[0]</code> and <code>t[1]</code>: It's more declarative to unpack tuples/lists and give names to its components -> <cod... | {
"AcceptedAnswerId": "29309",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T15:58:03.603",
"Id": "29307",
"Score": "2",
"Tags": [
"python"
],
"Title": "Finding associations for a set of keys"
} | 29307 |
<p>I really like functional programming in C#, it gives you a lot of flexibility.
I am wondering if it is the right idea to use functions instead of helper methods, and to make the code more readable.</p>
<p>So here is what I want, I have a method that needs to find Saturday and do something with it:</p>
<pre><code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T21:46:26.767",
"Id": "46293",
"Score": "0",
"body": "Why are the proposed solutions not acceptable? The best practice for this behavior is a utility function or an extension method and you seem to be excluding both of those from the... | [
{
"body": "<p>You could try create a utility function elsewhere in your solution ...</p>\n\n<pre><code>public static class DateUtils\n{\n public static DateTime MostRecent(DayOfWeek weekDay)\n {\n var date = DateTime.Today;\n while (date.DayOfWeek != weekDay)\n date = date.AddDays... | {
"AcceptedAnswerId": "29347",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T18:27:52.663",
"Id": "29308",
"Score": "1",
"Tags": [
"c#",
"functional-programming"
],
"Title": "Using Func<T> instead of helper methods in a class"
} | 29308 |
<p>The script currently loops through an output line-by-line, picking out elements of interest and adds them to a hash data structure. If a key already exists (in this case the interface name), it appends data to it.</p>
<p>I can work with a data structure, but I am never happy with the approach I take of looping thro... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T13:50:59.077",
"Id": "46273",
"Score": "1",
"body": "The data seems to be one record per line. So why are you unhappy \"looping through the data line by line\"? To put it another way, this seems tailor made for a line-by-line approa... | [
{
"body": "<p>You don't have to write code for testing of key existence because autovivification will do the work for you. So your cycle can be written as simple:</p>\n\n<pre><code>foreach my $line (@data) {\n my ($mac, $ip, $if) = (split /\\s+/, $line)[0,1,5];\n push @{$data_str{$if}}, {$ip => $mac};\... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T13:46:35.467",
"Id": "29310",
"Score": "2",
"Tags": [
"perl"
],
"Title": "Adding elements to a hash from an output"
} | 29310 |
<p>I've just written an implementation of Conway's Game of Life as an exercise and I'd love to get some feedback on how I can improve this program and hopefully my style in general.</p>
<p>I've tested the code in Python 2.7.3. It requires the <a href="https://github.com/drj11/pypng" rel="nofollow">PyPNG module</a> to ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T20:37:01.967",
"Id": "46282",
"Score": "0",
"body": "From a quick look, I'd say avoid placing code in the global namespace... place stuff in `main()` function, and use the `__name__ == '__main__'` thing. See http://meta.codereview.s... | [
{
"body": "<p>The main thing I want to point is that your algorithm is too simple since it uses matrix (list of lists) as a playing field. If it will be 1000*1000 you will process the field in about a second. And it is already slow. But if 10000*10000? 100 seconds per move (100 millions mostly empty cells to pr... | {
"AcceptedAnswerId": "29346",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T20:11:13.077",
"Id": "29314",
"Score": "4",
"Tags": [
"python",
"game-of-life"
],
"Title": "General feedback on Conway's Game of Life implementation"
} | 29314 |
<p>Ok, this might be a very stupid question/idea (I'm still a beginner). Lets say I have a construct like this:</p>
<pre><code>g.setColor(new Color(random.nextInt(5) * speed, 255, speed * 3));
</code></pre>
<p>Now it is very likely that the passed arguments will in some cases be out of the expected range, so the code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-26T19:36:51.843",
"Id": "46279",
"Score": "1",
"body": "It is a fine thing to do; nice job, in fact! I would not change a thing."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-26T19:39:15.117",
"Id": ... | [
{
"body": "<p>There is nothing too bad about this, and it is an acceptable pattern to get rid of extra/boilerplate code (for example <code>IOUtils</code> from Apache Commons has a <code>closeQuietly</code> for streams that takes a way a lot of the nested <code>try-catch-finally</code> madness for closing stream... | {
"AcceptedAnswerId": "29317",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-26T19:33:44.450",
"Id": "29316",
"Score": "3",
"Tags": [
"java"
],
"Title": "Make the awt.Color class constructors except out of range arguments"
} | 29316 |
<p>I have a script I use to prune packages that have gone stale from my custom Debian repository (i.e. they no longer exists on any of the official repositories):</p>
<pre><code>import apt_pkg
import gzip
import subprocess
CUSTOM_REPO = ("/home/tshepang/.custom_repo/dists/tshepang/main/"
"binary-amd64... | [] | [
{
"body": "<p>Your code looks very good, so I'll just propose some minor (and subjective) improvements:</p>\n\n<ul>\n<li><p>Imports: <a href=\"http://www.python.org/dev/peps/pep-0008/#imports\" rel=\"nofollow\">PEP8</a> has some recommendations about grouping imports that sound pretty reasonable.</p></li>\n<li>... | {
"AcceptedAnswerId": "29337",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T20:23:51.600",
"Id": "29318",
"Score": "5",
"Tags": [
"python",
"linux"
],
"Title": "Finding unique/obsolete binary Debian packages"
} | 29318 |
<p>I have come up with an idea for adding privacy support in JavaScript. I haven't found something similar in the net, so I'm thinking it's probably because the idea is bad, but yet, I want to see some response, just to be sure.</p>
<pre><code>var util = {
s4: function() {
return Math.floor((1 + Math.rando... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-29T18:16:56.217",
"Id": "46287",
"Score": "0",
"body": "It's a silly example. A class with 2 construct parameters - a and b. a is private, b is public. The last line console.log(obj.a, obj.b); outputs \"undefined\", \"public\""
},
... | [
{
"body": "<p>Interesting question,</p>\n\n<p>as mentioned in the comments, privacy support can be (better) achieved with modules, or with IFFE's.</p>\n\n<p>On the whole your design is not sound, <a href=\"http://en.wikipedia.org/wiki/Globally_unique_identifier#Algorithm\" rel=\"nofollow\">your GUID creation co... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-29T18:12:34.937",
"Id": "29323",
"Score": "1",
"Tags": [
"javascript",
"object-oriented"
],
"Title": "Privacy approach in JavaScript"
} | 29323 |
<p>I've followed <a href="http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners" rel="nofollow">this blog</a> to get images with nice pretty rounded corners in Android.</p>
<p>I've managed to strip out a lot of the superfluous <code>arrayAdapter</code> stuff and make it much more simpl... | [] | [
{
"body": "<p>This looks very clean to me. Except perhaps:</p>\n\n<ul>\n<li><code>imgvw</code> - that's <strong>disemvoweling</strong>. nd t's bd. Not to mention it's breaking your <em>camelCasing</em> convention for locals.</li>\n<li><code>drawit</code> - while the name says what the function does, I would avo... | {
"AcceptedAnswerId": "35739",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T21:40:11.723",
"Id": "29324",
"Score": "2",
"Tags": [
"java",
"optimization",
"android"
],
"Title": "Android image with rounded corners"
} | 29324 |
<pre><code>require([
'jquery',
'underscore',
'backbone'
], function ($, _, Backbone) {
'use strict';
// TODO: Would like to access through define module, but not sure how..
var player = chrome.extension.getBackgroundPage().YouTubePlayer;
var user = chrome.extension.getBackgroundPage().User... | [] | [
{
"body": "<p><a href=\"http://api.jquery.com/jQuery.Deferred/\" rel=\"nofollow\"><code>jQuery.Deferred</code></a>, or even just <a href=\"http://wiki.commonjs.org/wiki/Promises/A\" rel=\"nofollow\">promises in general</a>, would make your code simpler. In short, a promise can be unfulfilled, fulfilled, or fail... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-02T23:40:56.357",
"Id": "29326",
"Score": "0",
"Tags": [
"javascript",
"backbone.js"
],
"Title": "How to simply express a desire to run a function when two properties are true?"
} | 29326 |
<p>I've never used a framework before, so I wanted to see if this fairly simple scenario was done correctly or could be improved:</p>
<pre><code>public function actionCreate($id) {
// Is request Ajax
if(Yii::app()->request->getIsAjaxRequest()) {
$userID = Yii::app()->user->id;
try {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T02:36:52.300",
"Id": "46307",
"Score": "0",
"body": "What language is this? Be sure to add its tag to this post."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T02:38:39.057",
"Id": "46308",
... | [
{
"body": "<ol>\n<li><p>The code closes a <code>div</code> tag here:</p>\n\n<blockquote>\n<pre><code>echo '<strong>Error!</strong> ' . $e->getCode() . '</div>'; \n</code></pre>\n</blockquote>\n\n<p>But there isn't any opening <code>div</code> tag inside the function. I guess it's a bug.</p... | {
"AcceptedAnswerId": "45075",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T02:21:21.537",
"Id": "29327",
"Score": "8",
"Tags": [
"php",
"exception-handling"
],
"Title": "Yii exception usage"
} | 29327 |
<p>I'm writing a function called unzip that turns:</p>
<pre><code>[(1,2);(3,4);(5,6)]
</code></pre>
<p>to</p>
<pre><code>([1;3;5],[2;4;6])
</code></pre>
<p>I've got a working implementation right here:</p>
<pre><code>let unzip (data:(int*int) list) : int list * int list =
match data with
|(x,y)::tl->(x::t... | [] | [
{
"body": "<p>You have the right idea, but you didn't quite know how to get there. You don't need that <code>traverse</code> function to operate on the left or right lists. Just bind them to separate variables through a simple <code>let in</code> expression and you can add the items to each of the lists.</p>\... | {
"AcceptedAnswerId": "29333",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T04:45:15.400",
"Id": "29329",
"Score": "2",
"Tags": [
"ocaml"
],
"Title": "Ocaml Functional Programming Tree"
} | 29329 |
<p>I am trying to implement a vector-like container of my own (just to gain a better understanding of how <code>std::vector</code> works under the hood). I've been using <a href="http://www.cplusplus.com/reference/vector/vector/" rel="nofollow">this</a> as a reference. </p>
<p>Although I've succeeded in implementing... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T18:48:39.337",
"Id": "46343",
"Score": "2",
"body": "Your update is more dangerous than your original. Because you don't use placement new your use of explicit destructor calls is going to get you in trouble. See me update below."
... | [
{
"body": "<ul>\n<li><p>That's an okay guide for reference, but I'd highly recommend searching for pages that give in-depth information about <code>std::vector</code>s. There's a lot going on under the hood, and one general guide cannot teach you everything.</p></li>\n<li><p>I'm not sure how far you want to go... | {
"AcceptedAnswerId": "29334",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T06:20:29.633",
"Id": "29331",
"Score": "6",
"Tags": [
"c++",
"performance",
"memory-management",
"vectors",
"reinventing-the-wheel"
],
"Title": "Template vector class"
... | 29331 |
<p>I'm trying to write a message queue implementation
so my threads can exchange data.
To keep things simple, the queue is only responsible for
sending pointers to memory. Only one thread may send messages,
and only one thread may read messages.</p>
<p>The struct <code>mq_t</code> represents a message queue.</p>
<ul>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-02-27T17:29:23.133",
"Id": "148868",
"Score": "0",
"body": "I don't think POSIX is portable to windows these days. I'm not very windows-savvy so I could easily be mistaken."
}
] | [
{
"body": "<p>With a size of 2, your 'queue' can hold only one item, so it is not really a queue. If\nyou increase the size to 8 (say) you now really have a queue, but your tests don't\nwork.</p>\n\n<p>You seem to define <code>send</code> and <code>recv</code> as follows:</p>\n\n<ul>\n<li><p><code>send</code> ... | {
"AcceptedAnswerId": "29341",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T12:10:08.800",
"Id": "29338",
"Score": "6",
"Tags": [
"c",
"thread-safety",
"queue",
"circular-list"
],
"Title": "Thread-safe message queue without mutex in C"
} | 29338 |
<p>I'm trying to create small PHP framework for my own needs (and likes). However there are questions for which I may need advice of more wise and experienced people before things became too complicated - so I moved it to github from private repo.</p>
<p>Currently I'm curious about organizing imports of modules better... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T13:21:47.220",
"Id": "46468",
"Score": "0",
"body": "Why would you implement `module` method if we already have lazy loading trough autoloading? It looks to me you're doing something that's been done before (and much better)."
}
] | [
{
"body": "<p>As N.B. mentioned in their comment - why are you implementing a <code>module</code> method if we already have lazy loading via autoloading? I've even <a href=\"https://github.com/jsanc623/LazyLoader\" rel=\"nofollow\">written a class</a> that you can simply attach and not have to worry about loadi... | {
"AcceptedAnswerId": "29398",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T13:38:33.163",
"Id": "29340",
"Score": "1",
"Tags": [
"php"
],
"Title": "PHP - avoid many on-demand imports"
} | 29340 |
<p>I'm just getting to know the whole prototype world, and now I'm trying to do in JS what is normally done in OO languages, namely classes and DAO classes.</p>
<p>I'd be grateful for any comments on whether the code is written in accordance to JS best practices and whatnot. More specifically, I didn't implement gette... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T15:40:02.177",
"Id": "46333",
"Score": "0",
"body": "please post the code here, not just link to it. It should persist beyond only until you get the response or until jsbin.com passes away."
},
{
"ContentLicense": "CC BY-SA ... | [
{
"body": "<p>I feel your question is bit abstract, requiring for exactly \"point of view\" :)</p>\n\n<p>You also did not mention which \"normal OO language\" you mean. Supposedly Java. And what javascript kind you use - browser or node.js?</p>\n\n<p>Anyway, I personally agree your code is sound enough, though ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T15:38:19.707",
"Id": "29343",
"Score": "4",
"Tags": [
"javascript"
],
"Title": "JavaScript - prototype, getters, setters, functions"
} | 29343 |
<p>As this new approach differs from my previous revisions, it shouldn't need references to them.</p>
<p>After receiving much guidance from CR chat, I ended up utilizing these things:</p>
<ul>
<li><code>enum</code>s for the <code>Rank</code> and <code>Suit</code> instead of arrays</li>
<li>a <code>namespace</code> fo... | [] | [
{
"body": "<h3>General notes</h3>\n\n<ul>\n<li><p>The <code>to_string</code>s for <code>Rank</code> and <code>Suit</code> do not belong in the <code>Card</code> class. Move them out of the class and into the <code>card</code> namespace instead. They can be useful functions for client code as well.</p></li>\n<li... | {
"AcceptedAnswerId": "29351",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T20:11:02.497",
"Id": "29348",
"Score": "4",
"Tags": [
"c++",
"playing-cards"
],
"Title": "Newest approach to deck of cards project"
} | 29348 |
<p>I need a <code>copy_if_max()</code> function, i.e. copy all the elements in an input range that are equal to the max in that range. The most obvious implementation does two passes over the data:</p>
<pre><code>template<class InputIt, class OutputIt>
OutputIt copy_if_max2(InputIt first, InputIt last, OutputIt ... | [] | [
{
"body": "<p>I think you're overcomplicating the solution a bit. Since you're making copies of what is the maximum in the range, all you need is something that keeps a value to store the current max, and another which keeps a count of the number of maximum values that have been found in the input data. For exa... | {
"AcceptedAnswerId": "29365",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T20:23:47.350",
"Id": "29349",
"Score": "3",
"Tags": [
"c++",
"algorithm",
"c++11",
"stl",
"iterator"
],
"Title": "copy_if_max() algorithm"
} | 29349 |
<p>Currently, in my games, I'm using <code>new</code> and <code>delete</code> to create entities and components. It works fine, but there are slowdowns when creating/deleting many (5000+) entities or components at once.</p>
<p>After <a href="https://stackoverflow.com/questions/17789815/custom-heap-pre-allocation-for-e... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T22:28:22.950",
"Id": "46355",
"Score": "1",
"body": "Why don't you use [Boost.Pool](http://www.boost.org/doc/libs/1_54_0/libs/pool/doc/html/index.html)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04... | [
{
"body": "<h3>Big Issue:</h3>\n<p>Alignment. You do not consider alignment. You may not need too. But you should definitely comment the code to explain how it can be used.</p>\n<pre><code>p.create<char>();\np.create<int>(); // This will probably crash\n</code></pre>\n<p>Unlike new you don't suppo... | {
"AcceptedAnswerId": "29360",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T21:52:26.913",
"Id": "29350",
"Score": "2",
"Tags": [
"c++",
"performance",
"c++11",
"memory-management",
"heap"
],
"Title": "Heap memory preallocation (intended for ga... | 29350 |
<p>I've hacked together what feels like a mess for an authorize attribute to secure web api methods. The code appears to be functionally correct; passing the unit tests in place. The code has me worried because it will be executing with every call to any web api method and there is a lot going on, including string allo... | [] | [
{
"body": "<p>How about something like this. It's pretty much what you have but all I have done is seperated a couple of the parts into methods</p>\n\n<pre><code>using System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Threading;\nusing System.Web;\nusing System.Web.Http;\nusing Syste... | {
"AcceptedAnswerId": "29358",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T22:43:00.587",
"Id": "29353",
"Score": "7",
"Tags": [
"c#",
"asp.net-mvc-4"
],
"Title": "Custom System.Web.Http.AuthorizeAttribute"
} | 29353 |
<p>I try to implement a (restricted version of) step function in Haskell. A step functions is a function that is constant on a finite number of half intervals, and <code>mempty</code> everywhere else. (equivalently, one can fill those "everywhere else" by half intervals)</p>
<p>This can be modeled as a <code>StepData ... | [] | [
{
"body": "<p>I might be a little bit late to the party, but better late than never, right?</p>\n<h1>Type signatures</h1>\n<p>Your central functions <code>fromList</code> and <code>eval</code> don't have type signatures. This forces the user to check <code>Value</code> and <code>StepData</code>'s definition. Be... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-03T23:15:32.767",
"Id": "29354",
"Score": "3",
"Tags": [
"haskell"
],
"Title": "Implement step function in Haskell"
} | 29354 |
<p>I think many know the problem of working with multiple projects: private projects, company projects, probably even projects for multiple companies.</p>
<p>From day-one, I've always searched for better ways to handle all those projects on the file system level. I think I figured out a nice basic directory structure... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T01:10:14.203",
"Id": "46359",
"Score": "1",
"body": "If you're looking to reduce typing, are you using tab completion? If the company is Acme and the project is FooBar, `cd ~/c<tab>A<tab>F<tab>`"
},
{
"ContentLicense": "CC B... | [
{
"body": "<h3>Remove unused variables</h3>\n\n<p>The variable <code>argument_count</code> is not used for anything, so you should remove it.</p>\n\n<h3>Simplify shell arithmetics</h3>\n\n<p>Instead of this:</p>\n\n<blockquote>\n<pre><code>(( argument_count=argument_count-1 ))\n</code></pre>\n</blockquote>\n\n<... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T00:51:24.453",
"Id": "29355",
"Score": "5",
"Tags": [
"beginner",
"shell",
"zsh"
],
"Title": "A z-shell function to quickly cd into projects"
} | 29355 |
<p>I'm trying to do a one-way directory sync. Given a list of existing files in a dir, I'd like to make the files in the dir equal a new list of files. There will be subdirs under the dir. Because operating system calls are expensive, I'd rather minimize the number needed.</p>
<p>It's easy to just delete each file in ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T20:46:28.077",
"Id": "46499",
"Score": "1",
"body": "Some comments: 1) Why are you afraid of leaving empty subdirs? You could just remove all the subdirectories with ``shutil.rmtree(path)``... but I guess that would slow down so sti... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T01:48:24.037",
"Id": "29356",
"Score": "4",
"Tags": [
"python",
"algorithm",
"file-system",
"sync"
],
"Title": "Python files sync"
} | 29356 |
<p>I wrote a program to proxy MDNS requests in a local network to the DNS server. This is useful because in some private networks, host names ending in ".local" are configured in the DNS server. But ".local" is actually reversed for MDNS. Some systems have problems resolving these host names because they only try to re... | [] | [
{
"body": "<p>Overall this code reads well. Nice job.</p>\n\n<p>I do not know a better way to write <code>mdnsIp</code>.</p>\n\n<p>I have two concerns:</p>\n\n<ol>\n<li>Logging. A proper daemon should have logging to let people know what is happening.</li>\n<li>Infinite loops. There are several places in the co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T04:15:05.580",
"Id": "29361",
"Score": "8",
"Tags": [
"haskell",
"networking",
"socket",
"server",
"proxy"
],
"Title": "A program to proxy MDNS requests to the DNS server"... | 29361 |
<p>There are many PHP PDO classes out there, agreed. However I find they do not allow for flexibility. So I created one that helps reduce development time as little as it may be but it does the job (maybe apart from the disconnect part, but it allows to trace whether database is connected via <code>$database->isConn... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T08:00:55.103",
"Id": "46454",
"Score": "7",
"body": "You are actually making it worse! At this moment you throow away one of the most powerfull features of PDO: prepared statements. You can execute prepared statements multiple times... | [
{
"body": "<p>Personally, I must say that close to all PDO derived/based classes I've seen so far suffer from the same problem: They are, essentially, completely pointless.<Br/>\nLet me be clear: <code>PDO</code> offers a clear, easy to maintain and neat interface on its own, wrapping it in a custom class to be... | {
"AcceptedAnswerId": "29394",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T06:04:32.813",
"Id": "29362",
"Score": "54",
"Tags": [
"php",
"object-oriented",
"mysql",
"pdo"
],
"Title": "Class for reducing development time"
} | 29362 |
<p>Some background: I work mostly in Python (specifically numpy), doing Bioinformatics type work. I am interested in moving towards Haskell. Initially, I hope it will be possible to replace some of the simple exploratory scripting I've been doing with Haskell. The following is not something that would actually be parti... | [] | [
{
"body": "<p>Try using the functions from then <a href=\"http://hackage.haskell.org/packages/archive/bytestring/0.9.2.1/doc/html/Data-ByteString-Lazy-Char8.html\" rel=\"nofollow\">ByteString</a> package instead of System.IO and String as they are much more efficient. Also, consider using lazy IO (using heGetCo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T07:59:13.603",
"Id": "29363",
"Score": "3",
"Tags": [
"haskell"
],
"Title": "Calculating chromosome coverage of a set of regions"
} | 29363 |
<p>I am capturing a window of my own choice, and taking a screenshot of it constantly in a loop. Latency and speed is everything.</p>
<p>It's very capable, but I hope it can be improved.</p>
<pre><code>var proc = Process.GetProcessesByName(prcname)[0];
IntPtr hwnd = proc.MainWindowHandle;
RECT rc;
NativeMethods.Get... | [] | [
{
"body": "<p>Well, yes, you're holding on to a bunch of <code>IDisposable</code> objects which should be dealt with by employing the <code>using</code> statement:</p>\n\n<pre><code>IntPtr hwnd;\n\nusing (var proc = Process.GetProcessesByName(prcname)[0])\n{\n hwnd = proc.MainWindowHandle;\n}\n\nRECT rc;\nNa... | {
"AcceptedAnswerId": "29375",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T08:25:34.470",
"Id": "29364",
"Score": "6",
"Tags": [
"c#",
"image",
"serialization"
],
"Title": "Capturing and taking a screenshot of a window in a loop"
} | 29364 |
<p>Please criticize the classes <code>GameJudgeImpl</code> and <code>GameInfo</code> so that I could make them clearer.</p>
<pre><code>public interface GameJudge {
public GameInfo gameInfo();
}
public enum GameResult {
UNKNOWN, DRAW, PLAYER_WINS, OPPONENT_WINS
}
public enum Cell {
EMPTY, PLAYER, OPPONENT... | [] | [
{
"body": "<ol>\n<li><p>Interface, GameJudge, doesn't seem to make sense.</p>\n\n<ul>\n<li><p>the method gameInfo(), doesn't have an action verb so it's hard to determine what exactly it is doing. getGameInfo() perhaps?</p></li>\n<li><p>An interface is a contract. So if another class were to implement this int... | {
"AcceptedAnswerId": "29376",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T11:49:52.637",
"Id": "29367",
"Score": "2",
"Tags": [
"java",
"object-oriented",
"tic-tac-toe"
],
"Title": "Extremely Object Oriented Tic-Tac-Toe in Java"
} | 29367 |
<p>The PHP Mess Detector of my IDE warns about a Cyclomatic Complexity of 14 (threshold is 10). To me this code doesn't seem to hard to follow. Would you refactor it in some way to lower the metric?</p>
<ol>
<li>Exit if <code>$payload</code> isn't an array or has a number of elements not equal to 1</li>
<li>If <code>$... | [] | [
{
"body": "<p>You could easily extract the 4 functions you have within if statements by having</p>\n\n<pre><code>arrayChecker()\narraySetter()\nclassChecker()\narraySetter()\n</code></pre>\n\n<p>And then have something like </p>\n\n<pre><code>//Exit immediately if override is not allowed ( why wait ? )\n//Perso... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T15:42:25.143",
"Id": "29368",
"Score": "1",
"Tags": [
"php",
"php5"
],
"Title": "Lowering the cyclomatic complexity of this method, suggestions?"
} | 29368 |
<p>I am building a PHP framework and would like to get some feedback on a few different section of the project so far. I consider myself still a neophyte in PHP so I would like to ask if I'm going about completing this different task in an efficient and or correct way.</p>
<p>This section is of the Template parser. I ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T20:19:52.063",
"Id": "46406",
"Score": "0",
"body": "Why reinvent the wheel? Googling \"PHP template engine\" yields smarty, twig, and rain.tpl. Unless this is strictly a learning exercise, I'd use an existing engine."
},
{
... | [
{
"body": "<p>I would separate the components as follows:</p>\n\n<ul>\n<li>Database Layer (PL/SQL)</li>\n<li>View Layer (XSLT)</li>\n<li>Controller Layer (PHP)</li>\n</ul>\n\n<h1>Database Layer</h1>\n\n<p>Abstract out the database so that you can make generic calls to a database. For example:</p>\n\n<pre><code>... | {
"AcceptedAnswerId": "29383",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T16:44:20.843",
"Id": "29369",
"Score": "1",
"Tags": [
"php",
"optimization",
"design-patterns"
],
"Title": "PHP framework building: Template parsing"
} | 29369 |
<p>After 4+ months since I started learning web design I created my very first website. It's far from perfect but I learned a lot since then. I would appreciate it if someone would be so kind to review my work and suggest fixes to make it more functional and run more smoothly.</p>
<p>Please, don't pay attention to ba... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T17:57:01.143",
"Id": "46392",
"Score": "1",
"body": "As per the FAQ, you must embed the code you want reviewed. Email delivery will not work because all these posts are to benefit *everyone*."
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<p><strong>Regarding your HTML:</strong></p>\n\n<p>You could/should add a <code>meta</code> element (as the first element in the <code>head</code>) specifying the character encoding of the document. If it’s UTF-8, it could look like:</p>\n\n<pre><code><meta charset=\"utf-8\" />\n</code></pre>\n... | {
"AcceptedAnswerId": "29414",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T17:46:33.747",
"Id": "29373",
"Score": "4",
"Tags": [
"html",
"css"
],
"Title": "Web design studio site"
} | 29373 |
<pre><code>def dfs(graph, node):
"""Run DFS through the graph from the starting
node and return the nodes in order of finishing time.
"""
stack = [[node, True]]
while True in [x[1] for x in stack]:
i = 0
for x in xrange(len(stack)):
if stack[x][1] == True:
i = x
break
stack[... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-06T12:17:59.620",
"Id": "46536",
"Score": "0",
"body": "This does not do depth-first search, it does breadth-first search. Which do you want? I'll write an answer later today when I have time. Btw: The third function doesn't work be... | [
{
"body": "<p>Some hints.</p>\n\n<p>Set type can be used for seen variable.</p>\n\n<p>That stack = [...] + stack is a monster, both + operation and list comprehension.</p>\n\n<p>Is it possible to use set there (what type graph[x] is?). Maybe, its more efficient to have stack in a list of lists form?</p>\n\n<p><... | {
"AcceptedAnswerId": "29408",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T18:18:34.683",
"Id": "29374",
"Score": "4",
"Tags": [
"python",
"optimization",
"algorithm",
"performance",
"graph"
],
"Title": "Can someone help me optimize my DFS imp... | 29374 |
<p>I'm new to Haskell and I've made a very short <a href="https://en.wikipedia.org/wiki/KenKen" rel="nofollow">KenKen</a> solver. Any input is welcome.</p>
<pre><code>import Data.List
import Control.Monad
set :: [Int] -> Bool
set x = x == nub x
mats :: Int -> [[[Int]]]
mats x = filter (all set . transpose) . r... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2018-03-24T10:41:27.560",
"Id": "365162",
"Score": "1",
"body": "It's been almost four years since you've asked this question. Maybe you want to review your own code?"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T20:48:17.003",
"Id": "29378",
"Score": "4",
"Tags": [
"beginner",
"haskell",
"sudoku"
],
"Title": "A short KenKen solver"
} | 29378 |
<p>I made a site where you can add movies into the database. You can use up to 3 different hosts.</p>
<p>Everything works well, but it is very long. I would love to shorten it!</p>
<p>Code to enter the 3 hosts + the links to the host:</p>
<pre><code><TABLE>
<TR><TD width=120>Hoster*:</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T21:20:30.777",
"Id": "46410",
"Score": "3",
"body": "Using prepared statements for your SQL would save you having to do all the manual escaping."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T21:28:0... | [
{
"body": "<p>I fixed it up a little bit. The problem now, is that he keeps doing 3 queries even if I have only selected 1 or 2 hosts.</p>\n\n<pre><code><TABLE> \n <TR>\n <TD width=120>Hoster*:</TD>\n <TD>\n <SELECT class=\"interfaceforms\" name=... | {
"AcceptedAnswerId": "29390",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-04T21:18:57.397",
"Id": "29379",
"Score": "1",
"Tags": [
"php"
],
"Title": "Adding movies into a database"
} | 29379 |
<p>I currently have a container that has two features it allows adding objects to it and at the same time an independent thread continuously consumes items from it. It is a FIFO type deque. Which receives object at an extremely high rate. Following is the code for the container</p>
<pre><code>std::deque<Some_object... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T03:35:02.913",
"Id": "46438",
"Score": "0",
"body": "hi, got your comment message, hope you get a good answer cheers"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T14:51:34.197",
"Id": "46472",
... | [
{
"body": "<h3>Ownership symantics:</h3>\n<pre><code>void Container::Add_item(Some_object* obj)\n</code></pre>\n<p>Who owns <code>obj</code>?\nThis is a C-Style interface. Don't do it.</p>\n<p>It would be better to pass in as unique_ptr. This shows transfer of ownership. Also with good compiler optimization is ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T03:28:20.120",
"Id": "29382",
"Score": "6",
"Tags": [
"c++",
"design-patterns"
],
"Title": "Deque Container with an instant consumer for high speed object dumping"
} | 29382 |
<p>I am working on going through "Head First Design Patterns" and I am trying to properly convert the Java code into C#. Here is what I have. Can you tell me if this is a good implementation/conversion so far?</p>
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespa... | [] | [
{
"body": "<p>Oddly enough, in the Microsoft C# world, <code>PascalCasing</code> (as opposed to <code>camelCasing</code>) doesn't just apply to classes, but also to public fields, public methods, and public properties.</p>\n\n<p>So maybe you might want to rename <code>Duck.flyBehavior</code> to <code>Duck.FlyBe... | {
"AcceptedAnswerId": "29396",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T04:06:33.453",
"Id": "29384",
"Score": "5",
"Tags": [
"c#",
"design-patterns"
],
"Title": "Strategy Pattern"
} | 29384 |
<p>Common Lisp has a "special operator" called <a href="http://www.lispworks.com/documentation/HyperSpec/Body/s_multip.htm" rel="nofollow"><code>multiple-value-call</code></a>, which does something similar to Scheme's <code>call-with-values</code> but with a nicer syntax, and allowing multiple producers (<a href="http:... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T04:45:05.803",
"Id": "29385",
"Score": "2",
"Tags": [
"scheme",
"macros"
],
"Title": "`multiple-value-call` in Scheme"
} | 29385 |
<p>Here's the start of some code for a clock that can display time in 24 and 12 hours.</p>
<p>What could be added to it? How could I can apply notions such as OOP, model and Enums here?</p>
<pre><code>public Clock {
private int time = 0;
public int get24hrTime(){
return time;
}
public int se... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T10:38:03.117",
"Id": "46460",
"Score": "1",
"body": "\"Do not fix something that works\", what is the issue with this code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T10:41:27.500",
"Id": "46... | [
{
"body": "<p>Why do you check the time with <code>(hours - 12 < 0)</code>. This involves two operations, one subtraction and one compare. You could simply use <code>(hours < 12)</code>.</p>\n\n<p>Also you rely that in the method <code>set24hrTime(int newTime)</code> the time is never > 23 for your code t... | {
"AcceptedAnswerId": "29393",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T10:32:34.357",
"Id": "29392",
"Score": "3",
"Tags": [
"java",
"datetime"
],
"Title": "Programming a simple clock"
} | 29392 |
<p>I wrote this as a way to deliver static portion of the app. I'm wondering if there is a better way to write this, as I am new to Express.</p>
<p>The goal is to let a single-page app to handle routing as needed. There is an API layer of this app that is defined under the /api/ route namespace.</p>
<p>I wanted to n... | [] | [
{
"body": "<p>There is a better way.</p>\n\n<p>If you wish to serve static files with express - it comes bundled with <code>static</code> middleware. To use it, you simply add this line <strong>before</strong> your routes:</p>\n\n<pre><code>app.use(express.static(__dirname + '/public'));\n</code></pre>\n\n<p>Th... | {
"AcceptedAnswerId": "29902",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T16:24:49.443",
"Id": "29401",
"Score": "3",
"Tags": [
"javascript",
"node.js",
"express.js"
],
"Title": "Serving static assets through wildcard rule"
} | 29401 |
<p>I have a manager class (included below) and sub data types that are included inside it. All of the different stored types are more or less the same with some wrapper functions calling the exact same named function below to the sub object. This feels dirty and I can't help but think there's a better way to do this. S... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T19:06:04.297",
"Id": "46485",
"Score": "0",
"body": "I'm not entirely sure I understand the relationship between the two classes. What does the constructor for `ContentLockManager` do? Are IDs always `int`? What other mappings do ... | [
{
"body": "<p>As per the comments and Your actual problem, it seems that You are unknowingly and partly using a <a href=\"http://www.dofactory.com/Patterns/PatternProxy.aspx\" rel=\"nofollow noreferrer\">Proxy Pattern</a>. </p>\n\n<p>So as a slight modification You should be having an interface extracted from C... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T17:46:07.530",
"Id": "29403",
"Score": "3",
"Tags": [
"c#"
],
"Title": "How can I avoid seemingly unneccessary wrappers like this?"
} | 29403 |
<p>For Coursera's Algorithms course, I have written Kosaraju's algorithms which calculates strongly-connected components in a directed graph using depth first search. The code itself is correct but apparently not very efficient, because it took me almost 24 hours to get the answer for the file <a href="http://spark-pub... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T18:34:46.270",
"Id": "46484",
"Score": "0",
"body": "You missed placing the links in the paragraphs after the code. BTW you can use Ctrl + L to place links on text. There are other shortcuts that you can see at the topwhen you use e... | [
{
"body": "<p>Generally, with Kasuraju's algorithm (and other graph search algorithms), the biggest bottleneck is reading in the edges and then holding these in memory. If I understand this correctly, you have about 800,000 VERTEXES, which will lead to a few million edges. Holding both <code>G</code> and <code>... | {
"AcceptedAnswerId": "29411",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T18:18:09.637",
"Id": "29404",
"Score": "1",
"Tags": [
"python",
"performance",
"algorithm"
],
"Title": "Calculating strongly-connected components in a directed graph using DFS"... | 29404 |
<p>My page has been loading a bit slower than I want it to. </p>
<p>The website is <a href="http://www.digitechlab.com/" rel="nofollow">www.digitechlab.com</a></p>
<p>I segregated so many files because they were pretty big and I wanted to be able to work on just one section of that page at a time without running the ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-06T19:22:34.037",
"Id": "46599",
"Score": "2",
"body": "Looks fine to me from a code review perspective, the font choice is not so good. It looks ugly on my machine."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "... | [
{
"body": "<p>your structure looks good.</p>\n\n<p>I am sure you have a reason for nesting so many <code><div></code>s </p>\n\n<p>you know that you can add classes to Tags as well, and you don't have to add them to only <code><div></code> tags you can add them to other tags.</p>\n\n<p>it just looks... | {
"AcceptedAnswerId": "33618",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T18:51:05.123",
"Id": "29405",
"Score": "1",
"Tags": [
"html"
],
"Title": "Is this home page well organized and what can I do to improve performance here?"
} | 29405 |
<ol>
<li>What do you consider the readability of this program?</li>
<li>Do you think it's easy to understand what the variables and functions do just by reading their names?</li>
<li>Would you prefer more, less, or this amount of comments?</li>
<li>Do the comments make it easier or harder for you to understand the prog... | [] | [
{
"body": "<p>It is easy to get a general understanding of what your code does. You did a good job separating the code into functions. It could be made more readable in a few ways though, mostly by doing things in a simpler way. For example, your <code>add_prime</code> function (which appends a number to the... | {
"AcceptedAnswerId": "29419",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T21:19:41.783",
"Id": "29412",
"Score": "4",
"Tags": [
"python",
"primes",
"python-3.x"
],
"Title": "User-input prime number generator"
} | 29412 |
<p>First of all, I won't include the spin game there, cause it's very simple.</p>
<p>I went a bit deeper into object oriented since the last time, I learned array lists, using them with objects, maphashes, and more.</p>
<p>They are pretty useful I must say!</p>
<p>Let's begin:</p>
<p><strong>Mains.java</strong>:</p... | [] | [
{
"body": "<p>If you are focussing on OO it would be good to put your games in a separate class. For OO perspective you should check which are the different entities in your application and represent them in a class, defining that each entity can do and the relations to other entity. </p>\n\n<p>You might want... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T21:24:20.440",
"Id": "29415",
"Score": "1",
"Tags": [
"java",
"object-oriented",
"game"
],
"Title": "Game selection menu"
} | 29415 |
<p>I've been writing a program to perform a kind of pattern-matching in XML and text files. </p>
<p>When my program reaches this section of the code, the CPU usage gets very high and the performance slows down to a point where the program seems to be frozen. It actually isn't, but depending on the input (number of t... | [] | [
{
"body": "<p>This should help a little bit:</p>\n\n<pre><code> List<string> CandidatesRet = new List<string>();\n\n var splitChars = new[] { ' ' };\n\n for (var indexCi = 0; indexCi < Ci.Count - 1; indexCi++)\n {\n // generate all sub itemset with length-1\... | {
"AcceptedAnswerId": "29420",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-05T22:58:09.860",
"Id": "29418",
"Score": "3",
"Tags": [
"c#",
"performance"
],
"Title": "Program slows down significantly based on input"
} | 29418 |
<p>I have written a simple command line program in Python 3 that accepts a function (in the mathematical sense) from a user and then does various "calculus things" to it. I did it for my own purposes while taking a math class, so I was more concerned with getting it to output the right number than with security.</p>
<... | [] | [
{
"body": "<p>Looks well organized, understandable, and suited for the domain. You might want to take care with naming to improve readability. For example, name the class Function to be MathFunction to prevent confusion of purpose. Also single-letter variable names should normally be avoided, particularly lower... | {
"AcceptedAnswerId": "29475",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-06T05:18:44.263",
"Id": "29421",
"Score": "3",
"Tags": [
"python",
"python-3.x",
"mathematics",
"console"
],
"Title": "Command line calculus program"
} | 29421 |
<p>Can this be shortened, optimised or made more pythonic ?</p>
<pre><code>a = [1,9,'foo',5,7]
b = ['bar',4,8,6]
c = []
min_len = min(len(a),len(b))
for i in range(min_len):
c.extend([a.pop(0), b.pop(0)])
c.extend(a)
c.extend(b)
print c
</code></pre>
<p>output: [1, 'bar', 9, 4, 'foo', 8, 5, 6, 7]</p>
| [] | [
{
"body": "<p>There are a few possibilities...</p>\n\n<pre><code>from itertools import chain, izip_longest\ndef alternate(a, b):\n for i in range(max(len(a), len(b))):\n if i < len(a):\n yield a[i]\n if i < len(b):\n yield b[i]\n\ndef alternate2(list_a, list_b):\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-06T06:09:56.533",
"Id": "29423",
"Score": "5",
"Tags": [
"python"
],
"Title": "New list from the elements of two lists popping sequentially"
} | 29423 |
<p>I am trying to capture screenshots as fast as possible from when it's displayed, meaning that I want the latency to be minimal.</p>
<p>Currently, I am using user32.dll to capture a window. So, if I have a game, I capture that window along with borders and everything. It's very fast, but I wonder if hooking into th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T12:29:30.470",
"Id": "61637",
"Score": "1",
"body": "For inspiration, I would have a look at how [OBS does it](https://github.com/jp9000/OBS/tree/master/GraphicsCapture/GraphicsCaptureHook). One important aspect to remember is that ... | [
{
"body": "<blockquote>\n<p><em>It's very fast, but I wonder if hooking into the API (DirectX) and getting the buffer will be faster than this (I don't know how to do that, though).</em></p>\n</blockquote>\n<p>I don't know either.</p>\n<p>What you have here, probably hasn't been reviewed yet, because there's es... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-06T06:22:06.173",
"Id": "29424",
"Score": "13",
"Tags": [
"c#",
"performance",
"windows"
],
"Title": "Capture with User32.dll or hook?"
} | 29424 |
<p>I am using some string which contains an html. As follows</p>
<pre><code>var pagerHtml = '<span>No.Of Records</span><select class="rmselect" id="records" ><option value="10">10</option><option value="20">20</option><option value="40">40</option><option value=... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-06T08:46:35.237",
"Id": "46518",
"Score": "2",
"body": "You should check out [jsPerf](http://jsperf.com/). IMO, this isn't really a performance concern. I'd rather worry about maintaining this code, since HTML in JS isn't really good."... | [
{
"body": "<p>According to <a href=\"http://jsperf.com/parsing-escape\" rel=\"nofollow\">this jsperf test</a>, there is no consistent difference between parsing a string literal with and without escape sequences.</p>\n\n<p>There are differences depending on what browser you use, but they are quite small, and Ch... | {
"AcceptedAnswerId": "29432",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-06T08:44:05.613",
"Id": "29427",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"performance",
"parsing"
],
"Title": "Javascript parsing performance"
} | 29427 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.