body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I have the following <code>using</code> statement, used specifically for the purpose of archiving content in SharePoint libraries. In this statement my objects are disposed in two places:</p>
<pre><code>finally
{
web.Dispose();
site.Dispose();
}
</code></pre>
<p>and at the termination of my <code>using</co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T02:30:43.373",
"Id": "24229",
"Score": "0",
"body": "I recommend reading this item, even though there is a better construct in c# 4.0 http://my.safaribooksonline.com/book/programming/csharp/9780321659149/dotnet-resource-management/c... | [
{
"body": "<p>Prefer to use RAII above <code>finally</code>; you are already doing this with <code>site</code>, so disposing of it in the <code>finally</code> doesn't make much sense. On the other hand, you are not disposing of <code>web</code> that way and I would say that this could leak to (extremely unlike... | {
"AcceptedAnswerId": "14931",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T23:05:02.307",
"Id": "14922",
"Score": "5",
"Tags": [
"c#"
],
"Title": "Archiving content in SharePoint libraries"
} | 14922 |
<p>Okay, So I have this method I made that searches a 2d array of user input column length and row length comprised of integers. The method is suppose to find 4 alike numbers in rows, columns, and both major and minor diagonals throughout the entire array. The array can be as large as the user would like. My method wor... | [] | [
{
"body": "<p>I think the nicest thing to do is to create a function which separates the counting of the elements of an array from the array itself. For example, right now you have a \"counting procedure\", which basically looks like this:</p>\n\n<pre><code>public static boolean count(int[] values) {\n\n int... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T01:20:27.437",
"Id": "14928",
"Score": "6",
"Tags": [
"java",
"array",
"search"
],
"Title": "Java 2d array nested loops"
} | 14928 |
<p>While preparing an automated process to manipulate files, I've made the following function to check for the base directory and sub-directories presence, as to allow or deny the remaining code to be executed:</p>
<pre><code>/* Check Directories
*
* Confirm that the necessary directories exist, and if not,
* tries... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T13:38:34.707",
"Id": "24245",
"Score": "1",
"body": "why not just use mkdir() from PHP?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T20:09:55.637",
"Id": "24286",
"Score": "0",
"body": ... | [
{
"body": "<p>Quite a few things wrong with your PHPDoc. I'm actually learning quite a bit myself. Doccomments require two asterisks to begin, not one, no matter what language you are using. One asterisk just defines a multi-line comment. Your IDE will skip over this, essentially making these useless as doccomm... | {
"AcceptedAnswerId": "14946",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T13:20:44.767",
"Id": "14936",
"Score": "1",
"Tags": [
"php",
"performance",
"security"
],
"Title": "Confirming the presence/create directories"
} | 14936 |
<p>I have been trying to get the problem <a href="https://www.interviewstreet.com/challenges/dashboard/#problem/4e48b9cb8917f" rel="nofollow">Quadrant Queries</a> correct for a while now. Although my approach is an optimal one, I am getting a TLE on 3 test cases. Please help me optimize my approach so that I can pass a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T16:35:00.493",
"Id": "24266",
"Score": "0",
"body": "The point of this test is to test YOUR current ability to code, not your ability to solicit help on the internet."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | [
{
"body": "<h3>Algorithmic optimizations.</h3>\n<p>As you read the values in work out what quadrant the point belongs to and keep a running total for each quadrant (not adjustment needed on X/Y query). Then you do not need to re-calculate everything every time there is a 'C' request.</p>\n<p>As it stands comple... | {
"AcceptedAnswerId": "14947",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T13:36:57.190",
"Id": "14937",
"Score": "2",
"Tags": [
"c++",
"interview-questions",
"time-limit-exceeded"
],
"Title": "Optimization in overcoming TLE in interviewStreet problem... | 14937 |
<p>I was looking into removing multiple inputs and selects at once using jQuery, but I couldn't find a solution, so I ended up with the following code:</p>
<pre><code>$(function() {
$('a.add').click(function(evt) {
//clone lists
//is there any way to simplify this part --begin--
$('#s0 option').clone().... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T18:10:37.453",
"Id": "24246",
"Score": "0",
"body": "[`.each()`](http://api.jquery.com/each)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T18:12:35.613",
"Id": "24247",
"Score": "1",
"bo... | [
{
"body": "<p>for the top part you might be able to add some logic to your html.\nit looks when something is clicked you move the options to another element.\nif you just specified in the HTML the source and target elements through a class name like:\n<code><select class=\"source\" target=\"targetSelector\".... | {
"AcceptedAnswerId": "14940",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T18:09:15.130",
"Id": "14938",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html",
"animation",
"dom"
],
"Title": "An \"Add\" button that clones an item, and a \"Rem... | 14938 |
<p>I have a little chain of JQuery promises. My problem is at each stage I want to notify my progress to the user, keep them in the loop (Perhaps using .notify somehow?)</p>
<p>What I've eneded up with is this bizarre mess of callbacks and promises. It works but I'm quite certain there is a neater, more logical way ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T13:23:39.647",
"Id": "24251",
"Score": "2",
"body": "Am curious, why do you feel the code you posted is a mess? As in, what sort of pseudo code would look pretty? Maybe once I can see where the mess is, I can attempt to clean it up ... | [
{
"body": "<p>Surely this is possible. Only the <code>fetch</code> and <code>parse</code> functions would need to call <a href=\"http://api.jquery.com/deferred.notify/\" rel=\"nofollow\"><code>notify</code></a> with the respective message on the Deferreds they return. The code then could look like this:</p>\n\n... | {
"AcceptedAnswerId": "14943",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T13:16:27.740",
"Id": "14942",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"promise"
],
"Title": "Improving a JQuery Promise \"Chain\""
} | 14942 |
<p>I have seven checkboxes on a data maintenance WinForm, which indicate the days of the week that are "valid" for a particular operation to be performed. These "map" to a list of DayOfWeek enum values on the backing domain object; if the value is present in the list, the box should be checked, otherwise not. Any combi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T16:37:29.290",
"Id": "24267",
"Score": "0",
"body": "@Leonid - While in general I agree with you, there are exactly seven days in a Gregorian week (and in most other Abrahamic culture calendars), so until the entire world adopts the... | [
{
"body": "<p>I'd create an extension method that calculates the day by the name of the checkbox.</p>\n\n<p>I'm using dynamic because I don't know the name of your domain class, just replace it with your name.</p>\n\n<p>Also note, I'm using the web version of CheckBox, substitute ID with whatever version you ar... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T15:55:50.310",
"Id": "14948",
"Score": "5",
"Tags": [
"c#",
"winforms",
"gui"
],
"Title": "Ideas for reducing repetition in control binding"
} | 14948 |
<p>This is a pet project :)</p>
<p>I have hundreds of playlist files .m3u whose many entries have a wrong path. I'd like to fix them programmatically. Suppose one of my .m3U contains the following entry:</p>
<pre><code>z:\wrong-folder\Michael Jackson - Thriller.mp3
</code></pre>
<p>The file is stored in:</p>
<pre><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T16:27:17.843",
"Id": "24386",
"Score": "0",
"body": "Why do you think you need to break up a dictionary of just 6000 files? What makes you think you can repeat a key (e.g. M) in a dictionary? What have you tried? SO is for spe... | [
{
"body": "<p>If you are particularly interested in doing substring look-ups, you could look into the <a href=\"http://en.wikipedia.org/wiki/Trie\" rel=\"nofollow\">Trie</a> data structure. You will be stuck writing your own, however, as there is no implementation I know of in the BCL.</p>\n\n<p>Alternatively,... | {
"AcceptedAnswerId": "14953",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T16:19:17.943",
"Id": "14951",
"Score": "3",
"Tags": [
"c#",
".net",
"collections",
"hash-map"
],
"Title": "Iterating thousands of times over large collections: advices"
} | 14951 |
<p>So I had this idea; what if I could decorate my Enum values with an attribute that cross-references a "default" value of another Enum that should be used when a variable of the current Enum type has this value?</p>
<p>The desired usage would look like:</p>
<pre><code>public enum MyEnum
{
Value1,
Value2,
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T19:35:49.797",
"Id": "24281",
"Score": "0",
"body": "Your `GetLinkedValue` method can't compile - not all code paths return a value."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T19:43:38.520",
... | [
{
"body": "<p>I would personally write the attribute class as such:</p>\n\n<pre><code>[AttributeUsage(AttributeTargets.Field)]\npublic sealed class LinkedValueAttribute : Attribute\n{\n private readonly Type typeOfValue;\n\n private readonly Enum value;\n\n public LinkedValueAttribute(object value)\n ... | {
"AcceptedAnswerId": "14955",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T19:11:06.910",
"Id": "14954",
"Score": "2",
"Tags": [
"c#",
"optimization"
],
"Title": "\"Linked\" Enum value attribute"
} | 14954 |
<p>I have a simple class inheritance in JS:</p>
<pre><code>var Class = function(){};
Class.extend = function(){
var Extended = function(constructor){
function extend_obj(destination, source) {
for(var property in source){
if(typeof source[property] === "object" && sou... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-31T18:43:57.157",
"Id": "24728",
"Score": "0",
"body": "Try http://hay.github.com/stapes/"
}
] | [
{
"body": "<p>First of all, it seems like you're reinventing the wheel here. You didn't provide any context for what this is for so I'll try to cover all bases.</p>\n\n<p>If you are using this as part of a bigger project, I'd recommend abandoning this approach and picking up something like <a href=\"http://prot... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T20:21:21.333",
"Id": "14956",
"Score": "5",
"Tags": [
"javascript",
"classes",
"prototypal-class-design"
],
"Title": "Javascript inheritance"
} | 14956 |
<p>Below is the code for a compiler I created for a language called Jack. This compiler is one of the projects for the book "The Elements of Computing Systems" (http://www1.idc.ac.il/tecs/plan.html) where you build an entire computing system from the ground up. Anyway, what this compiler does is translate code from a h... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T14:37:30.430",
"Id": "24339",
"Score": "0",
"body": "\"I took out some code because it went over the character limit\" - You beat me to it, I thought one of my answers would have done that first :) Anyways, this is usually a sign th... | [
{
"body": "<p>Needs more classes, this one class does too many different things. </p>\n\n<p>Firstly, I'd suggest a Scanner class. This class will hold the array of tokens and the current position. It will then also have a number of methods to operate on it. It'll also keep track of errors during the parsing pro... | {
"AcceptedAnswerId": "14994",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T21:58:22.740",
"Id": "14957",
"Score": "3",
"Tags": [
"php",
"parsing"
],
"Title": "A simple compiler for a language called Jack"
} | 14957 |
<p>I created the following code to solve a simple ODE. It is clear enough? Is it efficient code? I really want to read opinions because I want to make all my exercise solutions the same way (same structure of the program), so I need to make sure that this code is really clear and efficient.</p>
<pre><code>#include <... | [] | [
{
"body": "<p>Although I'm not a C++ programmer I once held a course in computations with Matlab for physicists. So I can only give hints and thoughts on your code but I won't answer your question on efficiency.</p>\n\n<p>As you mentioned that this code will be the basic of following exercises, I'm missing all ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T22:34:20.177",
"Id": "14959",
"Score": "1",
"Tags": [
"c++",
"optimization",
"physics"
],
"Title": "Simple Open Dynamics Engine (ODE)"
} | 14959 |
<p>In the code below, does not clearing or setting the local variable <code>completed</code> to null create the potential for a memory leak?</p>
<pre><code>private Vector<Element> elements;
private void update()
{
Vector<Element> completed = new Vector<Element>();
for( Element e : elements )... | [] | [
{
"body": "<p>Because <code>complete</code> is used and is referenced entirely within the context of the method <code>update()</code>, it will become unreferenced after the method returns.</p>\n\n<p>This will eventually cause it to be garbage collected.</p>\n\n<p>After it has been garbage collected, some or all... | {
"AcceptedAnswerId": "14970",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T00:18:08.860",
"Id": "14963",
"Score": "4",
"Tags": [
"java",
"memory-management"
],
"Title": "Can not clearing a local java.util.Vector cause a memory leak?"
} | 14963 |
<p>I have a helper method to clean up a string and remove pieces that I will be generating again. (defined by the "SpecialKey" Constants) but I've never been real happy with the code. Although <strong>I</strong> find it easy to read adding more keys doesn't always seem so clean.</p>
<pre><code> protected static Sys... | [] | [
{
"body": "<p>I assume that the part that you want to improve is the key.StartsWith....</p>\n\n<p>I would replace the anonymous function with an Extension method String.StartsWith(IEnumerable<string>) -- then create a list of special keys (perhaps even load them from persisted storage, depending upon your... | {
"AcceptedAnswerId": "14968",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T00:23:17.940",
"Id": "14964",
"Score": "2",
"Tags": [
"c#",
"linq"
],
"Title": "Filter out string sections"
} | 14964 |
<p>I've got a <code>NumericUpDown</code> control for each denomination of money and all of the events run the exact same code save for a single line so I'm trying to condense them into 1 event. I was originally going to use a <code>switch</code> but you can't switch on a non-value object so I just did an <code>if</code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T01:47:56.880",
"Id": "24300",
"Score": "2",
"body": "Upon loading and just briefly seeing your code, NO."
}
] | [
{
"body": "<p>The problem is not in switching between senders but the fact that each branch calls a different method on <code>inBank</code>. I would suggest creating an enum for the denominations:</p>\n\n<pre><code>enum Denomination {\n Quarters,\n QuarterRolls,\n Nickels,\n NickelRolls,\n ...\n}\n</code><... | {
"AcceptedAnswerId": "14976",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T00:53:01.493",
"Id": "14965",
"Score": "2",
"Tags": [
"c#"
],
"Title": "Is this an efficient way to use one event for multiple controls?"
} | 14965 |
<p>I have two methods here that does the same thing: get the user input and validate them.</p>
<p>If they enter a letter, the program will prompt them again to enter a number. |After that, if it's a number it will compare it to the bound given by the program or the user. It is working fine, but can anybody help me re... | [] | [
{
"body": "<p>There are 2 problems that must be addressed first. Where did <code>diff.choice</code> come from, what is that? Second. What is the <code>this.askForCategory()</code> call? It <em>sounds like</em> exactly what <code>addToQuestionToQbank()</code> is doing. <code>addToQuestionToQbank()</code> does no... | {
"AcceptedAnswerId": "14996",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T01:10:26.380",
"Id": "14966",
"Score": "1",
"Tags": [
"java",
"validation",
"io"
],
"Title": "User prompts for entering quiz questions"
} | 14966 |
<p>I am writing a script to count the number of rows in a textarea, and as it will be called on every keypress I want to make sure it runs as fast as possible. I'm not aiming for a general solution: we can assume that the textarea has a monospace font and enough horizontal space for exactly 80 characters.</p>
<p>I've ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T02:41:42.597",
"Id": "24303",
"Score": "0",
"body": "Not that the performance difference will be noticable - but do you really need to do this on every keypress event? If not consider throttling the calls to maybe one call every (ha... | [
{
"body": "<p>What kind of performance are you getting? Is it acceptable. If it's not, then I'd look for changing your algorithm, and not minor tweaks. In particular, I'd look into NOT splitting the string and recalclating each time. Instead keep track of the state (what line and the number of characters on... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T02:07:20.297",
"Id": "14969",
"Score": "1",
"Tags": [
"javascript",
"google-chrome"
],
"Title": "Help optimizing a function to count the rows in a textarea"
} | 14969 |
<p>I'm writing a simulator for Conway's Game of Life (<a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" rel="nofollow">http://en.wikipedia.org/wiki/Conway's_Game_of_Life</a>) in C++ and I'm trying to make the code as idiomatic as possible. </p>
<p>The central object is a double array to represent the boa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T05:45:08.583",
"Id": "24316",
"Score": "0",
"body": "I don't know C++ but I think its the game of life thing is pretty cool just downloaded [this](http://www.macupdate.com/app/mac/26608/my-game-of-life)."
}
] | [
{
"body": "<p>Second one is better. Do not use pointers if it is possible to avoid them.\nFor example, in the beggining of the function update(Board *board) you have to check that board!=0 (to be sure, that your program will not crash). But in the function update(Board & board) you are sure, that board exis... | {
"AcceptedAnswerId": "14978",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T05:19:21.480",
"Id": "14972",
"Score": "4",
"Tags": [
"c++",
"memory-management",
"game-of-life"
],
"Title": "C++ Vector memory management in Game of Life"
} | 14972 |
<p>This is my first implementation of MongoDB, much much more to come. This sheds light on some things like how I've structured my collection. I hope to gain feedback and insight from the community on best practices as well as do's and don'ts.</p>
<p><strong>Givens</strong></p>
<ul>
<li>I have a website with multiple... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-18T09:30:30.230",
"Id": "25535",
"Score": "0",
"body": "Welcome to Code Review! Since you were wondering: the question is great, perfectly in the scope of Code Review. It's actually sad to see you didn't get an answer."
}
] | [
{
"body": "<p>While I cannot comment on your Node.js code, I can tell you that we're doing something very similar on a project that uses Mongo to store every bit of information for around 200 social profiles. In our case, we're doing something like:</p>\n\n<pre><code>foreach ($videos as $video) {\n $payload ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T05:21:05.923",
"Id": "14973",
"Score": "4",
"Tags": [
"javascript",
"node.js",
"mongodb"
],
"Title": "User-like MongoDB implementation"
} | 14973 |
<p>SQL:</p>
<pre class="lang-sql prettyprint-override"><code>CREATE FUNCTION dbo.fnRandomForeNames ()
RETURNS VARCHAR(50)
AS
BEGIN
RETURN (
SELECT TOP 1 [FirstName]
FROM [tmp_ForeNames]
ORDER BY (SELECT new_id from GetNewID)
)
END
GO
</code></pre>
<p>Similar functions fo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T14:22:12.843",
"Id": "24337",
"Score": "3",
"body": "Just a note:\nwhat you call a \"parametrised query\" is not actually it. In parametrised query you refer to parameters like @id, and add SqlParameter objects when running, not use... | [
{
"body": "<p>indexes! Index on new_id. </p>\n\n<p>You say you're using temp tables, so I assume you're populating them all at once. Do a update statistics after you fill them.</p>\n\n<p>Finally, why cant you say something like this?</p>\n\n<pre><code> select firstName from tmp_ForeNames where new_id = getNewI... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T09:43:41.497",
"Id": "14980",
"Score": "3",
"Tags": [
"c#",
"sql",
"sql-server",
"winforms"
],
"Title": "Any way to speed up this UPDATE?"
} | 14980 |
<p>I'm starting Rails and Ruby for a short time. But I try to make it the cleanest way I can. So, in an attempt to clean my view, I try to custom my <code>FormBuilder</code>:</p>
<pre><code># /config/initializers/custom_form_builder.rb
class ActionView::Helpers::FormBuilder
# My test form function
def test la... | [] | [
{
"body": "<p>I made it a different way. But, the answer was quite simple.</p>\n\n<p>The class ActionView::Helpers::FormBuilder inherit of the @template attribute.</p>\n\n<p>And to render my partials, I just need to call it this way :</p>\n\n<pre><code>def test label\n @template.render \"/forms/test\"\nend\n</... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T09:59:06.013",
"Id": "14981",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails",
"erb"
],
"Title": "Custom FormBuilder"
} | 14981 |
<p>I am using the following code to compare 2 images:</p>
<p>HTML (for example use only):</p>
<pre><code><canvas id="gViewCanvas"></canvas>
<img id="image1" src="image1.png" />
<img id="image2" src="image2.png" />
</code></pre>
<p>Javascript:</p>
<pre><code>var gOldImage = document.getElemen... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T14:31:16.763",
"Id": "24338",
"Score": "1",
"body": "FYI, If you draw an image on a canvas from a different domain than your own, you can't use `getImageData`. In short, this code will not work if you change `image1.png` to `http://... | [
{
"body": "<p>Instead of redrawing and getting new data for every pixel, just draw once and get both data arrays. Next loop through them and check their values:</p>\n\n<pre><code>var c1 = document.getElementById('c1');\nvar c2 = document.getElementById('c2');\nctx1 = c1.getContext('2d');\nctx2 = c2.getContext('... | {
"AcceptedAnswerId": "15001",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T12:41:25.643",
"Id": "14984",
"Score": "3",
"Tags": [
"javascript",
"optimization"
],
"Title": "Compare 2 Images"
} | 14984 |
<p>I have a List of a custom structure (myStruct) which has two ranges stored in it.
I'm trying to write a function where I can figure out if a range is completely enclosed in any of the ranges. Is this optimal and if not how can I improve it in terms of speed and memory efficiency?</p>
<pre><code>class myStruct {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T20:58:40.153",
"Id": "24334",
"Score": "1",
"body": "You could improve the *design* by introducing a `Range` type, and following .NET naming conventions."
}
] | [
{
"body": "<p>Just an idea</p>\n\n<pre><code>public struct Range\n{\n public readonly int From;\n public readonly int To;\n\n public Range(int from, int to)\n {\n From = from;\n To = to;\n }\n\n public bool Contains(Range other)\n {\n return Contains(other.From, other.T... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T20:51:55.173",
"Id": "14985",
"Score": "2",
"Tags": [
"c#",
"algorithm"
],
"Title": "determining if a range is within array of ranges"
} | 14985 |
<p>When <code>git</code> runs my <code>post-receive</code> hook, I'd like it to run all the scripts in the subdirectory <code>post-receive.d</code>.</p>
<p>My script is as follows</p>
<pre><code>#!/bin/bash
SOURCE="${BASH_SOURCE[0]}"
DIR="$( dirname "$SOURCE" )"
for SCRIPT in $DIR/post-receive.d/*
do
if [ -f "$SCR... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-28T19:49:24.860",
"Id": "74343",
"Score": "0",
"body": "`test -x \"$file\"` or `[[ -x \"$file\" ]]` is the only test you need; a file doesn't need to be readable to be executable."
}
] | [
{
"body": "<pre><code>for SCRIPT in $DIR/post-receive.d/*\n</code></pre>\n\n<p>You might want to limit that to only <code>*.sh</code> pattern, just for clarity.</p>\n\n<p>Personally I'm a fan of the one-line-style, but that's personal preference:</p>\n\n<pre><code>for ITEM in SET; do\nif [ CONDITION ]; then\n</... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T13:24:56.053",
"Id": "14988",
"Score": "2",
"Tags": [
"security",
"bash",
"shell",
"git"
],
"Title": "Run all scripts in a sub-directory"
} | 14988 |
<p>The domain model of my application revolves around movies.</p>
<p>Use case:</p>
<p>We have a movie for which only one title (in one country) is known and we want to know titles of this movie in other countries. To get that information, we call external movie repositories.</p>
<p>The <code>Movie</code> class has a... | [] | [
{
"body": "<p>One thing - this design is based on a false premise - that there is only ever a single title within a given country. See for example <a href=\"http://www.imdb.com/title/tt0216216/releaseinfo\">this movie</a> which has 3 USA titles (albeit only one, final, official title). This can be fixed by chan... | {
"AcceptedAnswerId": "14995",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T16:06:26.893",
"Id": "14993",
"Score": "8",
"Tags": [
"java",
"object-oriented"
],
"Title": "Movie repository for storing movies based on country"
} | 14993 |
<pre><code>String fileId = "CPP420.A2_2012072416244467745";
String reg1 = "CPP350";
String reg2 = "CPP420.A1";
String reg3 = "CPP420.A2";
String country = "";
if(fileId.startsWith(reg1)) {
country = "CA";
} else if(fileId.startsWith(reg2)) {
count... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T23:16:36.533",
"Id": "24416",
"Score": "1",
"body": "If \"CA\" is 'California' (the US State), you have a bigger problem - you're mixing your domains."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-20T2... | [
{
"body": "<p>Neither. Note: haven't tried this in and IDE, but you should be able to get the idea.</p>\n\n<pre><code>interface RegionID {\n boolean isRegionMatch(String fileID);\n String getRegionCode();\n}\n\nclass SimpleMatchRegionID implements RegionID {\n private String regionPrefix;\n private ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T17:26:00.760",
"Id": "14997",
"Score": "14",
"Tags": [
"java"
],
"Title": "Country selector: if or ternary?"
} | 14997 |
<p>I have recently started a project of SIMD libraries development for C++ on FASM for x86-64 Linux.
I would be glad to hear any opinion or feedback about the project, cleanness of the code and documentation. Here is the project's <a href="http://linasm.sourceforge.net/docs/index.php" rel="nofollow">web site</a> on So... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T20:52:04.007",
"Id": "24634",
"Score": "0",
"body": "For people, who would like to see the library speed, I made a simple performance testing page with graphics. I compare LinAsm algorithms with their GNU libc analogs. \nHere is the... | [
{
"body": "<pre><code>array equ rdi ; pointer to array\nsize equ rsi ; array size (count of elements)\nvalue equ xmm0 ; value to process with\n</code></pre>\n\n<p>I don't particularly care for these. It seems like you're tryi... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T17:56:33.030",
"Id": "14998",
"Score": "7",
"Tags": [
"linux",
"library",
"assembly",
"sse",
"simd"
],
"Title": "Writing SIMD libraries for C++ on FASM in x86-64 Linux"
} | 14998 |
<p>I neglected <code>java.nio</code> package in the past and now I am wondering if this is the best way to copy everything from a <code>Readable</code> to an <code>OutputStream</code>:</p>
<pre><code>public static void copy(@Nonnull Readable src, @WillNotClose @Nonnull OutputStream dest, @Nullable Charset targetCharse... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T07:53:09.053",
"Id": "24371",
"Score": "0",
"body": "It seems you forgot `.flush()` - have a look in new Java7 package nio.2 : http://docs.oracle.com/javase/tutorial/essential/io/fileio.html, very useful when Java7 will be in produc... | [
{
"body": "<p>Well, last night I came up with that. I am pretty satisfied with it right now but would be happy to see if I am still missing something.</p>\n\n<p>This solution does not rely on implementation details any more and provided streams are left open as the general contract demands it. </p>\n\n<pre><c... | {
"AcceptedAnswerId": "15021",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T19:16:54.467",
"Id": "15002",
"Score": "5",
"Tags": [
"java"
],
"Title": "Any better way to copy from Readable to OutputStream?"
} | 15002 |
<p>I'm looking for code correctness and improvements for the following code. It's my first step into class based programing.</p>
<p>What the class does, is simply to read a directory (path is passed as constructor argument) and find all sub directories matched by the search pattern. Then it returns a random directory ... | [] | [
{
"body": "<p>While not a problem, you aren't using the <code>$path</code> and <code>$array</code> properties and should remove them. You must call <code>getRandomPath</code> to get the actual path from the object.</p>\n\n<pre><code>$randomImages = new RandomImages('./backend/img');\n$path = $randomImages->g... | {
"AcceptedAnswerId": "15009",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T19:55:19.270",
"Id": "15004",
"Score": "5",
"Tags": [
"php",
"object-oriented",
"random",
"file-system"
],
"Title": "Selecting a random image from a subdirectory"
} | 15004 |
<p>I have the following code to split an address string in T-SQL. Excepting the unit number, which is already in its own field, it would affect too much of the application to split the address into different database fields. It's a bit of a long story, but it's also not possible to make it a parameterized query, or to ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T21:32:25.710",
"Id": "24362",
"Score": "2",
"body": "This is probably covered by your French cases but I wanted to point out that in some American cities (San Diego) Spanish names are numerous. Avenida Montuosa, Via San Marco, Cami... | [
{
"body": "<p>Reviewing this code is essentially meaningless without a ream of test data to compare against.... and it would be really nice to have a debugger!</p>\n\n<p>The REVERSE operations make keeping track of the data state quite complicated.</p>\n\n<p>In general though, the code is formatted well, though... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T21:20:45.183",
"Id": "15012",
"Score": "7",
"Tags": [
"sql",
"parsing",
"sql-server",
"t-sql"
],
"Title": "Splitting an address into fields in SQL"
} | 15012 |
<p>I've seen few ways of processing forms with PHP. Whenever I am working with a form, I typically have two files: one for displaying the information (e.g. form.php) and the other for processing information (e.g. process_form.php). The latter uses sessions and simply redirects to the appropriate page depending on if th... | [] | [
{
"body": "<p>That method is fine, and is the one I use. As for a better way? I don't know, seems just fine to me. However, there are some other things that could be improved with this script, and that may be why you feel there might be a better way.</p>\n\n<p>For one, that's some really messy HTML... I would t... | {
"AcceptedAnswerId": "15047",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T21:26:22.117",
"Id": "15013",
"Score": "4",
"Tags": [
"php",
"form"
],
"Title": "Processing a form with PHP"
} | 15013 |
<p>
As an exercise on GADTs I wrote a type-safe implementation of <a href="https://en.wikipedia.org/wiki/AA_tree" rel="nofollow">AA trees</a>. I'm quite happy that the <code>AANode</code> data type correctly grasps the properties of the tree. Just from the type it can be concluded that the trees has the balancing prope... | [] | [
{
"body": "<p>As suggested, I'm doing a review myself after a few years.</p>\n\n<p>First, let's use GHC's extensions to derive the phantom types from data definitions.\nThis also has the advantage of having proper kinds for each of these types.</p>\n\n<pre><code>{-# LANGUAGE GADTs, DataKinds, KindSignatures, Ty... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T07:52:02.630",
"Id": "15017",
"Score": "5",
"Tags": [
"haskell",
"tree",
"type-safety",
"gadt"
],
"Title": "Improving General Algebraic DataType type-safe code for AA trees"
} | 15017 |
<p>I have a jQuery script that checks for the strength of a password. The code looks like this (with more more of those "blocks"):</p>
<pre><code>if(passwordLC && lessThan12Password)
{
$('.passwordStrenght').animate({width:'75px',height:'5px'},200).show();
$('.passwordStrenght').css('background-color',... | [] | [
{
"body": "<p>The solution depends on your exact requirements and the context.\nIn your case, you could simplify the <code>if</code>-condition like below. If all fit into one <code>if</code>, you can write your code block there only once. If you need it and can't unify your condition, make it a function.</p>\n\... | {
"AcceptedAnswerId": "15020",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T08:06:20.433",
"Id": "15018",
"Score": "0",
"Tags": [
"javascript",
"jquery"
],
"Title": "Script for checking password strength"
} | 15018 |
<p>Can anyone review this?</p>
<pre><code>setInterval(function() {
var days_array = [31,29,31,30,31,30,31,31,30,31,30,31];
var m = randNum(12);
var m_limit = days_array[m-1];
var d = randNum(m_limit);
$("code").html("day = "+d+"<br>month = "+m);
},1000);
function randNum(limit){var r=Math.floor(Math.random()*lim... | [] | [
{
"body": "<pre><code>function randNum(limit){var r=Math.floor(Math.random()*limit)+1;return r;}\n</code></pre>\n\n<p>Can be shortened to:</p>\n\n<pre><code>function randNum(limit){return Math.floor(Math.random()*limit)+1;}\n</code></pre>\n\n<p>You should also declare your variables outside of the setInterval a... | {
"AcceptedAnswerId": "15051",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T09:01:01.173",
"Id": "15022",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"datetime",
"random"
],
"Title": "Random \"month & day\" with JS"
} | 15022 |
<p>I know this code is pretty awful, but, by any chance, could someone point out all the flaws you can find and tell me them? It's Python 3.2.3, by the way.</p>
<pre><code># Alien Assualt
# A bullet hell alien invasion game.
# Bobby Clarke
#Imports
import pygame, sys, os, random, math, easygui
from pygame.locals imp... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T15:21:48.883",
"Id": "24398",
"Score": "2",
"body": "I'm pretty sure I mentioned that using a pastebin here is a bad practice by itself :P."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T17:44:46.803... | [
{
"body": "<p>Some problems:</p>\n\n<ul>\n<li>Classes uncapitalised</li>\n<li>Default parameter equal signs <strong>without</strong> space (<em>def foo(a=0)</em>)</li>\n<li>Too long lines (you can break them!)</li>\n<li>Built-in paths (\"Images/player.png\")</li>\n<li>Use of too many arguments (use **kwargs ins... | {
"AcceptedAnswerId": "15028",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T12:17:48.100",
"Id": "15025",
"Score": "3",
"Tags": [
"python",
"game",
"python-3.x"
],
"Title": "Alien Assault game"
} | 15025 |
<p>I got a file with lots of ASCII characters. No extension, and has the Type Of file attribute 190000 File.</p>
<p>I have many characters like L¿ö in the file however I required to remove lines from a word PYGR to another word MCG. It has several lines in between.</p>
<p>I tried the following code. And got everythi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T13:10:44.230",
"Id": "24378",
"Score": "5",
"body": "Those *aren't* ASCII characters..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T13:24:41.770",
"Id": "24380",
"Score": "2",
"body": ... | [
{
"body": "<h1>Some clarifications</h1>\n<blockquote>\n<p>I got a file with lots of ASCII characters. [...] I have many characters like L¿ö in the file [...]</p>\n</blockquote>\n<p>As others have pointed out, these are <em>not</em> ASCII characters.</p>\n<blockquote>\n<p>No extension, and has the Type Of file a... | {
"AcceptedAnswerId": "15032",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T13:02:17.023",
"Id": "15027",
"Score": "4",
"Tags": [
"c#",
"vb.net"
],
"Title": "I have an encrypted file, how to remove a specific string from that file"
} | 15027 |
<p>I'm writing a program in wxpython, and to make GUI parts that are built in different modules I made a module called <code>runtime</code>, where all the GUI parts get stored on runtime.
This is how it looks: </p>
<pre><code>mainFrame = anotherGUIPart = InputDialog = SomethingElse = None
</code></pre>
<p>For exampl... | [] | [
{
"body": "<p>This is fine, as long as you're not bleeding too much across the module boundaries. Ideally you would have a structure somewhat akin to MVC, where you have all of your UI logic in one module, all your business logic in another, and a controller module which links the two together. However, if you ... | {
"AcceptedAnswerId": "15258",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T13:07:13.780",
"Id": "15029",
"Score": "-1",
"Tags": [
"python"
],
"Title": "Is it a good idea to store GUI elements in a module on runtime?"
} | 15029 |
<p>Is this return style acceptable? Would the code be more readable if I assigned the <code>MonthDay.parse()</code> return value to a variable and returned that variable on the last line?</p>
<p>Also, is it a bad idea to both log and rethrow inside a catch block?</p>
<pre><code>/**
* Parses showing date from the hea... | [] | [
{
"body": "<p>It is a very good understandable write.</p>\n\n<p>You can also write the return method in a parameters, it is optimal (look in <a href=\"http://www.pascal-man.com/navigation/faq-java-browser/java-concurrent/Effective%20Java%20-%20Programming%20Language%20Guide.pdf\" rel=\"nofollow\">Effective Java... | {
"AcceptedAnswerId": "15037",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T15:19:42.303",
"Id": "15034",
"Score": "5",
"Tags": [
"java",
"error-handling"
],
"Title": "Error handling for parsing a date"
} | 15034 |
<p>Here is my code;</p>
<pre><code>import socket
def read_line(sock):
"read a line from a socket"
chars = []
while True:
a = sock.recv(1)
chars.append(a)
if a == "\n" or a == "":
return "".join(chars)
def read_headers(sock):
"read HTTP headers from an internet ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-25T15:50:00.620",
"Id": "24434",
"Score": "0",
"body": "Code Review strictly improves working code, we aren't here to help debug your code.You can ask on Stackoverflow, but you should narrow down your question first."
},
{
"Con... | [
{
"body": "<p>Reading one byte at a time is bad idea, because it won't buffer the input. Instead, you'll probably get a system call for each byte which will be really inefficient.</p>\n\n<p>Easiest solution is to use <code>makefile</code></p>\n\n<pre><code>myfile = sock.makefile('r') \n</code></pre>\n\n<p>Then ... | {
"AcceptedAnswerId": "15074",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T15:45:14.523",
"Id": "15038",
"Score": "2",
"Tags": [
"python"
],
"Title": "Working with sockets"
} | 15038 |
<p>For educational purposes I've tried to implement a simple algebraic OOP example using CLOS. The functionality is as far as I can say as it is supposed to be. The intended approach was to implement a simple example of ideomatic OOP polymorphism. For a greater learning experience I've wanted to show the code to get su... | [] | [
{
"body": "<pre><code>(defmethod evaluate ((node op-node))\n (apply (value node) \n (list (evaluate (left-node node))\n (evaluate (right-node node)))))\n</code></pre>\n\n<p>can be written:</p>\n\n<pre><code>(defmethod evaluate ((node op-node))\n (funcall (value node) \n (evalua... | {
"AcceptedAnswerId": "15046",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T15:55:40.587",
"Id": "15039",
"Score": "3",
"Tags": [
"object-oriented",
"lisp"
],
"Title": "simple \"if\"-less algebraic computation using CLOS"
} | 15039 |
<p>This is for an instrumentation tool using the ASM tree api. This method assigns a <code>handler</code> to a field, which is used in instrumented methods. As a result of my instrumentation, the instrumented class implements an interface and is a handler itself, so a value of <code>this</code> behaves like a NullObjec... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T19:42:00.957",
"Id": "24409",
"Score": "9",
"body": "Without really seeing more of the code a common suggestion is to use inheritance and polymorphism. A first step would be to more common code to code to methods then once that is ... | [
{
"body": "<p>You use of switch is unconventional and in consequence hard to follow. I'd avoid it for that reason. What I see is that that both case are very similar, and so I'd try to refactor them into a function.</p>\n\n<p>Here's my approach:</p>\n\n<pre><code>private void assignHandler(MethodNode method,\n ... | {
"AcceptedAnswerId": "15102",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T17:47:53.467",
"Id": "15043",
"Score": "3",
"Tags": [
"java"
],
"Title": "Instrumentation tool using the ASM tree API"
} | 15043 |
<blockquote>
<p>Assume a 2D [n][n] matrix of 1's and 0's. All the 1's in any row should come before 0's. The number of 1's in any row I should be at least the number of 1's row (i+1). Find a method and write a C program to count the number of 1's in a 2D matrix. The complexity of the algorithm should be order <em>n</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-26T08:47:28.643",
"Id": "24468",
"Score": "1",
"body": "Please format your code nicely to make it easier for everyone else to read. You only need to format it once, but you'll save a lot of people time and increase your chances of gett... | [
{
"body": "<p>I think your main loop should be something more along the lines of</p>\n\n<pre><code>row = n-1; // start at bottom row \nfor (col=0; col<n; col++) { // read columns from left to right\n while ((row >= 0) && (map[row,col] == 0)) { // while not out of rows, and on a 0\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T18:11:27.740",
"Id": "15044",
"Score": "4",
"Tags": [
"algorithm",
"c",
"programming-challenge",
"matrix"
],
"Title": "Devise an algorithm of complexity O(N) finding No of 1's... | 15044 |
<p>I have 16 permutations each with 104 variables using the standard alphabet. The 104 variable permutation is selected based off of compression complexity.
This is one example of the pattern I am able to generate it has a low compression ratio of 1.3 with overhead:</p>
<blockquote>
<p>HHHFHHFFHHFHHFFHHFHHHFHAAAAHHH... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-25T02:12:54.173",
"Id": "24418",
"Score": "3",
"body": "Could you write this up better? I am forced to read the code since I do not understand the description, but the code is not complete either."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>Ok.</p>\n\n<p>Lots of stuff going on here and I'm writing this as I work your example so bear with me...</p>\n\n<p>In you code, polar contains six letters. And you don't care about letter repetition in your top examples so what you are calculating here are not permutations but variations. Secondly... | {
"AcceptedAnswerId": "15232",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T23:17:03.130",
"Id": "15053",
"Score": "4",
"Tags": [
"c#",
"performance",
"combinatorics"
],
"Title": "compression condition permutation"
} | 15053 |
<p>I started learning <code>C</code> a week ago, and here is my implementation for the <code>split</code> function:</p>
<pre><code>char** my_split(const char* str, char delim, int* size)
{
int index = 0, start;
char** results = NULL;
*size = 0;
do
{
if ((*size) % 10 == 0) //top floor reach... | [] | [
{
"body": "<p><strong>Note:</strong> I would take everything I say with a grain of salt. It's been a few years since I used C on a regular basis, and even at my peak with C, I was never very familiar with the standard or certain best practices.</p>\n\n<p>Your function is responsible for cleaning up memory, yet... | {
"AcceptedAnswerId": "15058",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-25T01:33:24.953",
"Id": "15055",
"Score": "5",
"Tags": [
"c"
],
"Title": "C Split function review"
} | 15055 |
<p><code>playerObject</code> is an <code>NSDictionary</code> from <code>JSONObjectWithData:options:error</code>.</p>
<p>I'm trying to update a <code>CoreData</code> entity.</p>
<pre><code>if ([results count] > 0)
{
newPlayer = (Player *)[results objectAtIndex:0];
} else {
//Add a new player
newPlayer =... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T15:53:02.570",
"Id": "24872",
"Score": "1",
"body": "Take a look at JSRestNetworkKit and stop parsing the JSON yourself :) https://github.com/JaviSoto/JSRestNetworkKit"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDat... | [
{
"body": "<pre><code>if ([results count] > 0)\n{\n newPlayer = (Player *)[results objectAtIndex:0];\n} else {\n //Add a new player\n newPlayer = [NSEntityDescription insertNewObjectForEntityForName:@\"Player\" inManagedObjectContext:temporaryContext];\n}\n</code></pre>\n\n<p>This chunk of code coul... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-25T13:05:25.767",
"Id": "15059",
"Score": "5",
"Tags": [
"objective-c",
"json",
"ios"
],
"Title": "Parsing NSDictionary from NSJSONSerialization"
} | 15059 |
<pre><code>import java.util.ArrayList;
public class SumsOfPerfectPowers {
ArrayList<Long> numList = new ArrayList<Long>(5000001);
// status of whether a number is power number
boolean[] result = new boolean[5000001];
public SumsOfPerfectPowers() {
numList.add((long) 0);
nu... | [] | [
{
"body": "<p>A couple of comments:</p>\n\n<ol>\n<li>Generally, it is recommended to declare variables as interface types for extensibility and implementation-neutral as much as possible. You would realize this when writing large programs. Based on this, numList would be of type List or Collection.</li>\n<li>I... | {
"AcceptedAnswerId": "15075",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-25T14:18:46.600",
"Id": "15060",
"Score": "24",
"Tags": [
"java",
"algorithm",
"mathematics"
],
"Title": "Sums of perfect powers"
} | 15060 |
<p>I have this kind of file structure</p>
<blockquote>
<pre><code>MALE:FooBar:32
FEMALE:BarFoo:23
</code></pre>
</blockquote>
<p>Where I would want to identify the gender and age of person, <code><Gender>:<Name>:<age></code></p>
<pre><code>try{
BufferedReader in = new BufferedReader(new FileRea... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T08:06:42.403",
"Id": "24502",
"Score": "0",
"body": "String.split(RegEx) is the now recommended for new Java'versions (StringTokenizer for old version compatibility). With 'palacsint' advices, you code look fine."
}
] | [
{
"body": "<p>I don't think that using <code>:</code> is a bad practice but you have to escape it somehow if it occurs inside your data. Anyway, I'd consider using XML or JSON here.</p>\n\n<p>Some notes about the code:</p>\n\n<ol>\n<li>You should close the stream (in a <code>finally</code> block). See <em>Guide... | {
"AcceptedAnswerId": "15077",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-25T16:59:41.817",
"Id": "15062",
"Score": "5",
"Tags": [
"java",
"file",
"file-structure"
],
"Title": "Reading a line from a text file and splitting its contents"
} | 15062 |
<p>I am new to programming and have written this <code>Data Access Layer</code>. I am using this <code>DAL</code> in my projects. Now, I have a feeling that it is pathetic (when I wrote it, I was kind of happy). Do you guys also feel the same for this <code>DAL</code>. Kindly help me write a better one. There is no <co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-25T18:17:25.387",
"Id": "24444",
"Score": "2",
"body": "Why not use ORM / MVC / EF ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-25T18:21:48.313",
"Id": "24445",
"Score": "0",
"body": "Actua... | [
{
"body": "<p>The first part of the answer has already been given by <a href=\"https://codereview.stackexchange.com/users/9778/leonid\">Leonid</a>: \"don't create your own data access methodology\". Use something like Entity Framework. This is a frequently-used \"wheel\": don't reinvent it.</p>\n\n<p>That said,... | {
"AcceptedAnswerId": "15076",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-25T17:14:55.600",
"Id": "15063",
"Score": "4",
"Tags": [
"design-patterns",
"asp.net",
"vb.net"
],
"Title": "Writing a Data Access Layer"
} | 15063 |
<p>I tried to solve the <a href="https://www.interviewstreet.com/challenges/dashboard/#problem/4f7272a8b9d15" rel="nofollow">Unfriendly Number</a> problem on InterviewStreet:</p>
<blockquote>
<p>There is one friendly number, K, and N unfriendly numbers. We want to find
how many numbers are there which exactly divi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T15:30:52.913",
"Id": "24440",
"Score": "0",
"body": "It might be more efficient to replace the `length . filter not . map try` chain with a fold like `foldl (\\count t -> if try t then count + 1 else count) 0` (probably with more st... | [
{
"body": "<p>Your divisors generation is lacking. As explained e.g. <a href=\"https://stackoverflow.com/a/12052561/849891\">here</a>, you should generate them from a number's prime factorization. It is much faster that way.</p>\n\n<p>You may try using <code>rem</code> instead of <code>mod</code>.</p>\n\n<p>Als... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T15:19:07.650",
"Id": "15064",
"Score": "2",
"Tags": [
"haskell",
"time-limit-exceeded"
],
"Title": "\"Unfriendly Number\" challenge"
} | 15064 |
<p>I often get lines like this in my Apache error log:</p>
<blockquote>
<p>File does not exist: /path/to/www/data:image/gif;base64,R0lGODlhBgAGAIAOAP/yH5BAEACAEALAAAAAAGGAYAAAIJhB0Xi5vOoFwFADs=</p>
</blockquote>
<p>Obviously, this is due to somebody using an outdated browser (or a robot) which doesn't handle inline... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-25T18:23:58.363",
"Id": "24446",
"Score": "0",
"body": "@W3Coder Asking about voting is inappropriate for the comments section. Please refrain from asking about downvotes in the future."
}
] | [
{
"body": "<p>The only real problem I see is that if the browser is really \"last century\" it probably won't support a long enough query string to contain the full image. So your returned image might be incomplete. Another thing is that this would waste a lot of bandwidth.</p>\n\n<p>I see two options</p>\n\n<u... | {
"AcceptedAnswerId": "15116",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-18T11:08:52.147",
"Id": "15066",
"Score": "1",
"Tags": [
"regex",
"error-handling",
"perl",
"base64",
"cgi"
],
"Title": "Perl CGI script to respond to erroneous Base64 ima... | 15066 |
<p>I am trying to simplify the following massive conditional statement but have no idea how to. Does anyone have suggestions for it?</p>
<pre><code>//regular elements use the normal position variables.
var tooltipXPos = xPos;
var tooltipYPos = yPos-$tooltipElement.height()-YOffset;
//individual elements position shi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T15:57:25.447",
"Id": "24447",
"Score": "0",
"body": "Problem is, it's not a massive conditional. It's just a lot of individual conditionals. Could use a switch I guess..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<p>Create an array which contains : </p>\n\n<ul>\n<li>the id of element</li>\n<li>the offset x</li>\n<li>the offset y </li>\n</ul>\n\n<p>then, loop on each element of this array and do a single if.</p>\n\n<p>Something like that (not tested)</p>\n\n<pre><code>var items = [\n {name: '#te_classbuilde... | {
"AcceptedAnswerId": "15068",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T15:55:03.257",
"Id": "15067",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"css"
],
"Title": "Positioning a tooltip relative to various kinds of elements"
} | 15067 |
<p>Similar to, but distinct from <a href="https://codereview.stackexchange.com/questions/12112/poker-hand-identifier">Poker hand identifier</a>. I'm working towards solving <a href="http://codingdojo.org/cgi-bin/wiki.pl?KataPokerHands" rel="nofollow noreferrer">this kata</a>. The below code doesn't print the result yet... | [] | [
{
"body": "<p>It's generally a good idea to give explicit type signatures for your top level definitions. It helps your code's readers (e.g. us) understand your code.</p>\n\n<p><code>hasGroupOf</code> looks perfectly clear (save for the missing type signature), but I'd write the other two like this:</p>\n\n<pre... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-26T03:13:24.637",
"Id": "15079",
"Score": "2",
"Tags": [
"haskell",
"playing-cards"
],
"Title": "Poker Hand Kata"
} | 15079 |
<p>I have a database schema for a game to hold save files where some tables have a one-to-one relationship to classes. I was wondering if I should split up some tables.</p>
<p>Example: <code>troop_class table</code>. It could have a PK of</p>
<blockquote>
<pre><code>{ GameID,PostionX,PostionY,PostionZ,Team }
</code>... | [] | [
{
"body": "<p>Here are a few suggestions, many of which are just \"best practices\" I've picked up along the way (or simplifications that would make things a bit more concise and easier to read). There are also a few ideas that will likely prevent common errors from happening to the code as it's maintained in ... | {
"AcceptedAnswerId": "24554",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-26T11:04:23.513",
"Id": "15082",
"Score": "15",
"Tags": [
"game",
"sql",
"mysql"
],
"Title": "Database schema for holding game save files"
} | 15082 |
<p>I'm developing a <a href="http://duc.pagodabox.com/product.php" rel="nofollow noreferrer">JS-based app</a> that allows you to customize a product. I still consider myself a super newbie to javascript and especially to object oriented programming. So far, so good, the app does what I want it to do, so no trouble ther... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-03T21:16:22.047",
"Id": "24819",
"Score": "0",
"body": "In `updateCost()`, why do you pass `addCost` when you set it to 0?"
}
] | [
{
"body": "<p>Here are few things that I noticed with Product.js:</p>\n\n<ol>\n<li><p>The Module design pattern is normally used to create private functions and variables. Unless if <code>\"use strict\"</code> is required, then there's no point in wrapping your code inside a closure when all the functions and v... | {
"AcceptedAnswerId": "15310",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-26T19:33:00.723",
"Id": "15088",
"Score": "8",
"Tags": [
"javascript",
"object-oriented"
],
"Title": "JavaScript-based product customization app"
} | 15088 |
<p>I put together this code to for the Udacity cs101 exam. It passes the test, but I feel their must be a more elegant way to manage this problem. Some help from a module (like itertools).</p>
<p>Question 8: Longest Repetition</p>
<p>Define a procedure, longest_repetition, that takes as input a
list, and returns th... | [] | [
{
"body": "<p>Take a look at <a href=\"http://docs.python.org/library/collections.html#collections.Counter\" rel=\"nofollow\">collections.Counter</a>. It will do your work for you.</p>\n\n<pre><code>>>> Counter(['a', 'b', 'b', 'b', 'c', 'd', 'd', 'd']).most_common(1)\n[('b', 3)]\n</code></pre>\n\n<p>UP... | {
"AcceptedAnswerId": "15095",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T04:58:16.900",
"Id": "15089",
"Score": "2",
"Tags": [
"python"
],
"Title": "pythonic longest repetition"
} | 15089 |
<p>I'm making a simple httpcode monitor as an example for teaching myself PHP OOP. I have written the code below and would be interested in having it improved.</p>
<p>In particular, I'm not sure about this line:</p>
<pre><code>$httpcode = $website->get_httpcode($url);
</code></pre>
<p>This seems very inefficient ... | [] | [
{
"body": "<p>Two things:</p>\n\n<ol>\n<li><p><em>Always</em> specify the visibility. Don't use the old <code>var</code> keyword, use <code>public</code>, <code>private</code> or <code>protected</code>. Since the class-member <code>$url</code> contains internal information, you'll probably want to <a href=\"htt... | {
"AcceptedAnswerId": "15094",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T08:10:32.767",
"Id": "15093",
"Score": "3",
"Tags": [
"php",
"object-oriented",
"http",
"url"
],
"Title": "Simple httpcode monitor"
} | 15093 |
<p>I have a list of friends and new friends are added via a form. When you click on a friend you see all the information about him. There is also an <kbd>Edit</kbd> button. When clicking it, I want a form to be displayed (the same as the form for adding) but already filled with the current information about the friend... | [] | [
{
"body": "<p>That HTML looks like Jekyll, or something very similar... Just out of curiosity, what is that, twig?</p>\n\n<p>Anyways... The first thing you can do is follow the \"Don't Repeat Yourself\" (DRY) Principle. Both of your methods have very similar contents and could benefit from sharing those resourc... | {
"AcceptedAnswerId": "15103",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T10:23:47.273",
"Id": "15096",
"Score": "3",
"Tags": [
"php",
"form",
"symfony2"
],
"Title": "Friends edit form"
} | 15096 |
<pre><code>forceTwoDigits = (val) ->
if val < 10
return "0#{val}"
return val
formatDate = (date) ->
year = date.getFullYear()
month = forceTwoDigits(date.getMonth()+1)
day = forceTwoDigits(date.getDate())
hour = forceTwoDigits(date.getHours())
minute = forceTwoDigits(date.getMinutes())
sec... | [] | [
{
"body": "<p>Updated:</p>\n\n<pre><code>formatDate = (date) ->\n timeStamp = [date.getFullYear(), (date.getMonth() + 1), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()].join(\" \")\n RE_findSingleDigits = /\\b(\\d)\\b/g\n\n # Places a `0` in front of single digit numbers.\n timeSt... | {
"AcceptedAnswerId": "15299",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T11:27:26.923",
"Id": "15097",
"Score": "4",
"Tags": [
"javascript",
"strings",
"coffeescript"
],
"Title": "CoffeeScript date formatting"
} | 15097 |
<p>I have a byte array in a C# program.</p>
<p>I want to determine as quickly as possible if the content is Xml. If it's the case, I also want to return the Xml itself.</p>
<p>By now I have this method :</p>
<pre><code> protected bool TryGetXElement(byte[] body, out XElement el)
{
el = null;
/... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T13:27:40.300",
"Id": "24513",
"Score": "0",
"body": "Why do you need to do this? Can't you figure out whether it's XML some other way?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T13:35:14.580",
... | [
{
"body": "<p>Why not verify if a root node exists rather than check for a '<' ?</p>\n\n<pre><code> public bool GetRootNode(XmlReader reader)\n {\n bool isValid;\n try\n {\n while (reader.Read())\n {\n if (reader.NodeType == XmlNodeType.Element)... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T12:41:33.010",
"Id": "15100",
"Score": "5",
"Tags": [
"c#",
"xml"
],
"Title": "Checking and returning Xml from a byte array"
} | 15100 |
<p>The errors are passed through every callback, but in fact, it might be better to throw an error at higher levels. For example, look at the mongodb.js database function. It passes through an error in the callback. However, if there was an error at that level, it might be better to deal with it at that point and just ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-04T23:02:37.490",
"Id": "70058",
"Score": "0",
"body": "Have you tried https://github.com/caolan/async#waterfall ? I would use it and handle errors in the callback."
}
] | [
{
"body": "<p>First, there is a principle you should be reminded: \n<strong>Never deal with the error you don't know, just pop it up.</strong></p>\n\n<p>Which means, if you can't deal with or don't know about the error passed in the callback, you just pass it to next callback, or throw it(A pattern of <strong>C... | {
"AcceptedAnswerId": "15272",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T16:43:24.880",
"Id": "15106",
"Score": "6",
"Tags": [
"javascript",
"node.js",
"error-handling",
"callback"
],
"Title": "Node.js callback error pattern"
} | 15106 |
<p>I am studying descriptors. They work with class varibles out of the box, but I want them to operate on instance variables too, so I did this:</p>
<pre><code>class NumberDescriptor(object):
def __init__(self,name):
self.name = name
def __set__(self, instance, value):
if not isinstance(value,... | [] | [
{
"body": "<p>That looks reasonable; but you should handle the case of when the descriptor is invoked from the class: <code>Human.age</code>. In that case, <code>__get__</code> is invoked with None as an argument to instance. If you've no better use for it; you can just return the descriptor itself:</p>\n\n<p... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T18:10:35.773",
"Id": "15108",
"Score": "2",
"Tags": [
"python",
"object-oriented"
],
"Title": "Using descriptors with instance variables to store a human's age"
} | 15108 |
<p>I have an ASP.NET MVC3 web application that displays a list of parts (a part is a simple entity with a number and a description). </p>
<p>I have updated the action method to support filtering and paging:</p>
<pre><code>[HttpGet]
public ViewResult Index(int page = 1, int pageSize = 30, string filter = "All")
{
... | [] | [
{
"body": "<p>You can construct LINQ queries step by step instead of writing them all at once</p>\n\n<pre><code>parts = Database.Parts;\nif (filter == \"123\") {\n parts = parts.Where(p => p.Number[0].IsDigit())\n} else if (filter != \"All\") { // Alphabetic filter\n parts = parts.Where(p => p.Numbe... | {
"AcceptedAnswerId": "15111",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T20:03:05.320",
"Id": "15110",
"Score": "5",
"Tags": [
"c#",
"linq",
"asp.net-mvc-3"
],
"Title": "Locating a list of parts"
} | 15110 |
<p>I'm toggling on/off series in chart and was wondering if I was doing anything crazy.</p>
<p>Is the atom really a good idea here?</p>
<pre><code>;; ================ Graph data ================
(def serie1 {:label "Bar" :data [[11 13] [19 11] [30 -7]]})
(def serie2 {:label "Foo" :data [[10 1] [17 -14] [30 5]]})
(de... | [] | [
{
"body": "<p>If your dataset were coming from an outside source, like an API call, I'd say the atom would make sense. In this case, your dataset is static. In that case, I think I might find it more intuitive to use a var for the series and then select the items out that you want to plot. In that case, you... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T20:40:02.690",
"Id": "15112",
"Score": "3",
"Tags": [
"clojure"
],
"Title": "Toggle chart series in clojurescript"
} | 15112 |
<p>Here is a Python script I wrote earlier for rapidly requesting a file from a server and timing each transaction. Can I improve this script?</p>
<pre><code>from time import time
from urllib import urlopen
# vars
url = raw_input("Please enter the URL you want to test: ")
for i in range(0,100):
start_time = time... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T20:53:26.160",
"Id": "24534",
"Score": "0",
"body": "Are you trying to time the whole operation (checking the file 100 times) or just one opening? Are you interested in the number of times where you could get a proper `pic.getcode()... | [
{
"body": "<p>Here are some comments on your code:</p>\n\n<ol>\n<li><p><code>raw_input</code> is a very inflexible way to get data into a program: it is only suitable for interactive use. For more general use, you should get your data into the program in some other way, for example via command-line arguments.</... | {
"AcceptedAnswerId": "15143",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-27T20:44:00.267",
"Id": "15113",
"Score": "4",
"Tags": [
"python"
],
"Title": "Rapidly requesting a file from a server"
} | 15113 |
<p>I just spent some time putting together a simple protocol and implementation for packetizing byte streams (<a href="https://github.com/nickpascucci/S3P" rel="nofollow noreferrer">on GitHub here</a>). The project is aimed at embedded systems that need a very lightweight way to pass discrete messages across serial lin... | [] | [
{
"body": "<p>A few comments...</p>\n\n<p>I'm no expert in data transmission, but there are sure to be some on StackOverflow who are. Perhaps you could discuss optimal encoding schemes there. Yours may or may not be optimal, but has some peculiarities. In particular, it is not easy to determine the packet leng... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T04:06:32.073",
"Id": "15119",
"Score": "2",
"Tags": [
"c",
"networking"
],
"Title": "Style and Best Practices for C99 Packetization Functions"
} | 15119 |
<p>This is from a C# library I'm writing that checks for updates through a PHP script.</p>
<pre><code>public bool CheckForUpdate(Request Request)
{
HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(UpdateServerAddress + "http://{0}/update.php?{1}" + Request.ToString());
httpRequest.UserAgent =... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T07:49:07.677",
"Id": "24538",
"Score": "0",
"body": "it looks fine to me, readable, does the job, I can't see how or why to reduce the code size."
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-10-27T05:16:... | [
{
"body": "<p>You could use <a href=\"http://www.codinghorror.com/blog/2006/01/flattening-arrow-code.html\" rel=\"nofollow\">guard statements</a> and extract out the <code>switch(response.StatusCode)</code> block to a method. Furthermore, I'd replace the three-letter magic strings with constants. Their name cou... | {
"AcceptedAnswerId": "15129",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T05:05:20.383",
"Id": "15120",
"Score": "3",
"Tags": [
"c#",
".net",
"web-services"
],
"Title": "Is this too long for a web request?"
} | 15120 |
<p>I was using such code:</p>
<pre><code>class Counter
{
private int i = 0;
public int Next()
{
lock (this)
{
return i++;
}
}
public void Reset()
{
lock (this)
{
i = 0;
}
}
}
</code></pre>
<p>I refactored it such a ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T08:52:29.337",
"Id": "24541",
"Score": "0",
"body": "I would use `Thread.VolatileWrite()` (or `Volatile.Write()`) in your `Reset()`, but I'm not sure whether it's actually necessary."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>It should also be fine in earlier versions of .NET as you are not using any 4.5 specific classes or language features.</p>\n\n<p>The reset is fine as the assignment is atomic as you mentioned, however if you were using a <code>long</code> then you would want to use <code>Interlocked.Exchange</code... | {
"AcceptedAnswerId": "17985",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T08:01:32.427",
"Id": "15121",
"Score": "12",
"Tags": [
"c#",
".net",
"thread-safety",
"lock-free"
],
"Title": "Thread-safe lock-free counter"
} | 15121 |
<p>I have to check a given amount of regular expressions, which are defining number ranges for dial plans, against an input number range.
The target is to check and see, if any of the numbers in the range are free, or which regular expression matches for the number. Last situation is said to be an occupied number, othe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-17T08:35:24.230",
"Id": "25496",
"Score": "1",
"body": "Welcome to Code Review! It's quite hard to see for ourselves what's taking a lot of time. How many regexes? How large can the range be? Is it possible to define a regex that would... | [
{
"body": "<p>Well, REGEX is actually your first problem. A REGEX function is typically slower than its string/int counterparts. So, if you can do something with a normal function, or a few normal functions, it is normally preferable to REGEX. This is why so many people say REGEX is bad. Its not bad, just misus... | {
"AcceptedAnswerId": "15145",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T08:05:39.350",
"Id": "15122",
"Score": "3",
"Tags": [
"php",
"regex"
],
"Title": "Lots of RegEx match against huge number range (PHP)"
} | 15122 |
<p>I know there are some answers about a user function to split chars and I have one already running (found one years ago in the net and modified it to my own needs).</p>
<p>Since I use this function very often, I'd like to ask the best SQL professionals (which are probably here) to review this function for performanc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T09:06:15.807",
"Id": "24542",
"Score": "0",
"body": "Oh yes, my bad. Can a moderator move this post please?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T11:06:01.740",
"Id": "24544",
"Score... | [
{
"body": "<p>try this:</p>\n\n<pre><code>Create function dbo.SplitString(@inputStr varchar(1000),@del varchar(5))\nRETURNS @table TABLE(col varchar(100))\nAs\nBEGIN\n\nDECLARE @t table(col1 varchar(100))\nINSERT INTO @t\nselect @inputStr\n\nif CHARINDEX(@del,@inputStr,1) > 0\nBEGIN\n ;WITH CTE1 as (\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T08:51:49.910",
"Id": "15125",
"Score": "4",
"Tags": [
"sql",
"sql-server"
],
"Title": "SQL Server Split function"
} | 15125 |
<p>Let me start with a little introduction. I am in the process of learning OOP in PHP. I have also researched Design Patterns but have not yet fully grasped the different types of concepts. I am at the stage where every few months I realise that I am not doing things the correct way and have to change my style. <stron... | [] | [
{
"body": "<p>Congratulations, that means you are learning. You'll be at that stage for some time. In fact, I don't think you'll ever truly leave it, or if you do, then you should be concerned. The time between \"changes\" might increase, but you should never stop learning and should always find some way you ca... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T12:21:11.510",
"Id": "15130",
"Score": "4",
"Tags": [
"php",
"object-oriented",
"design-patterns",
"mysql"
],
"Title": "What is the correct way to set up my classes in OOP pro... | 15130 |
<p>I am just trying to use ASP.NET MVC using repository pattern. Could somebody see If I am doing something wrong here.</p>
<p><strong>Model</strong> - Contains the model</p>
<pre><code>public class Contact
{
public int Id { get; set; }
public string FirstName { get; set; }
public string L... | [] | [
{
"body": "<p>You code shows not only your definition of your repository but also it's usage.</p>\n\n<p>What worries me is that i don't see how the DbContext (AddressBookDB in this case) is disposed off.</p>\n\n<p>I think i'd rather pass in the AddressBookDB object as a paramter to the repository constructor fo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-11-24T22:44:11.133",
"Id": "15132",
"Score": "3",
"Tags": [
"c#",
"asp.net",
"asp.net-mvc-3"
],
"Title": "ASP.NET MVC using Repository pattern - code review"
} | 15132 |
<p>I'm a Pthreads newbie and I've been giving myself a challenge: I want to have a resource that multiple threads can access at the same time as read. However, if a thread wants to write, then this need to be exclusive.</p>
<p>Now, I know that there are read/write locks designed specifically for this purpose. I would ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-11-13T01:13:15.787",
"Id": "24552",
"Score": "0",
"body": "This is a huge code dump. You're right for asking, because testing almost by definition won't find bugs in concurrency. But the answer to this is probably \"take an OS class\". As... | [
{
"body": "<p>You forgot to remove the \"stupid waiting\" from version 2. Otherwise, it looks good. Not particularly efficient, but correct.</p>\n\n<p>You can and should remove this chunk of code from version 2. The code before it already does this:</p>\n\n<pre><code> // Do a stupid waiting\n while(true)\... | {
"AcceptedAnswerId": "15137",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-11-13T01:06:02.430",
"Id": "15136",
"Score": "4",
"Tags": [
"c++",
"multithreading",
"locking",
"pthreads"
],
"Title": "Accessing limited resources with Pthreads"
} | 15136 |
<p>I'm working on the floors of a building, using SVG objects generated by Raphael.js. All objects are clickable and all have different shapes, but all of them have the same actions. The code below is just a little sample. How could I optimize it?</p>
<pre><code>// FLOOR 00
var budA4_0 = new Raphael(document.getE... | [] | [
{
"body": "<p>As you noticed, you are violating DRY ( Dont repeat yourself ).</p>\n\n<p>Your code has plenty of repetitions, part of the trick is try and catch them all</p>\n\n<ul>\n<li>My assumption is that <code>A4</code> is the name or number of the building, that should be 1 variable in the whole code</li>\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T14:27:22.900",
"Id": "15141",
"Score": "1",
"Tags": [
"javascript",
"raphael.js",
"fancybox"
],
"Title": "Combining Raphael.js objects for working on floors of a building"
} | 15141 |
<p>I used the following Javascript to sort an unnumbered list of numeric li-tags as follows:</p>
<pre><code>// 1. get the <UL>-element from the BODY
var nList = document.getElementById("allItems");
// 2. extract all the <LI>-elements from that <UL> and put it in a NodeList
var nEntry = nList.getEleme... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T14:56:45.297",
"Id": "24570",
"Score": "0",
"body": "sources that I based this code on: [sorting a node list](http://stackoverflow.com/questions/4760080/how-can-i-reorder-sort-a-nodelist-in-javascript), [changing the order of `<LI>`... | [
{
"body": "<p>There are a few clear improvements I can see when you are reinserting the nodes back into the DOM tree. </p>\n\n<pre><code>for (i=0; i<nEntryArray.length; i++)\n{\n nList.appendChild(nEntryArray[i]);\n}\n</code></pre>\n\n<p>1) You may benefit from using a documentFragment to build up your ele... | {
"AcceptedAnswerId": "15146",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T14:48:48.290",
"Id": "15144",
"Score": "4",
"Tags": [
"javascript",
"sorting"
],
"Title": "Sorting numeric <LI> tags without omitting the attributes"
} | 15144 |
<p>This code works, but I get the feeling that it could be shorter and simpler. Any ideas?</p>
<pre><code>private void CheckNameCase(Models.PersonalInformationModels.PersonalInformationModel model)
{
// if first middle and last names are all upper or lower case then title case the name
//Name
string firs... | [] | [
{
"body": "<p>Good layout and spacing.</p>\n\n<p>My first observation is that you are repeating yourself many times over. If you look closely, all of the checks are the same. If you find duplicate code, move them out into a function.</p>\n\n<p>Second observation is you are coding lengthy namespaces. Learn ab... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T15:24:58.603",
"Id": "15148",
"Score": "5",
"Tags": [
"c#",
"strings"
],
"Title": "Title case name when first, middle and last are all upper or lower case"
} | 15148 |
<p>In a project I'm working on, the data access layer has evolved to something that somewhat resembles the Unit Of Work and Repository patterns, at least they started with those names, I'm not entirely sure with how far they've drifted, if they can still be called that.</p>
<p>For classes data access, an implementatio... | [] | [
{
"body": "<p>If all your business classes (e.g., <strong>User</strong>) could inherit from a common class or interface that has <strong>Modified</strong> and <strong>ModifiedBy</strong> properties, you could make your <strong>Repository</strong> a generic <strong>Repository<T></strong>. Class-specific me... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T16:01:38.120",
"Id": "15149",
"Score": "4",
"Tags": [
"c#",
"design-patterns"
],
"Title": "Unit Of Work/Repository usage"
} | 15149 |
<p>I have this rather verbose piece of code. How can I get it shorter and simpler?</p>
<p>This function aggregate results of test by population and by different keys:</p>
<pre><code>def aggregate(f):
""" Aggregate population by several keys """
byMerchant = col.defaultdict(lambda: col.defaultdict(lambda: [0,0,0,... | [] | [
{
"body": "<p>If I try to split on the empty string I get an error:</p>\n\n<pre><code>>>> 'a b c'.split('')\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nValueError: empty separator\n</code></pre>\n\n<p>Perhaps you meant <code>.split()</code>?</p>\n\n<p>Anywa... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T16:49:46.280",
"Id": "15151",
"Score": "2",
"Tags": [
"python"
],
"Title": "Aggregate by several keys"
} | 15151 |
<p>I've seen the pattern:</p>
<pre><code><?php
if ($node = node_load(30) && $node->type == 'bogus') {
print $node->title . 'is bogus';
}
</code></pre>
<p>But when I tried to use it I got a warning: variable not defined... Has this pattern of declaring variables while you loop in an if been de... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T09:26:26.060",
"Id": "24926",
"Score": "0",
"body": "Where is the loop?"
}
] | [
{
"body": "<p>I could only wish... No, it has not been deprecated, but it should be. I seriously suggest that you don't use this syntax. It is too easy to accidentally assign a variable in a statement, which can result in similar errors. If you make a habit of avoiding this syntax it will make debugging that mu... | {
"AcceptedAnswerId": "15343",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T19:30:37.760",
"Id": "15157",
"Score": "1",
"Tags": [
"php"
],
"Title": "Setting a variable during an if loop"
} | 15157 |
<p>I am getting information from an XML document and for the most part everything runs as it should. Occasionally, I get a php fatal error Call to a member function children() on a non-object. I have tried to use this</p>
<pre><code>if(isset($current->AttributeSets->children('ns2', true)->ItemAttributes->L... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T20:38:20.237",
"Id": "24591",
"Score": "0",
"body": "This should really be moved to SO as this is not a request for a review, but for help. Also, you might think about adding more information. There isn't nearly enough here to answe... | [
{
"body": "<p>The trouble is that your check can fail. Before you can call the <code>children</code> method you need to be sure that you are dealing with an object (that provides the <code>children</code> method). This is actually what your fatal error is telling you (<code>$current->AttributeSets</code> i... | {
"AcceptedAnswerId": "15184",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T19:49:14.987",
"Id": "15158",
"Score": "1",
"Tags": [
"php",
"xml"
],
"Title": "Error handling data from XML document"
} | 15158 |
<p>In an attempt to learn more about Clojure's parallel computation functions, I devised the following task: calculate a factorial in parallel using <code>pmap</code>, <code>pcalls</code> and <code>pvalues</code>. </p>
<p>The idea is to split the factorial sequence into sub-computations, reducing the final output of e... | [] | [
{
"body": "<p>1) that is quite idomatic Clojure from what I have seen.</p>\n\n<p>2) macros are \"contagious\" if the thing you are trying to call is a macro and you want to do anything requiring first-class-functions (map apply reduce etc...) then the thing doing the <code>apply</code>ing must it's self be a ma... | {
"AcceptedAnswerId": "15162",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-28T21:24:53.850",
"Id": "15160",
"Score": "0",
"Tags": [
"clojure"
],
"Title": "Calculating a factorial with parallel sub-computations using pmap, pvalues and pcalls"
} | 15160 |
<p>I'm a bit concerned about function usage. There are so many different libraries/possible ways to do something that I'm not sure if the way I'm working at the moment is reasonable, or what I could modify to have a better code.</p>
<p>Also, I'm searching on how to optimize this code, since for a small 25MB file the m... | [] | [
{
"body": "<p>You can use <code>HLint</code> tool to get rid of few extra parentheses, and use <code><$></code> instead of <code>liftM</code>:</p>\n\n<pre><code>contents <- B.lines <$> B.readFile filename\n</code></pre>\n\n<p>Other than that I don't see anything to be improved in your code at low... | {
"AcceptedAnswerId": "15331",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T00:18:20.390",
"Id": "15164",
"Score": "3",
"Tags": [
"haskell",
"memory-management",
"csv",
"signal-processing"
],
"Title": "Reading a data file for performing a FFT"
} | 15164 |
<p>I have the following Ruby code snippet:</p>
<pre><code> url = "http://somewiki.com/index.php?book=#{author}:#{title}&action=edit"
encoded = URI.encode(url)
encoded.gsub(/&/, "%26").sub(/%26action/, "&action")
</code></pre>
<p>The last line is needed since I have to encode the ampersands (<code>&am... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-03-08T13:51:33.040",
"Id": "507244",
"Score": "0",
"body": "See https://stackoverflow.com/a/36191180/520567 , you can use a specified parser."
}
] | [
{
"body": "<p>Unless you need the unencoded url (for logging?), I would just:</p>\n\n<pre><code>encoded_url = \"http://somewiki.com/index.php?book=#{CGI.escape(author)}:#{CGI.escape(title)}&action=edit\"\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | {
"AcceptedAnswerId": "15271",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T00:35:13.457",
"Id": "15165",
"Score": "5",
"Tags": [
"ruby"
],
"Title": "Encoding special characters in URLs with Ruby"
} | 15165 |
<p>I'm in the process of building a website for the company I work for and I'm trying to think of the best way to namespace and organize the site's JavaScript code.</p>
<p>I've written several jQuery/JavaScript plugins for the big chunks of code, but now I'd like a namespaced place to "call" said plugins and any other... | [] | [
{
"body": "<p>One problem in your code is that the \"modules\" aren't standalone. You'd be adding the \"modules\" for calling into the <code>init</code> every time a new on is made.</p>\n\n<p>To avoid doing so, each module should register itself for <code>init</code>. You can do this by adding a \"register\" fu... | {
"AcceptedAnswerId": "15181",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T01:03:23.577",
"Id": "15166",
"Score": "7",
"Tags": [
"javascript"
],
"Title": "Organizing JavaScript code for a website"
} | 15166 |
<p>I have the following code in a portion of my program that hides/shows certain elements based on the status of a certain checkbox:</p>
<pre><code>private void enableFolderVariableRemoval_CheckedChanged(object sender, EventArgs e)
{
if (enableFolderVariableRemoval.Checked)
{
cleanFolderTextPanel.Visib... | [] | [
{
"body": "<p>Not sure if there are any other constraints but here is one possible solution:</p>\n\n<pre><code>private void enableFolderVariableRemoval_CheckedChanged(object sender, EventArgs e)\n{\n cleanFolderTextPanel.Visible = enableFolderVariableRemoval.Checked; \n cleanTextPanel.Visible = cleanFolde... | {
"AcceptedAnswerId": "15170",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T01:14:05.530",
"Id": "15168",
"Score": "3",
"Tags": [
"c#",
".net",
"winforms"
],
"Title": "Showing/hiding controls based on event"
} | 15168 |
<p>To help learn the SharePoint object model (primarily for SharePoint 2007), I've been working on a class library with a number of useful functions. I'm a junior developer and this is my first C# project of this nature.</p>
<p>With this in mind, how can I improve the class below? What bad habits do I have or what sho... | [] | [
{
"body": "<p>Good job on the formatting and using using.</p>\n\n<p>There's a few things I can see to clean this up.</p>\n\n<p>Is there a reason you are not using var to declare obvious variables? I would suggest to use it whenever you can.</p>\n\n<p>I would move the Console.WriteLine logging into a separate c... | {
"AcceptedAnswerId": "15174",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T01:35:59.150",
"Id": "15169",
"Score": "1",
"Tags": [
"c#",
"object-oriented",
"sharepoint"
],
"Title": "SharePoint class"
} | 15169 |
<p>I'm using this form to submit articles into the database:</p>
<pre class="lang-html prettyprint-override"><code><form enctype="multipart/form-data" method="post" action="add.php">
<input name="title" type="text">
<input name="image" type="file">
<textarea name="text"></textarea>... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2010-12-27T15:57:21.727",
"Id": "24601",
"Score": "0",
"body": "I would be able to upload a script and take over your server :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-06T12:06:17.370",
"Id": "98994",
... | [
{
"body": "<p>There are quite few things to note in your code.</p>\n\n<p>First of all, you are using deprecated <code>$HTTP_POST_FILES</code> where as you should use <code>$_FILES</code></p>\n\n<p>You are not using <a href=\"http://php.net/manual/en/function.mysql-real-escape-string.php\"><code>mysql_real_escap... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2010-12-27T12:31:00.850",
"Id": "15172",
"Score": "8",
"Tags": [
"php",
"network-file-transfer"
],
"Title": "Bad code to handle image upload"
} | 15172 |
<p>I have a rather large class that needs to provide a reasonable amount of output for debugging purposes. I've done this with the following:</p>
<pre><code>#if DEBUG
Console.WriteLine("Source Site Set to: {0}", archiveQueueEntity.SourceSite);
Console.WriteLine("Source List Set to: {0}", archiveQueueEntity.SourceUrl);... | [] | [
{
"body": "<p>I think it would be much cleaner to utilize partial methods to create your logging statements. That way you can log wherever you need it and can disable the code my omitting it the logging function definition. By using partial methods, if the definition is omitted, no IL is generated for the met... | {
"AcceptedAnswerId": "15178",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T06:44:20.543",
"Id": "15176",
"Score": "14",
"Tags": [
"c#"
],
"Title": "Is there a cleaner way to add DEBUG comments?"
} | 15176 |
<p>I am using this code to insert and retrieve:</p>
<pre><code>namespace Gridwebpart.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SPWeb site = SP... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T13:22:44.227",
"Id": "24618",
"Score": "0",
"body": "Nope, looks like the textbook example to me."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T05:37:12.800",
"Id": "24657",
"Score": "0",
... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T07:45:36.287",
"Id": "15177",
"Score": "2",
"Tags": [
"c#",
"sharepoint"
],
"Title": "Is there any better way to insert and retrieve data into SPList?"
} | 15177 |
<p>I'm a developer at a networking company that really has no peers that work above me that I can use for any sort of sounding board for my code, so it's just me. I was wondering if anyone would be willing to take a look at some of my code and just give me a few notes, bullet points, etc... on things that are wrong, t... | [
{
"ContentLicense": "CC BY-SA 2.5",
"CreationDate": "2010-12-27T15:55:04.973",
"Id": "24612",
"Score": "4",
"body": "Your code looks very clean and your naming convention is pretty good. The only thing I would prefer to do is to make the code object oriented by using functions as objects. Oth... | [
{
"body": "<p>From perusing your code a few times:</p>\n\n<p><strong>Custom event abuse</strong></p>\n\n<p>While it's very cool to have custom events, I would simply remove this extra layer of logic. It does not make sense to call <code>$(networkInfo).trigger('selectNetworkRanges');</code> if you could just cal... | {
"AcceptedAnswerId": "45277",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2010-12-27T15:43:51.290",
"Id": "15182",
"Score": "29",
"Tags": [
"javascript",
"jquery",
"networking"
],
"Title": "Managing network address information"
} | 15182 |
<p>So I have a view model (asp.net mcv 3 app) that when instantiated with a particular parameter, populates it's properties via a couple of calls to a web service in it's constructor. </p>
<pre><code>public class QuizPreviewViewModel
{
private IQuizServiceWrapper _service;
public string QuizName { get; set; }... | [] | [
{
"body": "<p>IMHO, you're asking the constructor to do too much work. To put it another way, the constructor has too many points of failure.</p>\n\n<ol>\n<li>You nicely set up <strong>_service</strong> to be a dependency-injectable interface; doesn't it make sense to follow that up by injecting a concrete inst... | {
"AcceptedAnswerId": "15194",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T17:39:31.827",
"Id": "15188",
"Score": "6",
"Tags": [
"c#",
"asp.net-mvc-3",
"constructor"
],
"Title": "Self populating view models"
} | 15188 |
<p>For logging purposes, I need to output a double[,] to the log file. So I need to represent the array as a string.</p>
<p>The following code gets the job done using basic C# 1 features, but I was wondering if there is a more elegant solution using Linq:</p>
<pre><code>private static string OneRowPerLine(double[,] n... | [] | [
{
"body": "<p>First off, I think there may be bugs in your code. Specifically in the dimension parameters of some of the <code>GetLowerBound()</code> parameters. Based on a quick glance, it should be:</p>\n\n<pre><code>private static string OneRowPerLine(double[,] numbers)\n{\n var ret = new StringBuilder();... | {
"AcceptedAnswerId": "15192",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T20:05:34.403",
"Id": "15191",
"Score": "3",
"Tags": [
"c#",
"linq"
],
"Title": "Is there a better way to convert two-dimentional array to string?"
} | 15191 |
<p>I am developing a webapp with Ruby on Rails to expand the features of <a href="http://mite.yo.lk" rel="nofollow">mite</a> (online time-tracking app) with the help of the offical mite API. Unfortuanaly, the API can't return all projects by a specific customer id. Because of that, i am developing a workaround.</p>
<p... | [] | [
{
"body": "<p>You should save projects in array or something like it, not hash. For example</p>\n\n<pre><code> Mite::Customer.all.each do |customer|\n @customers[customer.id] = {:name => customer.name, :projects => []} # !!!\n end\n\n Mite::Project.all.each do |project|\n @customers[project.custo... | {
"AcceptedAnswerId": "15206",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T20:20:06.573",
"Id": "15193",
"Score": "0",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "How to create associative hashs in Ruby (on Rails) dynamicly"
} | 15193 |
<p>Also, how would I go about putting my class in another file? Thanks!</p>
<pre><code>#include <iostream>
using std::cout;
using std::endl;
class Array
{
int *arrayPointer;
public:
Array(int size);
~Array();
int get(int index);
void set(int index, int value);
protected:
int array[];
int size;... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-05T21:38:17.927",
"Id": "24906",
"Score": "0",
"body": "At least IMO, not very well, no. I wrote a rather [lengthy post](http://coderscentral.blogspot.com/2012/08/c-dynamic-arrays.html) about this recently."
}
] | [
{
"body": "<p>First of all, you have no copy constructor (or assignment operator). This will be a problem in this case:</p>\n\n<pre><code>void foo(Array a) {\n //...\n}\n\nint main() {\n Array a(10);\n foo(a);\n //a is still around, but the pointer has been destroyed.\n}\n</code></pre>\n\n<p>Since there... | {
"AcceptedAnswerId": "15198",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T22:18:47.347",
"Id": "15197",
"Score": "3",
"Tags": [
"c++",
"memory-management"
],
"Title": "C++: Am I managing memory the right way?"
} | 15197 |
<p>How is this function?</p>
<pre><code>/// <summary>Extension methods used by RedViewerLibrary.</summary>
internal static class Extensions
{
/// <summary>A string array extension method that gets the human readable enumerated version of the array.</summary>
/// <param name="items"&g... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T11:57:12.113",
"Id": "24663",
"Score": "3",
"body": "Does this \"and\" make it human readable? A lot of code for what could be just `String.Join(\", \", array)`."
}
] | [
{
"body": "<p>It's ok. A bit hard to follow however since you're taking steps that really aren't necessary.</p>\n\n<ul>\n<li><p>It is not necessary to give the <code>StringBuilder</code> a starting capacity. Just let it do its business and you do yours, it will just work.</p>\n\n<p>However if you really wante... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T00:41:31.057",
"Id": "15200",
"Score": "0",
"Tags": [
"c#",
"array",
"formatting"
],
"Title": "Making a list human-readable"
} | 15200 |
<p>I'm writing a library which calls a RESTful API and then performs some work on the data.</p>
<p>I've architected my code like this:</p>
<p>I have a class (let's call it <code>APIRequestor</code>) that initiates a call to the API via an injected <code>HTTPRequestor</code> library (which basically wraps a <code>cURL... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T02:58:55.363",
"Id": "24640",
"Score": "1",
"body": "\"I created a HTTPRequestorMock which extends HTTPRequestor\" --- why don't you use native `$this->getMock` phpunit thing?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cre... | [
{
"body": "<p>Yes, it looks like a reasonable design and approach.</p>\n\n<p>At the nit-pick level <code>getMockedRequestor</code> should be private or protected, to document that it is a helper for the tests. Also, if every test is going to be calling it, some people might move that code into setUp(). But that... | {
"AcceptedAnswerId": "15202",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-29T02:55:58.020",
"Id": "15201",
"Score": "5",
"Tags": [
"php",
"api",
"unit-testing"
],
"Title": "Unit testing code that calls RESTful API"
} | 15201 |
<p>I have tables that use BulkManager to save data to database.
I moved common functionality to <code>BulkTableBase</code>. Because creation of <code>BulkManager</code> depends on params of each Table I create the <code>BulkManager</code> in .ctor of the Table. The <code>Add</code> method of each Table is also differen... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T14:15:05.803",
"Id": "24673",
"Score": "0",
"body": "Why not use a factory to create the correct class instead?"
}
] | [
{
"body": "<p>Calling that function from sub-classes is not that bad, I think the problem is your classes are trying to do too much and are stepping on each others toes, so to speak. I'll touch on this as I go through this. </p>\n\n<p>You are doing too much in the constructors for the Table#. The constructor ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T08:44:47.313",
"Id": "15207",
"Score": "3",
"Tags": [
"c#",
"database",
"classes",
".net-datatable"
],
"Title": "Is my base class constructed correctly?"
} | 15207 |
<p>I have a time-based signal (Raw signal) sampled at 6 MHz and need to analyze it in freq. domain.
I'm learning DSP and this is very first time I work with DSP. Could you please help to check if this code is correct or not. And I have couple of questions needed to be clarify:</p>
<ol>
<li><p>I've heard about linear ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-27T15:44:04.773",
"Id": "31925",
"Score": "0",
"body": "If you want verification that the code is correct more information will be required. In particular encountered problems."
}
] | [
{
"body": "<ol>\n<li><p>The easy way to plot something with a logarithmic scale would be to just take the logarithm of the variable. </p>\n\n<p><code>logspectrum = log(spectrum);</code></p></li>\n<li><p>The source of some files is available when you type edit function name, example:</p>\n\n<p><code>edit unique<... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T13:49:26.527",
"Id": "15208",
"Score": "3",
"Tags": [
"matlab",
"signal-processing"
],
"Title": "Calculate FFT from windowed time-based signal"
} | 15208 |
<p>I've written this code that I've been using for a while now to check for browser geolocation services for Google Maps applications. I have to say that I am not very happy with it as I've had to hack it quite a bit to work in IE9.</p>
<p>Could I please get some critical assessment of the following and possible sugge... | [] | [
{
"body": "<p>A tricky question,</p>\n\n<p><code>navigator.geolocation.getCurrentPosition</code> will always return <code>undefined</code>, regardless of browser or whether or not the the user allowed the location to be retrieved.</p>\n\n<p>That means that <code>//Do nothing as script has started, This if claus... | {
"AcceptedAnswerId": "40846",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T15:28:01.920",
"Id": "15210",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"html5",
"google-maps"
],
"Title": "Geolocation check and error management for Google Maps"
} | 15210 |
<p>I implemented a MVC Framework with Generic DAO and I would like know if is correct. I did not have developed yet the MySQLDAO.</p>
<p>My controller class</p>
<pre><code>class ClienteController {
public function __construct() { }
public function actionSubmit(){
$objCliente = new Cliente();
$objCli... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-17T08:32:09.180",
"Id": "25495",
"Score": "0",
"body": "Welcome to Code Review! I'm not familiar with DAO, but I think that we need more explanation to understand what you want to do. Also, make sure your code works before submitting i... | [
{
"body": "<p>I don't feel that this post really qualifies as an answer as I don't know enough about the main subjects in the OP's post, DAO and the factory pattern. I am unfamiliar with both, but there are a few things unrelated that I noticed and couldn't hurt to be pointed out. I would have just posted this ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T16:43:36.647",
"Id": "15211",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"design-patterns"
],
"Title": "Correct GenericDAO implementation?"
} | 15211 |
<p>I have files with over 100 million lines in each:</p>
<blockquote>
<pre><code>...
01-AUG-2012 02:29:44 important data
01-AUG-2012 02:29:44 important data
01-AUG-2012 02:36:02 important data
some unimportant data
blahblah (also unimportant data)
some unimportant data
01-AUG-2012 02:40:15 important data
some unimport... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T08:44:35.590",
"Id": "24688",
"Score": "0",
"body": "Without proper profiling we can only guess where the bottleneck is. Create a smaller test file (http://www.manpagez.com/man/1/head/) and run your script under [profiler](http://do... | [
{
"body": "<p>Use string operations instead of regular expression matching. RE uses a fully featured engine which is redundant in this situation.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T08:51:19.117",
... | {
"AcceptedAnswerId": "15253",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-30T08:38:50.370",
"Id": "15214",
"Score": "12",
"Tags": [
"python",
"performance",
"datetime",
"regex"
],
"Title": "Script for analyzing millions of lines"
} | 15214 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.