body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I started out with a function having code duplication like this:</p>
<pre><code> private static void GetAndSaveResources(string url)
{
...
if (url.Contains("[" + "access_id" + "]"))
{
RestCall.UriVariables.Add("access_id", 1);
}
if... | [] | [
{
"body": "<p>I don't think this makes your code any more \"DRY\", because you still have one function. It's just a matter of the scope the function exists in. If you <em>only</em> need this function here, then I don't think a lambda is a step in the wrong direction as it could make the rest of your code cleane... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T16:36:59.593",
"Id": "10255",
"Score": "5",
"Tags": [
"c#"
],
"Title": "Does using a lambda make this code more DRY?"
} | 10255 |
<p>I am new at facebook development using their PHP-SDK and Graph API. I am at the stage that I need to find which road should I take for a better/faster and efficient results.</p>
<p>I display the pages a user administrates in both ways. My question is which one should I choose?<br>
Thank you community.</p>
<p><stro... | [] | [
{
"body": "<p>I think you'd be better off using the official API wrapper from Facebook. If they ever change their APIs you could download the latest version of their wrapper and continue on.</p>\n\n<p>The best thing you can do for speed is cache the results. PHP can read files on the server a lot faster than do... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T18:58:54.667",
"Id": "10259",
"Score": "3",
"Tags": [
"php"
],
"Title": "Which one should I choose to work with, Facebook PHP-SDK or Graph Api with Curl?"
} | 10259 |
<p>I am working on an app where I have to calculate the age of a person. Inside of my age class I have a function that is designed to account for leap year. Is there anything I am missing or could improve upon? I would have though this would have been more complicated so I am not confident in my method or my test ca... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T22:32:59.033",
"Id": "16326",
"Score": "2",
"body": "See SO question [How do I calculate someone's age in C#?](http://stackoverflow.com/questions/9/how-do-i-calculate-someones-age-in-c). There are really interesting answers there. T... | [
{
"body": "<p>what about?</p>\n\n<pre><code>var date1 = DateTime.Parse(\"2/29/2000\");\nvar date2 = DateTime.Parse(\"2/28/2009\");\n\nvar years_old = date2.Subtract(date1).TotalDays / 365.25;\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-... | {
"AcceptedAnswerId": "10264",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T22:05:57.070",
"Id": "10263",
"Score": "3",
"Tags": [
".net",
"datetime",
"vb.net"
],
"Title": "Attempt to calculate age in VB.NET"
} | 10263 |
<p>Right now I am working on an install and uninstall script for my vim configuration files. The install script links files and directories and the uninstall script deletes those links. I just want to make sure that this code is somewhat safe, are there better ways of doing the same thing? Here is the code I have right... | [] | [
{
"body": "<p>If you're worried about it being safe, probably verifying that what you're deleting is a symlink and bailing out if not would be a good start:</p>\n\n<pre><code>if [[ ! -h $TARGET_LOCATION/.$file ]]; then\n printf >&2 \"%s is not a symlink!\\n\" \"$TARGET_LOCATION/.$file\"\n return 1\... | {
"AcceptedAnswerId": "10324",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-23T00:33:33.200",
"Id": "10266",
"Score": "3",
"Tags": [
"bash"
],
"Title": "Shell script that creates and deletes symbolic links"
} | 10266 |
<p>I recently had an interview for a programming job and after the interview I was then asked to create a function with the following brief:</p>
<blockquote>
<p>The Task:</p>
<p>Relating to pagination links: given a page number, a total number of pages, and an amount of 'context' pages, generate the appropriate paginat... | [] | [
{
"body": "<p>You can cut out some redundancy by just using one array to store the results, and you can cut down on the number of operations by doing simple checks against what we know will be the last and first members of the outer page groups instead of checking whether those numbers are in the right/left arr... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-03-23T04:11:34.167",
"Id": "10271",
"Score": "6",
"Tags": [
"php",
"pagination"
],
"Title": "Generating pagination links"
} | 10271 |
<p>How to minimize the following code using java's features ... looking for some workaround with the switch-case statement</p>
<p>I've seen several question regarding switch-case design pattern / best practices but because I am new to java, I am having difficulties in implementing them.</p>
<p>Here is the code:</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T23:36:33.070",
"Id": "16343",
"Score": "0",
"body": "And the question is...?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T23:55:13.803",
"Id": "16344",
"Score": "0",
"body": "how to min... | [
{
"body": "<p>Consider creating an object which can handle each case:</p>\n\n<pre><code>interface NodeHandler {\n void handle(Node node, Element current, ...);\n}\n\nclass ElementHandler implements NodeHandler {\n public void handle(Node node, Element current, ...) {\n readElement(node, current);\n... | {
"AcceptedAnswerId": "10278",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T23:28:57.920",
"Id": "10273",
"Score": "7",
"Tags": [
"java",
"parsing",
"xml",
"dom"
],
"Title": "Handling various types of nodes when traversing a DOM tree"
} | 10273 |
<p>This is a specific case in merge sort. I'm trying to do a merge sort on an array that's created using the Java <code>Integer</code> class. My implementation is slow and therefore needs some modifications for better performance. I believe the process where I copy the original items to two new arrays over and over ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T23:31:13.647",
"Id": "16361",
"Score": "0",
"body": "The algorithm looks correct to me. Merge sort requires you to split the array which doesn't really happen without copying to two new arrays at some point so I don't think that's y... | [
{
"body": "<p>If performance is the only criteria that you want, then you can use threads to paralyze the merging part of it. To copy an array there is a simple way to use <code>Arrays.copyOf()</code>.</p>\n\n<p>Here is the code that includes thread and the use of array as reference:</p>\n\n<pre><code>Integer[]... | {
"AcceptedAnswerId": "10280",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T23:21:37.727",
"Id": "10276",
"Score": "4",
"Tags": [
"java",
"performance",
"sorting",
"mergesort"
],
"Title": "Merge sort on an Integer class"
} | 10276 |
<p>I would greatly appreciate the input of any gurus out there. I have recently begun learning JavaScript and then jQuery and jQuery-UI and have thought I would take a stab at writing my own jQuery-UI plugin, the result of which you can see here:</p>
<p><a href="http://jsfiddle.net/ben1729/djA6G/" rel="nofollow">http:... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-01T13:27:54.930",
"Id": "18244",
"Score": "0",
"body": "Come on chaps. Anyone? Even if that you would not change anything (which I doubt - it cannot be perfect!) then I would like to know."
}
] | [
{
"body": "<p>There is a javascript concept about one <code>var</code> per scope. Personally I'm not a big fan of it but you might want to read this: <a href=\"http://wonko.com/post/try-to-use-one-var-statement-per-scope-in-javascript\" rel=\"nofollow\">http://wonko.com/post/try-to-use-one-var-statement-per-sc... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-23T15:26:14.683",
"Id": "10282",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"jquery-ui"
],
"Title": "Pie Chart jQuery-UI plugin"
} | 10282 |
<p>I would like to know if there is a better/shorter/cleaner/resource saving method for this snippet of php code with codeigniter? Thanks.</p>
<pre><code>$code = $this->uri->segment(3);
if (!$code) {
// validation
$this->form_validation->set_rules('code', 'PassCode', 'required|trim|max_length[100]... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T18:30:11.107",
"Id": "16374",
"Score": "1",
"body": "Check out the codeigniter style guide: http://codeigniter.com/user_guide/general/styleguide.html For example, instead of `if (!$code)`, write `if ( ! $code)`. In my opinion, codei... | [
{
"body": "<pre><code>if ($this->form_validation->run() == true)\n</code></pre>\n\n<p>is redundant, just use...</p>\n\n<pre><code>if ($this->form_validation->run())\n</code></pre>\n\n<hr>\n\n<p>Also, you can move the whole <code>if (empty($user_id))</code> block outside to the end to avoid duplicati... | {
"AcceptedAnswerId": "10284",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T18:19:51.583",
"Id": "10283",
"Score": "0",
"Tags": [
"php",
"codeigniter"
],
"Title": "How to write a cleaner code for this piece of php snippet?"
} | 10283 |
<p>Got the following piece of code:</p>
<pre><code> If boolFlag Then
With offer.Person1
entity.Birthdate = .BirthDate
entity.FirstName = .FirstGivenName
entity.LastName = .FamilyName
entity.Street = .StreetName
ent... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-23T20:56:52.953",
"Id": "16394",
"Score": "0",
"body": "Can only think of using reflection to map properties but that seems overkill in this case, unless code snippets like this is scattered throughout your code then it may be worth lo... | [
{
"body": "<p>Options:</p>\n\n<ol>\n<li>Change the original code base (best option, what should happen)</li>\n<li>Inherit your own objects from the originals and attach an interface (given your scenario, this is the option to go with)</li>\n<li>Use static helper methods ( you can abstract and decorate the routi... | {
"AcceptedAnswerId": "10291",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-23T16:36:01.383",
"Id": "10289",
"Score": "4",
"Tags": [
"vb.net"
],
"Title": "Rewrite 2 repeating With-blocks"
} | 10289 |
<p>I've written this <a href="https://github.com/Ralt/ralt.github.com/blob/master/school/countdown.js" rel="nofollow">little countdown script</a> to count until the end of our school days.</p>
<p>Now, that was written quickly, badly remembering modulo from a few years ago, and I don't think that's very optimized.</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-23T17:19:57.727",
"Id": "16387",
"Score": "0",
"body": "Some cool stuff going on here, never thoughts of using arguments.callee like that to avoid a named function. though mdn does seem to recommend against it: https://developer.mozill... | [
{
"body": "<p>First question - your countdown is \"symmetric\", it does not care if current date is past the end date. Is it on purpose?</p>\n\n<p>Define constants to avoid \"magic numbers\": <code>var ONE_DAY = 1000 * 60 * 60 * 24</code> etc</p>\n\n<p>May be it is better to calculate <code>diff = Math.abs(curD... | {
"AcceptedAnswerId": "10298",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-23T16:42:58.240",
"Id": "10290",
"Score": "2",
"Tags": [
"javascript",
"datetime"
],
"Title": "Countdown script in JavaScript"
} | 10290 |
<p>I've built a JavaScript function returning the index of the nth occurrence of a substring in a string.</p>
<pre><code>$(document).ready(function() {
var containingString = '.this.that.';
subString = '.';
var index = GetIndexOfSubstring(containingString, subString, 2);
});
functio... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-23T18:29:54.043",
"Id": "16392",
"Score": "1",
"body": "Using a custom build RegExp should be faster and a lot less code."
}
] | [
{
"body": "<p>There's no need to split the original string or slice away at the string, you can just use the built in <a href=\"https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/indexOf\"><code>indexOf</code></a>, keeping track of how many times you've looked for the substring. As a pe... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-23T18:22:26.650",
"Id": "10295",
"Score": "6",
"Tags": [
"javascript",
"strings"
],
"Title": "Returning index of nth occurrence of a substring"
} | 10295 |
<p>In order to create fast map/reduce processor for hadoop, I'm evaluating many languages. I'm learning python so I would like my python processor to go as fast as my perl processor.</p>
<p>So, for this question, the point is to increase the performance of simpleprocessor.py. To measure improvement, there is a benchma... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-24T01:34:14.510",
"Id": "16398",
"Score": "1",
"body": "Can I ask you strip this down? Having a complete ready-to-go benchmark is great. However, it makes it hard to see what you are actually asking for a review on. So I'd request that... | [
{
"body": "<p>Instead of your try-except in simpleprocessor.py, check out setdefault and defaultdict:</p>\n\n<p>(untested code)</p>\n\n<pre><code>DATA = {}\nDATA.setdefault(k1, defaultdict(int))[k2] += 1\n</code></pre>\n\n<p>I have no idea whether this will be faster or not (although I would guess it would). Si... | {
"AcceptedAnswerId": "10322",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-23T22:04:37.087",
"Id": "10297",
"Score": "3",
"Tags": [
"python",
"performance",
"perl"
],
"Title": "Improving python3 processing speed (against a reference perl script)"
} | 10297 |
<p>Well, the questions is a little bit broader, so I'll assume that the basics is already defined:</p>
<p><strong>Controller</strong></p>
<ol>
<li>FrontController</li>
<li>Controllers (plugin hooks, request/response object, view handler)</li>
</ol>
<p><strong>View</strong></p>
<ol>
<li>View (template, scripts, part... | [] | [
{
"body": "<blockquote>\n<p>Should controllers implement business logic?</p>\n</blockquote>\n<p>That depends on your design and style of doing things "your" MVC-way. As you're designing a framework you should probably allow both to keep the usage of the framework flexible.</p>\n<p>Taking a closer look... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-24T11:59:53.247",
"Id": "10303",
"Score": "0",
"Tags": [
"c++",
"mvc"
],
"Title": "Best way to implement a web MVC application (language agnostic)"
} | 10303 |
<p>Do you see any unneccessary code, or code that can be deleted in here? Its not finished...</p>
<pre><code> import random
import os
# Shortcut to clear the screen
c = 'clear'
# Info about the program
info = 'This game was developed in xCode, by Solomon Wise. He used Python 3.0.1 to build this awe... | [] | [
{
"body": "<p>Some suggestions:</p>\n\n<ul>\n<li>I really don't like how you spread your classes all over the place. You should place them all near the top. This will force you to write constructors for at least some of them.</li>\n<li>As it stands, the attributes for your classes are class attributes. Meaning ... | {
"AcceptedAnswerId": "10308",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-24T13:06:07.550",
"Id": "10305",
"Score": "2",
"Tags": [
"python"
],
"Title": "Unneccessary Things to Delets"
} | 10305 |
<p>I cannot understand how I can make two classes work together by passing variables between them.</p>
<p>During the last 5 days, I learned the basics of inheritance, singleton methods and eval methods. I even read about template methods, but since I have no programming background, I'm in no position to learn from oth... | [] | [
{
"body": "<p>Don't use <code>instance_variable_get</code> unless you really need it. And here you don't need it.</p>\n\n<p>When you need the content of an attribute outside the class, then define a getter:</p>\n\n<pre><code>class Game\n attr_accessor :armor_list, :weapon_list, :equipment\n #additional getter... | {
"AcceptedAnswerId": "10317",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-25T00:25:14.317",
"Id": "10312",
"Score": "4",
"Tags": [
"object-oriented",
"ruby",
"role-playing-game"
],
"Title": "Communication between two classes in ruby"
} | 10312 |
<p>This behaves to an outside observer mostly like <code>@property (copy)</code>, except it has the very nice property of automatically performing any side effects that may exist in <code>remove<Key>AtIndexes:</code> and <code>insert<Key>:atIndexes:</code>. If I'm going to have such side effects, this seems... | [] | [
{
"body": "<p>[NSIndexSet indexSetWithIndexesInRange:] leaks itself. it creates NSIndexPath object, and leaks by 16 bytes per call.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-02T16:48:33.607",
"Id": "18297",
"Score": "0",
... | {
"AcceptedAnswerId": "11185",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-25T16:56:19.093",
"Id": "10321",
"Score": "2",
"Tags": [
"objective-c",
"cocoa",
"properties"
],
"Title": "Is there anything wrong with this unusual NSMutableArray setter?"
} | 10321 |
<p>As a little helper I recently had to write a code that solves the 1-D Euler equations. As it serves my purpose well I though others could make use of it as well. The homepage of the code can be found <a href="http://sci.amconception.de/index.php?nav=gees" rel="nofollow">here</a>, including a download containing the ... | [] | [
{
"body": "<p>A few points I'd do different:</p>\n\n<ul>\n<li>use the name of the procedures/modules also in their end statement</li>\n<li>not writing enddo and endif in a single word, but seperately. There are newer language constructs, where writing them together is not allowed, and separating them all is mor... | {
"AcceptedAnswerId": "66397",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-25T19:31:27.677",
"Id": "10326",
"Score": "5",
"Tags": [
"numerical-methods",
"fortran"
],
"Title": "Gees - GPL Euler equation solver"
} | 10326 |
<p>There is <a href="https://gist.github.com/2188681" rel="nofollow">some little program</a> (using a Last.FM API wrapper) which gets the play count of 2 specific users every 5 minutes and appends the difference between these 2 numbers to log file.</p>
<p>Can you review that part of the code?
I think that using the <c... | [] | [
{
"body": "<p>I don't see why you say <code><-</code> \"decreases readability\", but you could line them up if you think that helps (this style is typical of Haskell programmers)</p>\n\n<pre><code>main = forever $ do\n diff <- user1 `subtractCounts` user2\n timestamp <- formatTime defaultTimeLoc... | {
"AcceptedAnswerId": "10334",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-25T19:54:17.203",
"Id": "10327",
"Score": "7",
"Tags": [
"haskell",
"logging",
"client"
],
"Title": "Periodically comparing the play count of two Last.FM users"
} | 10327 |
<p>I am learning Scala and FP (Functional Programming), coming from Java, OO and a strong imperative pardigm. I am now trying to implement a small puzzle solving project so I can get some deeper hands on experience with both Scala and FP.</p>
<p>So, I have the following Scala class:</p>
<pre><code>class Bitmap2d(rows... | [] | [
{
"body": "<ol>\n<li><p>In Scala, never use <code>null</code> unless some API requires it of you; use <code>Option</code> instead. If you have to interface with an API that returns <code>null</code>, convert the result into an <code>Option</code>. As long as you do that, you can ignore <code>null</code> checks,... | {
"AcceptedAnswerId": "10331",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-25T20:01:09.853",
"Id": "10328",
"Score": "2",
"Tags": [
"functional-programming",
"scala"
],
"Title": "Ideal FP/Scala way to vaildate rectangular list"
} | 10328 |
<p>I have some kind of high thoughput message handler receiving ordered messages. Now the task is - adding monitoring stuff in it in order to recognize wrong input messages, more exactly: it must notify about missed messages and just ignore the stale ones (with smaller order).</p>
<p>Due to high thoughput - it mustn't... | [] | [
{
"body": "<p>I think that there is a certain amount of fuzziness to the question but I'll make a couple of suggestions and perhaps they will help.</p>\n\n<p>First of all, I would recommend giving serious consideration to using Akka actors (http://akka.io/). Actors are a very straightforward way to handle multi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-25T21:41:21.283",
"Id": "10329",
"Score": "3",
"Tags": [
"java",
"optimization"
],
"Title": "Non blocking high performance message processor"
} | 10329 |
<p>I have two columns representing a date and a time. </p>
<pre><code>{dateproc: '2012-03-23', horproc: '2000-01-01 16:15:23 UTC'}
</code></pre>
<p>Both are read as a <code>TimeWithZone</code> by Rails. I need to combine them.</p>
<p>This is what I've done. It works, but it doesn't <em>feel</em> elegant, and it just... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-16T12:07:29.363",
"Id": "62068",
"Score": "0",
"body": "I can't really think of a better way (but I think you can skip the last `.seconds` call). What you have is pretty straightforward, even if it feels a little \"blunt\""
}
] | [
{
"body": "<p>Nope. That's about as clean as it'll get, though like <a href=\"https://codereview.stackexchange.com/questions/10330/date-and-time-columns-conversion-to-timewithzone#comment62068_10330\">Flambino said</a>, you can skip the last <code>.seconds</code> call. It's a bit clunky, but that's just how it ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-25T21:42:51.017",
"Id": "10330",
"Score": "3",
"Tags": [
"ruby",
"datetime",
"ruby-on-rails",
"converting"
],
"Title": "Date and time columns conversion to Time(WithZone)"
} | 10330 |
<p>Ever since I was a kid I wanted to understand how brute force programs work. I have not been able to make sense of any of the examples throughout the internet, so it became a personal challenge to make my own. Now that I have a couple Java classes under my belt, I realized I could tackle this problem with a linked l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-29T21:40:19.660",
"Id": "30643",
"Score": "0",
"body": "I don’t really understand what this is supposed to mean. “brute force” simply means that a solution is found by trying all potential solutions out until one is found that fits. It... | [
{
"body": "<p>Your data structure is alread good. I would drop the <em>circular</em> from the list, since you don't really need it, do you?</p>\n\n<p>If you care about speed more than flexibility, you can switch to using primitive data types and avoid following references, since that requires reading from RAM. ... | {
"AcceptedAnswerId": "10356",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T09:43:37.653",
"Id": "10338",
"Score": "5",
"Tags": [
"java",
"performance",
"circular-list"
],
"Title": "Producing every string of a given length using some range of character... | 10338 |
<p>I'm trying to learn how to structure my jQuery code better. I'm only about a week into jQuery so if something looks way off please tell me. I'm attempting to use object literals and it appears to work ok, but I am wondering if there is possibly a better way to structure my code.</p>
<pre><code>var application = {
... | [] | [
{
"body": "<p>This won't scale if you entire application is one large object.</p>\n\n<p>If you seperated it into multiple objects</p>\n\n<pre><code>var application = []\n\napplication.push({\n wrapper: $(\"#wrapper\"),\n init: function () {\n this.wrapper.on(bla, this.foo)\n },\n foo: function () {\n\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T13:45:21.937",
"Id": "10340",
"Score": "4",
"Tags": [
"javascript",
"beginner",
"jquery"
],
"Title": "Context menu with click handlers"
} | 10340 |
<p>I have written a web crawler. I hope anyone can help me make this code be more better.</p>
<p>This is the task to implement a web crawler in Python.</p>
<blockquote>
<pre><code># Task:
# Write a crawler code by python
# for example:
# myspider.py -u www.google.com -d 3 -t 10 -l logfile -v log_level
# -d --- th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T13:05:35.287",
"Id": "16495",
"Score": "1",
"body": "You need a code review site. Is this homework?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T13:14:33.310",
"Id": "16496",
"Score": "1",... | [
{
"body": "<p>It is easy to write an abusive crawler you need to keep a couple of things in mind.</p>\n\n<ul>\n<li>You should always respect the robots.txt file</li>\n<li>You should respect the meta \"ROBOTS\" tag.</li>\n<li><p>You should not hit a site too quickly.</p>\n\n<ul>\n<li>A good rule of thumb is that... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T13:04:52.687",
"Id": "10344",
"Score": "3",
"Tags": [
"python"
],
"Title": "Web crawler in Python"
} | 10344 |
<p>While I'm aware of various <a href="https://stackoverflow.com/questions/3099716/javascript-check-if-a-variable-is-the-window">different means</a> of checking if a variable is a <code>Window</code> object in JavaScript, I'm interested in writing a function that is more accurate and resilient.</p>
<p>For example, jQu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T18:29:19.687",
"Id": "16503",
"Score": "0",
"body": "Also note, I'd prefer accuracy over performance. `function (arg) { return !!arg && arg === arg.self }` is very performant but not as accurate."
},
{
"ContentLicense": "CC ... | [
{
"body": "<pre><code>(function (global) {\n function isWindow(o) { return o === global }\n})(window)\n</code></pre>\n\n<p>Just grab the window token at global scope, it can be overwritten</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T18:58:05... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T18:24:27.713",
"Id": "10346",
"Score": "6",
"Tags": [
"javascript"
],
"Title": "Most accurate isWindow function"
} | 10346 |
<p>OK, so I recently posted <a href="https://codereview.stackexchange.com/questions/10230/python-implementation-of-the-longest-increasing-subsequence-problem">this solution in Python</a> to the <a href="http://en.wikipedia.org/wiki/Longest_increasing_subsequence" rel="nofollow noreferrer">longest non-decreasing subsequ... | [] | [
{
"body": "<p>A few general remarks</p>\n\n<p>I find that stepped whiles are as evil as nested if statements for readability of the code. Here, you have three levels of nesting.\nRelying on the surrounding environment for variables can some times obscure possibility to generalize (You make use of x and m for in... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T20:54:31.333",
"Id": "10349",
"Score": "4",
"Tags": [
"optimization",
"haskell"
],
"Title": "Longest non-decreasing subsequence, in Haskell"
} | 10349 |
<p>I am studying about the converting int to string and string to int without using <code>toString</code> and <code>parseInt</code> method. I already made methods. However, I don't believe that my way of doing was the best. I would like to improve these function.</p>
<p>For example, the first converts from <code>Strin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T21:35:35.430",
"Id": "16516",
"Score": "0",
"body": "Your making these on purpose right.. Instead of just using Integer.parseInt() and Integer.toString().."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03... | [
{
"body": "<p>To improve your <code>intToString()</code> method you should consider using a <a href=\"http://docs.oracle.com/javase/6/docs/api/java/lang/StringBuilder.html\" rel=\"nofollow\"><code>StringBuilder</code></a>, and specifically the method <a href=\"http://docs.oracle.com/javase/6/docs/api/java/lang/... | {
"AcceptedAnswerId": "10352",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T21:29:44.320",
"Id": "10351",
"Score": "9",
"Tags": [
"java",
"interview-questions",
"reinventing-the-wheel"
],
"Title": "Converting int value to String without using toString ... | 10351 |
<p>I have a website on which for every request, the scraping of other websites is done to get accurate data. While it works well, it has a slight impact on the performance.</p>
<pre><code>public ActionResult Index(int id)
{
Product product = pe.Products.Where(p => p.Id == id).First();
foreach (var pricing i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T15:32:30.563",
"Id": "16542",
"Score": "1",
"body": "Does the data change frequently? Could you live with somewhat stale data? Can you afford to do this asynchronously?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDa... | [
{
"body": "<p>It's hard to tell exactly how it's being utilized since your code sample is an example. However, a few notes. </p>\n\n<p>Due to the design of your use case above most of the time any improvements are going to pale in comparison to pulling a web page live (especially multiple). If you want real ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T04:56:55.337",
"Id": "10358",
"Score": "3",
"Tags": [
"c#",
"performance",
"web-scraping"
],
"Title": "Gaining better performance when screen scraping is required"
} | 10358 |
<p>I am adding new functionality into a legacy application. For my new classes I have introduced Unit Testing. I still need to work with the existing code.</p>
<p>One of the problems I face is that a lot of static methods have been used.</p>
<p>Below is an example of a class I need to use:</p>
<pre><code>public clas... | [] | [
{
"body": "<p>What about creating new classes that use the existing static methods rather than extending existing code. That way you will not need to worry about breaking existing code or adding duplicate method calls onto existing? </p>\n\n<p>One thing I would say for certain is to stay away from a property ... | {
"AcceptedAnswerId": "10371",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T07:11:24.907",
"Id": "10359",
"Score": "13",
"Tags": [
"c#",
"unit-testing",
"static"
],
"Title": "Unit testing legacy code with static classes"
} | 10359 |
<p>What is the best way to refactor the following script?</p>
<pre><code><script type="text/javascript">
$(document).ready(function() {
$(".rolesList").hide();
});
$("#legendFunction").click(function() {
$("#divChkUserRoles").toggle('slow');
var text = $... | [] | [
{
"body": "<p>Don't use ids at all. (You almost never should be using them. Ids get to be really problematic once you have composite views and/or multiple people on a project)</p>\n\n<p>Place a few appropriate classes in your html. And use the jquery composite and relative references to do it all at once.</p>\n... | {
"AcceptedAnswerId": "10363",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T10:00:09.593",
"Id": "10361",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"form",
"animation"
],
"Title": "Expandable text boxes for legends of fieldsets"
} | 10361 |
<p>I'm working on chat client for mobile devices, and I need to get new messages from server as fast, as possible and, if it possible, keep battery alive.</p>
<p>I've created such class, that listens for server on it's own thread. Here is <code>run</code> method of <code>Thread</code>:</p>
<pre><code>@Override
public... | [] | [
{
"body": "<p>I'm not sure about your first question - I've never programmed on a mobile device where power was an issue.</p>\n\n<p>In answer to your second question, one of the options for sockets that is contained in the specification for TCP/IP is SO_KEEPALIVE. When this is set to true, the internal socket m... | {
"AcceptedAnswerId": "10367",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T12:01:09.797",
"Id": "10365",
"Score": "6",
"Tags": [
"java"
],
"Title": "Socket listener for chat client"
} | 10365 |
<p>I'm doing a side project at work and I consider it as a learning opportunity more than work itself, but it does hold a purpose if I can complete it. Anyway, I'll post the code, what it actually does and hopefully people can critique/improve what I've done.</p>
<pre><code>os.system("bjobs -u all| awk ' NF>1' >... | [] | [
{
"body": "<p><strong>I'm having a major doubt:</strong> should I give you the same advice I gave you the last time <a href=\"https://stackoverflow.com/a/9806512/1132524\">here</a>? Would you follow them this time? Or there was something not clear?</p>\n\n<p>Well, I'll try my best.</p>\n\n<h2>Don't use <a href=... | {
"AcceptedAnswerId": "10370",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T13:21:52.977",
"Id": "10366",
"Score": "5",
"Tags": [
"python",
"console"
],
"Title": "Job queue system"
} | 10366 |
<p>I've been using CSS and HTML for a while and I'm trying to start to use better methods of coding. I've tried my best not to hack anything. Could anyone let me know how I'm doing at the moment in terms of using things which are better practice?</p>
<p>Please note - I've taken some image names and comments out to pro... | [] | [
{
"body": "<p>This code seem nice to me although they are certain things that I would do differently. </p>\n\n<p>First I don't understand why you've put you jquery script at the end. I always put my script at the beginning in the head so that my script are loaded before my content. If there is javascript that n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T14:07:24.430",
"Id": "10368",
"Score": "7",
"Tags": [
"javascript",
"jquery",
"html",
"css",
"e-commerce"
],
"Title": "Front page for an e-commerce website, with a simple ... | 10368 |
<p>I have this <code>Queue</code> declared in my class:</p>
<pre><code>static private Queue<SignerDocument> QUEUE = new Queue<SignerDocument>();
</code></pre>
<p>I fill this <code>Queue</code> with some items to process, and I want to process it using multithreading.</p>
<p>Did I need to use lock in thi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T17:33:40.077",
"Id": "16600",
"Score": "1",
"body": "Is there a reason you are using a queue object to buffer work items for ThreadPool.QueueUserWorkItem (which is itself a queue)? The most intuitive behavior would be to perform th... | [
{
"body": "<p>Yes, and don't lock on <code>typeof</code> - <a href=\"https://stackoverflow.com/a/1603044/3312\">highly unrecommended</a>. Also you'll need to lock whatever's adding to the <code>QUEUE</code> so that the multithreaded <code>Dequeue()</code> does not race against it.</p>\n\n<pre><code>static prote... | {
"AcceptedAnswerId": "10374",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T17:19:38.477",
"Id": "10373",
"Score": "4",
"Tags": [
"c#",
"multithreading",
".net",
"thread-safety",
"queue"
],
"Title": "Multithreaded item-processing queue"
} | 10373 |
<p>I've created a sliding panel menu that works (<a href="http://jsfiddle.net/stephmoreland/3BT7t/" rel="nofollow noreferrer">JSFiddle</a>), but I can't wrap my head around shortening the jQuery for it. Right now, when you click one of the links on the left, I wanted it to show that link's <code>div</code> and hide the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T20:43:23.910",
"Id": "16552",
"Score": "0",
"body": "A few comments - avoid using ids, prefer using classes that describe the elements to prevent weird conflicts. Also, don't include the element type in the id/classname, there's no ... | [
{
"body": "<p>If you make the <code>href</code> the <code>id</code> of the element you wish to <code>show</code> you can simplify it greatly.</p>\n\n<p>This works since you use the structure of your document to your advantage you know you want to <code>hide</code> all the <code><div/></code> child element... | {
"AcceptedAnswerId": "10377",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T19:05:07.240",
"Id": "10376",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Sliding panel menu"
} | 10376 |
<p>I'm just wondering how my model looks. And by this I mean did I perform the correct tests with the results on each function and use the return at the right points. If you can check all functions. I'm curious to know about if I did the sendMessage function correctly.</p>
<pre><code><?php if ( ! defined('BASEPATH'... | [] | [
{
"body": "<p>Well taking a brief look and not knowing everything your code is doing in general outside of this model, I would assume its fine. However down at the bottom the last if-else statement you have. </p>\n\n<pre><code>return $query->row();;\n</code></pre>\n\n<p>which is an extra semi-colon. Remove t... | {
"AcceptedAnswerId": "10384",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T19:39:17.010",
"Id": "10378",
"Score": "3",
"Tags": [
"php",
"codeigniter"
],
"Title": "Personal Messsage Model"
} | 10378 |
<p>I'm trying to get the peaks/zero crossings from a basic 1D signal and am not sure if my naive/basic approach is correct:</p>
<pre><code>float[] signal = {168.02423,167.11852,167.50813,166.8597,166.05814,165.11226,164.18024,162.52278,159.26706,154.01059,151.02512,145.88942,139.96555,131.64963,128.41841,125.55873,123... | [] | [
{
"body": "<p>Well, fine for good signals. Good signals means low noise level, absense of features like very slow volume change rates, etc.\nOtherwise, you need things like FIR filter(s) to average and diffifentiate signal and use an interpolation to increase precision of the detection.</p>\n",
"comments": ... | {
"AcceptedAnswerId": "10394",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T20:28:58.020",
"Id": "10380",
"Score": "3",
"Tags": [
"algorithm",
"computational-geometry",
"signal-processing",
"processing"
],
"Title": "Zero crossings from a 1D signal"... | 10380 |
<p>This is some of my first real F# code ever. I have done a bit of reading and watched a few videos however. I chose to do a code kata for string calculator to try it out.</p>
<p>The kata I was working on is here <a href="http://osherove.com/tdd-kata-1/" rel="nofollow">by Roy Osherove</a>, though I may have strayed a... | [] | [
{
"body": "<p>Is there a specific reason you want to accept a string? You could pass a list and get by with one overload.</p>\n\n<pre><code>type Calculator() =\n member x.Add(nums: int list) = List.sum nums\n\nlet calc = Calculator()\n\ncalc.Add([0; 0])\ncalc.Add([1; 2; 3; 4])\ncalc.Add(List.init 10 id)\n</cod... | {
"AcceptedAnswerId": "10386",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T20:48:18.500",
"Id": "10382",
"Score": "3",
"Tags": [
"beginner",
"f#",
"calculator"
],
"Title": "String calculator in F#"
} | 10382 |
<p>Any thoughts on my code? It's a simple hashing code that runs from the command line.</p>
<p>There just appears to be a lot of condition <code>if</code> / <code>elif</code> entries in both of the main functions (<code>hashingmethod</code> and <code>hashcalculator</code>). </p>
<pre><code># hashcalculator.py
import... | [] | [
{
"body": "<p>You should really take a look at <a href=\"http://docs.python.org/library/argparse.html\" rel=\"nofollow noreferrer\"><code>argparse</code></a>: <em>the argparse module makes it easy to write user-friendly command-line interfaces</em>. It will even take care of writing the help for you.</p>\n\n<p>... | {
"AcceptedAnswerId": "10387",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T21:18:42.310",
"Id": "10383",
"Score": "3",
"Tags": [
"python",
"beginner",
"python-2.x",
"console"
],
"Title": "Simple hashing code with excessive conditional statements"
... | 10383 |
<p>I am looking for a <strong><em>Perl</em></strong> (5.8.8) script for CSV parsing that would follow CVS standards.</p>
<p>(See <a href="http://en.wikipedia.org/wiki/Comma-separated_values" rel="nofollow noreferrer">Wikipedia</a> or <a href="https://www.rfc-editor.org/rfc/rfc4180" rel="nofollow noreferrer">RFC-4180</a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T06:06:43.527",
"Id": "16558",
"Score": "2",
"body": "1) Wikipedia is **NOT** an authoritative source. Don't use it when quoting standards."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T06:08:23.307"... | [
{
"body": "<h3>General Overview</h3>\n\n<ul>\n<li>It is unreadable\n<ul>\n<li>This is OK as an exercise for your reg ex muscles.</li>\n<li>BUT this is not maintainable code. As such it is would never get past a code review at any company or get placed in production.</li>\n<li>You may get away with it for a one ... | {
"AcceptedAnswerId": "10404",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-27T22:45:06.620",
"Id": "10385",
"Score": "-3",
"Tags": [
"parsing",
"perl",
"csv"
],
"Title": "CSV parsing in Perl"
} | 10385 |
<p>I'm new to Django and learning my ways around it. I'm writing a fake basic CRUD app to get me started. In the following code I pretty much copy and paste the same code four times with minor adjustments between each. I only pasted it here twice for the Bands and Album models.</p>
<p>Am I doing this right? </p>
<pre... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-15T06:38:17.243",
"Id": "18880",
"Score": "0",
"body": "Do you realize that anybody can delete all bands of your website ?"
}
] | [
{
"body": "<p>I'd say the best way to be \"less redundant\" would be to use the already-existing <a href=\"https://docs.djangoproject.com/en/1.4/ref/class-based-views/#generic-views\" rel=\"nofollow\">generic views</a> - e.g. <a href=\"https://docs.djangoproject.com/en/1.4/ref/class-based-views/#django.views.ge... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T02:44:57.733",
"Id": "10389",
"Score": "2",
"Tags": [
"python",
"django"
],
"Title": "Am I being too redundant in this Django view (or can I reduce the repetition in my code)?"
} | 10389 |
<p>Is it possible to make this algorithm faster ? Algorithm represents primality test for Wagstaff numbers . </p>
<pre><code>import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.math.RoundingMode;
public class WPT
{
public static void main(String[] args)
{
int n;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T17:17:57.827",
"Id": "16599",
"Score": "2",
"body": "Please use consistent indentation"
}
] | [
{
"body": "<p>Avoid dealing with BigDecimals <em>at all costs</em> - they are slow. I changed the formula to work with \"twice the number\", so my <code>s</code> is actually 2*s. Further keep the numbers in the loop small by \"modding\" the intermediate results, too. Finally I tried to simplify the syntax and t... | {
"AcceptedAnswerId": "10393",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T07:38:57.390",
"Id": "10390",
"Score": "4",
"Tags": [
"java",
"optimization"
],
"Title": "How can I make this primality test algorithm faster?"
} | 10390 |
<p>Got this idea from the php.net website on extending exceptions. The main thing I wanted with this was to have the exception name auto imprinted on the exception message, so I wouldn't have to write it in each message. So far its working, just wondering if this is efficient or not?</p>
<p>Thanks</p>
<pre><code>clas... | [] | [
{
"body": "<p>I'd suggest to change arguments order in ctor for better compatibility with parent calss.\n<code>public function __construct($message, $code = 0, Exception $previous = null, $solved = false, $howSolved = null)</code>\nAnd getters for <code>$soved</code> and <code>$howSolved</code> seems to be miss... | {
"AcceptedAnswerId": "10395",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T08:30:43.540",
"Id": "10392",
"Score": "2",
"Tags": [
"php",
"exception-handling"
],
"Title": "extending Exception to allow for auto appending class name on exception message"
} | 10392 |
<p>Just needed a quick way to convert an elementtree element to a dict. I don't care if attributes/elements clash in name, nor namespaces. The XML files are small enough. If an element has multiple children which have the same name, create a list out of them:</p>
<pre><code>def elementtree_to_dict(element):
d = di... | [] | [
{
"body": "<pre><code>def elementtree_to_dict(element):\n d = dict()\n</code></pre>\n\n<p>I'd avoid the name <code>d</code> its not very helpful</p>\n\n<pre><code> if hasattr(element, 'text') and element.text is not None:\n d['text'] = element.text\n</code></pre>\n\n<p><code>getattr</code> has a t... | {
"AcceptedAnswerId": "10414",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T13:07:28.167",
"Id": "10400",
"Score": "6",
"Tags": [
"python",
"xml"
],
"Title": "Convert elementtree to dict"
} | 10400 |
<p>I just programmed a basic neural network in F# to learn the logical OR function. As I am very new to F# and especially functional programming, I did it the imperative way. And even tho it works, I find it highly unattractive. I would like to improve it to make it as functional-like as possible. I though about overlo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T18:35:29.713",
"Id": "16601",
"Score": "3",
"body": "Tsk tsk... couldn't resist using `mutable` huh? :)"
}
] | [
{
"body": "<p>Printing a list of items to the console is inherently imperative. But keeping track of lots of state between iterations using higher-order functions is often inelegant. Regardless, there are some things you can do to clean this up and (if you're compelled) get rid of mutables. Most notably, you ca... | {
"AcceptedAnswerId": "10415",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T15:54:49.687",
"Id": "10406",
"Score": "3",
"Tags": [
"functional-programming",
"f#",
"neural-network"
],
"Title": "Basic neural network"
} | 10406 |
<p>How would you improve and shorten this small piece of code? It basically update a <code>textarea</code> label with the number of characters inside the field itself. It saves the original label and restores it when characters count is <code>0</code>.</p>
<p>jsFiddle <a href="http://jsfiddle.net/274gy/1/" rel="nofoll... | [] | [
{
"body": "<p>Just a few things I notice, prolly not warranting a \"mark as answer\" but may help:</p>\n\n<ol>\n<li>Cache <code>$(this)</code>: <code>var $this = $(this);</code> So that you don't keep inefficiently re-wrapping <code>this</code></li>\n<li><code>$(this).attr('id')</code> - really? You can just us... | {
"AcceptedAnswerId": "10409",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T15:57:23.787",
"Id": "10407",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Updating a textarea label with the number of characters inside the field itself"
} | 10407 |
<p>Is this bad coding? Is it OK to use 'OR' to specify argument alternatives?</p>
<pre><code> // This function will throw an error if it has no arguements and local stroage is not available
var buildLoginUrl = function(username, password, account)
{
var user = username || loc... | [] | [
{
"body": "<h2>DO NOT DO THIS</h2>\n<p>A minor issue is that this will not function properly if someone provides a blank string such as account = "" AND localStorage does not exist.</p>\n<p>A larger one is that you're not encoding any special characters here meaning that spaces, ampersands, question m... | {
"AcceptedAnswerId": "10410",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T16:01:29.813",
"Id": "10408",
"Score": "-2",
"Tags": [
"javascript",
"html5"
],
"Title": "Javascript, providing arguement alternatives"
} | 10408 |
<p>Thanks in advance for any insight. All used classes are at the top, and everything starts at the comment:</p>
<pre><code>// where the magic happens
</code></pre>
<p>In particular, I am looking for feedback on my attempt at using the factory method and dependency injection. However, I would appreciate any other fee... | [] | [
{
"body": "<h2>1. $this->$this->action()</h2>\n\n<p>You could do this with $this->{$this->action}(). The braces are important for the precedence. PHP wants to break up $this->this->action() first into $this->$this (using the second $this as a string to get the property from the first $this) and then call the ac... | {
"AcceptedAnswerId": "10423",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T18:30:15.693",
"Id": "10412",
"Score": "4",
"Tags": [
"php",
"dependency-injection"
],
"Title": "Working with dependency injection and factories"
} | 10412 |
<hr>
<p>Finished
Someone helped me see that i was framenting the output by writing to each file inside
the for loop instead i needed to have one big for loop for each file so that the harddrive
didnt have to move its head everytime</p>
<p><a href="https://stackoverflow.com/questions/9913788/outputing-dictionary-opti... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T19:23:22.397",
"Id": "16603",
"Score": "2",
"body": "Have you profiled your code? What is the bottleneck, writing to the disk or checking the hash tables?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-... | [
{
"body": "<p>One way to speed up the lookups is to use <a href=\"http://msdn.microsoft.com/en-us/library/bb347013.aspx\" rel=\"nofollow\"><code>TryGetValue()</code></a> instead of <code>ContainsKey()</code> and then the indexer. So, for example:</p>\n\n<pre><code>if (hashs1[i].ContainsKey(filenamef))\n{\n s... | {
"AcceptedAnswerId": "10457",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T18:57:41.420",
"Id": "10413",
"Score": "1",
"Tags": [
"c#",
"performance"
],
"Title": "Optimal way to output a dictionary"
} | 10413 |
<p>I wrote a script that I decided to refactor so I could add functionality to it as my coworkers think of it. I only saved four lines in the effort, but the main change is I removed both methods and reduced the number of called variables in favor of string interpolation/manipulation. Is there a preference for this? Is... | [] | [
{
"body": "<p>Your refactor seems to have reduced the readability of your code, which is usually the opposite of your intent when refactoring. The code may be terser, and string interpolation and re-use is a part of how you've achieved this, but it doesn't make the code easy to follow. That will make it harder ... | {
"AcceptedAnswerId": "10420",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T19:55:49.443",
"Id": "10417",
"Score": "3",
"Tags": [
"ruby"
],
"Title": "When to use a new variable vs string interpolation?"
} | 10417 |
<p>I have the following table called info:</p>
<pre><code>info_name | info_value
name | Susan
desc | Human
</code></pre>
<p>I'm trying to print Susan without knowing that the value is Susan.</p>
<p>The following code works, but I want to know if what I wrote is correct.</p>
<p>I'm open to an... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T23:07:48.417",
"Id": "16624",
"Score": "0",
"body": "I think there's a typo in the error handling when the connection fails. `$this->database->error` will not work. Maybe you meant `$this->connection->error`."
}
] | [
{
"body": "<p>Your <code>config</code> and <code>name</code> classes are good starts. Here are a few humble suggestions:</p>\n\n<ol>\n<li><p>I highly suggest steering clear of what is called the entity-attribute-value pattern when structuring your MySQL tables. Here is an <a href=\"http://pratchev.blogspot.com/... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-28T20:06:40.040",
"Id": "10418",
"Score": "4",
"Tags": [
"php",
"mysql",
"mysqli"
],
"Title": "Am I on the right track? PHP/MySQL"
} | 10418 |
<p>I'm re factoring some code and have come across a method which is throwing 7 exceptions, the method length is approx 20 lines. The method caller wraps this method in a try catch, and just catches the generic Exception. Is there a better way to handle this ? I don't think I should handle each possible exception throw... | [] | [
{
"body": "<p>This depends on what you want to do in case of an exception. If your handling is just printing the stack trace your solution is OK. But you might want to react in a different way depending on the problem.</p>\n\n<p>Just an example:</p>\n\n<ul>\n<li>an IO problem could mean that you have to retry (... | {
"AcceptedAnswerId": "10430",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T08:10:45.983",
"Id": "10429",
"Score": "3",
"Tags": [
"java"
],
"Title": "How to deal with method which throws 7 exceptions"
} | 10429 |
<p>While working on a project with a friend of mine, I noticed the following syntax:</p>
<pre><code>public IObservable<X> GetXs()
{
return from x in xs
select x;
}
</code></pre>
<p>He said that while <code>xs</code> is an <code>IObservable<X></code> field, this is the way it is supposed to ... | [] | [
{
"body": "<p>Based on my understanding the first option is going to create a whole new enumerable object (as well as a linq iterator object) as well as the overhead of calling a function for each element. I would definitely go with the second (your) option. If you need where filtering later, then add it late... | {
"AcceptedAnswerId": "10506",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T09:07:09.957",
"Id": "10431",
"Score": "2",
"Tags": [
"c#",
"linq"
],
"Title": "Using `from select`-syntax to pass through elements from a collection unmodified"
} | 10431 |
<p>This code works great and does exactly as it should, but there has to be a better way of doing this and I just can't figure out how!</p>
<p>I'm pretty new to jQuery and am trying to use it more myself instead of using plugins and I can get stuff to work fine. It just isn't the tidiest or neatest code, which I'm try... | [] | [
{
"body": "<p>Instead of mouseenter/mouseleave, you can use <a href=\"http://api.jquery.com/hover/\" rel=\"nofollow\">hover</a>. It combines both events.</p>\n\n<p><code>.css('display','none');</code> can be done with <code>.hide();</code></p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0"... | {
"AcceptedAnswerId": "10447",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T09:31:36.133",
"Id": "10433",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "jQuery vertical dropdown menu"
} | 10433 |
<p>I'm working on caching library which is intended to work with all types of values.</p>
<p>Values are represented as instances of <code>value_type</code>: <code>value_type</code> holds a <code>std::vector<char></code> for the raw data, and a <code>uint32_t</code> <code>flags</code> integer value which is used ... | [] | [
{
"body": "<p>You can use an internal traits type to reduce redundancy and complexity.</p>\n\n<pre><code>template< typename serialized >\nstruct serialize_traits; // no implementation of general case\n\nenum class serialize_style {\n string,\n integral\n};\n\ntypedef std::vector< char > serial... | {
"AcceptedAnswerId": "10440",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T11:12:12.860",
"Id": "10438",
"Score": "2",
"Tags": [
"c++",
"template",
"template-meta-programming"
],
"Title": "How can I improve the design of this serialization mechanism?"... | 10438 |
<p>I am writing a scraper, using Scrapy, in which I need to populate items with default values at first.</p>
<p>Could my method be improved?</p>
<pre><code> def sp_offer_page(self, response):
item = MallCrawlerItem()
for key, value in self.get_default_item_dict().iteritems():
i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T13:49:01.933",
"Id": "97665",
"Score": "0",
"body": "Item has [default values](http://readthedocs.org/docs/scrapy/en/latest/topics/loaders.html?highlight=item%20loader#declaring-input-and-output-processors). Why don't you use them?"... | [
{
"body": "<pre><code> def sp_offer_page(self, response):\n item = MallCrawlerItem()\n</code></pre>\n\n<p>If MallCrawlterItem is your class, it might make more sense to have it set everything to defaults.</p>\n\n<pre><code> for key, value in self.get_default_item_dict().iteritems():\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T11:32:04.417",
"Id": "10439",
"Score": "3",
"Tags": [
"python",
"scrapy"
],
"Title": "Default initialization of items using Scrapy"
} | 10439 |
<p>Example speaks for it self:</p>
<pre><code>function writeSpecialTabContentForTtm(){
document.write('<div style="float:right;width:250px;min-height:200px;display:block;border-width: 1px 1px 1px">');
document.write('<form id="ttmsetpointrun" action="" style="text-align:right">');
... | [] | [
{
"body": "<p>To create dynamic forms and elements in javascript is easy.</p>\n\n<pre><code>var newdiv = document.createElement('div'); // Creates the div\ndocument.body.appendChild(newdiv); // Adds the div to body\n</code></pre>\n\n<p>After that, you can access newdiv and change attributes of it, such... | {
"AcceptedAnswerId": "10461",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T13:45:26.883",
"Id": "10451",
"Score": "4",
"Tags": [
"javascript",
"design-patterns",
"html"
],
"Title": "How to add forms dynamically in javascript?"
} | 10451 |
<p>Not sure if this question will be considered "off topic". If it is, I'll remove it, but:
I hadn't see this yet so I wrote it and would like to know if this is a good approach to it. Would anyone care to offer improvements to it, or point me to an example of where someone else has already written it better?</p>
<pre... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T13:48:33.747",
"Id": "16657",
"Score": "0",
"body": "I think You're right. I've seen questions get moved before, but I don't know how / probably don't have the proper permissions to do it yet. I did just create an account over ther... | [
{
"body": "<p>Your code seems fairly robust, but it is inefficient. Here are a few ways you could speed it up.</p>\n\n<ul>\n<li>Reuse request objects. There is a good bit of overhead creating these, so you definitely want to be reusing these if you are making more than a few requests per page. But be careful - ... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T13:33:43.670",
"Id": "10453",
"Score": "2",
"Tags": [
"javascript",
"ajax"
],
"Title": "Generalized Ajax function"
} | 10453 |
<p>I'm using <a href="http://casperjs.org/" rel="nofollow">CasperJS</a> and CoffeeScript for integration testing of a hobby project. <a href="https://code.google.com/p/selenium/wiki/PageObjects" rel="nofollow">Page Objects</a> seem to be a useful abstraction. I had two major requirements:</p>
<ul>
<li>Support for node... | [] | [
{
"body": "<p>Do we need to attach a <code>casper</code> reference to the <code>PO</code> class?\nBy using the module pattern you inject the dependency anyway.\nHere is the <code>P0</code> class with a tiny refactoring:</p>\n\n<pre><code>module.exports = (casper) ->\n\n class PO \n constructor: (@na... | {
"AcceptedAnswerId": "32287",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T14:16:16.860",
"Id": "10456",
"Score": "2",
"Tags": [
"coffeescript"
],
"Title": "PageObject implementation (CoffeeScript, CasperJS)"
} | 10456 |
<p>I'm trying to dynamically generate some MarkDown formatted documents, with header fields of arbitrary lengths.</p>
<pre><code>I want to have a title of arbitrary length underlined like this
---------------------------------------------------------------
This should work to
-------------------
</code></pre>
<p>The... | [] | [
{
"body": "<p>One way is to use multiplication. Multiplying a String by a Fixnum will produce a new String where the original String appears the Fixnum of times. </p>\n\n<pre><code>\"-\" * @title.length #=> \"---------------\" \n</code></pre>\n\n<p><a href=\"http://ruby-doc.org/core-1.9.3/String.html#method-... | {
"AcceptedAnswerId": "10463",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T14:59:20.090",
"Id": "10459",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails",
"markdown"
],
"Title": "Creating MarkDown documents in ruby"
} | 10459 |
<p>I am wondering about the best way to save on RAM/memory when there are many required arrays (I plan to have many more NPCs and various other arrays with text and items). And I am wondering what I can improve on so far.</p>
<pre><code> #include <iostream>
#include <cstring>
#define NUM_NPC 10 ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T22:12:14.613",
"Id": "16685",
"Score": "1",
"body": "Unfortunately we could spend a whole book on what you need to know. But a good starting point is to understand OO programming (rather than worry about memory). If you want to writ... | [
{
"body": "<ol>\n<li><p>C++ is statically typed programming language. Due to this overhead for allocation of class members is very small.</p></li>\n<li><p>Using of global variables is not a good idea. Such vars like <code>NUM_NPC</code> makes your application non-scalable.</p></li>\n<li><p>Each domain object (l... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T15:33:01.227",
"Id": "10460",
"Score": "6",
"Tags": [
"c++",
"beginner"
],
"Title": "Array data-handling with NPC class"
} | 10460 |
<p>We want to create a <code>TransactionScope</code> factory class that we can use as a central point for instantiating <code>TransactionScope</code>s with varying configurations throughout our app.</p>
<p>One requirement we have is that a method can either:</p>
<ol>
<li>Instantiate a plain <code>TransactionScope</co... | [] | [
{
"body": "<p>Eoin, nice job with the second attempt. However, I would stick to your guns on the first style with a few deviations. Either A) pass in enumerations into the create method or B) create an override method with the specific name.</p>\n\n<p>I would highly recommend direction B. This prevents magic... | {
"AcceptedAnswerId": "10473",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-29T17:04:46.173",
"Id": "10464",
"Score": "8",
"Tags": [
"c#",
".net",
"reflection"
],
"Title": "Attribute driven behaviour in C# methods"
} | 10464 |
<p>This is pretty much my first "bigger" application besides some "Hello World!" stuff, so I would appreciate critiques to improve my style.</p>
<p>It can be started with <code>Mastermind.play(<difficulty-setting>)</code>, with being a number from 1 (easy) to 10 (hard).</p>
<pre><code>public class Mastermind {... | [] | [
{
"body": "<pre><code>public class Mastermind {\n public static void play(int difficulty) {\n int round = 1;\n int[] zahl = getZufallsZahl(difficulty);\n</code></pre>\n\n<p>zahl? What's that?</p>\n\n<pre><code> int[] tries = Try(round,difficulty);\n</code></pre>\n\n<p>Usually we have cla... | {
"AcceptedAnswerId": "10476",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T02:04:53.660",
"Id": "10475",
"Score": "6",
"Tags": [
"java",
"game"
],
"Title": "Simple Mastermind game"
} | 10475 |
<p>This is a general poste about what I can improve in my coding style while wrapping C libraries up into C++.</p>
<pre><code>#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <png.h>
#include <iostream>
#include <vector>
#include <string>
class PNGFileReade... | [] | [
{
"body": "<p>I believe it is better to make separate <code>Image</code> class and convert <code>PNGFileReader</code> into a factory/builder for the <code>Image</code>. It will completely change the code, but you see that it will force you to have clearer code. </p>\n\n<p>At least, it is better to use streams i... | {
"AcceptedAnswerId": "10507",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T04:56:26.790",
"Id": "10477",
"Score": "1",
"Tags": [
"c++"
],
"Title": "PNG Filereader Implementation in C++: Using libpng"
} | 10477 |
<p>After reading a bit about the <a href="http://msdn.microsoft.com/en-us/library/system.runtime.caching.aspx" rel="nofollow">System.Runtime.Caching</a> in the .net 4 framework I've added a simple Cache class to my application. </p>
<p>Can I improve it or add additional useful functionality? Typing it out here I see t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T12:40:00.187",
"Id": "16704",
"Score": "0",
"body": "Is this supposed to be a caching class for just those two objects superusers and template location?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30... | [
{
"body": "<p>What do you need the singleton for? You don't need it at all. Just use static members if there is always one instance of this class.</p>\n\n<p>I think the responsibilities of storing keys and values, and of returning and creating cache values should be separated.</p>\n",
"comments": [],
"m... | {
"AcceptedAnswerId": "10530",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T10:50:20.713",
"Id": "10478",
"Score": "1",
"Tags": [
"c#",
"cache"
],
"Title": "Improvements and advice for my Cache class"
} | 10478 |
<p>I've written some class which allows me to derive from it to make objects lazy-instantiated. Do you see notational improvements or maybe even cases where this method might not work (multiple inheritance etc.)? What else could I try?</p>
<pre><code>class LazyProxy(object):
def __init__(self, cls, *params, **kwar... | [] | [
{
"body": "<p>Would be cool as a class decorator.</p>\n\n<pre><code>@Lazy\nclass MyFoo:\n ...\n</code></pre>\n\n<p>To me it seems like it would fit nicely as a class decorator because it's independent of what the class is representing. It has more to do with the way the class works internally than it does w... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T11:43:59.207",
"Id": "10481",
"Score": "3",
"Tags": [
"python",
"lazy"
],
"Title": "Lazy class instantiation in Python"
} | 10481 |
<p>I am writing this code in the controller. I want to know is this the right way to write it or not. Because I don't want to write If else conditions and then either redirect or render the pages.</p>
<p>Here is my sample code :</p>
<pre><code>def create
@stud = Student.new params[:student]
@stud.save!
re... | [] | [
{
"body": "<p>I know you wanted to avoid if / else, but I think i would probably write it like this:</p>\n\n<pre><code>def create\n @stud = Student.new params[:student]\n\n if @stud.save\n redirect_to @stud\n else\n render :action => :new\n end\nend\n</code></pre>\n\n<p>Which is the same amount of ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T11:52:25.147",
"Id": "10482",
"Score": "3",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Controller code with exception handling"
} | 10482 |
<p>I have class that handles HTTP requests:</p>
<pre><code>public final class RestHttpClient {
/*there is no fields*/
/**
* @param mhttp - HTTP request that need to send
* @return HttpResponse, that contains information about server response
*/
public HttpResponse sendRequest(final HttpReq... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T15:08:11.197",
"Id": "33586",
"Score": "0",
"body": "[Killing the Helper class, part two](http://blogs.msdn.com/b/nickmalik/archive/2005/09/07/462054.aspx)"
}
] | [
{
"body": "<p>If you don't need instance variables (even singularly) then go static methods, it will simplify your code since you won't have to deal with the logistics of singletons. Also, since your example is about http traffic, it will already have a distinct start and stop. So I would either use static me... | {
"AcceptedAnswerId": "10498",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T12:04:55.100",
"Id": "10484",
"Score": "6",
"Tags": [
"java",
"singleton",
"static"
],
"Title": "Static methods or singleton?"
} | 10484 |
<p>I'm doing the git dot files thing and created a script -- my first Unix shell script -- to synchronise the repo dot files with those in the user's home. It checks which dot files exist in the repo folder (except for <code>.git</code>) and then archives any clashes in the home directory before symlinking to the repo.... | [] | [
{
"body": "<ol>\n<li><p>Consider putting the following at the beginning of every script:</p>\n\n<pre><code>set -e\nset -u\n</code></pre>\n\n<p>The first makes your script abort as soon as the first command exits with an error. This ensures that your script doesn’t try to operate after it’s failed. The second yi... | {
"AcceptedAnswerId": "10528",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T12:20:37.310",
"Id": "10485",
"Score": "4",
"Tags": [
"shell",
"git",
"sh"
],
"Title": "Shell script to sync dotfiles repository"
} | 10485 |
<p>The function of this code is to show/hide divs by way of fadeIn/fadeOut, starting with an empty div (home) and fading in one of the other divs (work,cms,contact,) on click, then fading out the last div and fading in the next on click, and then fading out any div and fading in 'panel' (an empty div) when you click on... | [] | [
{
"body": "<p>I have no problem setting this up in html - it makes sense in this case.</p>\n\n<pre><code><div class=\"menu\">\n<ul class=\"menu\">\n<li class=\"home_button\">home</li>\n<li class=\"work_button\"><a href=\"#work\" data-fadeOut=\"#cms,#contact\">work</a>&l... | {
"AcceptedAnswerId": "10494",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T13:29:39.220",
"Id": "10489",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"animation"
],
"Title": "Fade-in / fade-out effects for several buttons"
} | 10489 |
<p>I only want to create this SQL function if the dependent Assembly exists.
I can do it using dynamic SQL, but it seems messy and I lose syntax checking (in
management studio). This function's dependency (for various reasons) may or may
not be available on an individual developers machine, and I don't want to
inte... | [] | [
{
"body": "<p>You could use the <a href=\"http://msdn.microsoft.com/en-us/library/ms188394.aspx\"><code>SET NOEXEC</code></a> statement, which controls whether the subsequent statements are executed (<code>OFF</code>) or not (<code>ON</code>). Use it in conjunction with your <code>EXISTS</code> test like this:<... | {
"AcceptedAnswerId": "13858",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-03-30T13:46:02.083",
"Id": "10490",
"Score": "15",
"Tags": [
"sql",
"sql-server",
"t-sql"
],
"Title": "Conditional Create: must be the only statement in the batch"
} | 10490 |
<p>I could use some feedback on the class I designed for the above purpose, the complete code is here:</p>
<p><a href="https://github.com/tom-dignan/android-switched-service/blob/master/src/com/tomdignan/android/libs/switchedservice/SwitchedService.java" rel="nofollow">https://github.com/tom-dignan/android-switched-se... | [] | [
{
"body": "<p>Some small notes:</p>\n\n<ol>\n<li><p>Comments like this are unnecessary:</p>\n\n<pre><code> * @param context\n * @param service\n * @param ignition\n * @throws NoSuchServiceException\n</code></pre>\n\n<p>It says nothing more than the code already does, it's rather noise. (<em>Clean Code</em> by <... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T15:40:50.253",
"Id": "10496",
"Score": "2",
"Tags": [
"java",
"android"
],
"Title": "Android SwitchedService class design, for cases where you want to start/stop a service from Broadc... | 10496 |
<p>I've been learning about Racket sequences and noticed a hole where nested iteration is concerned. We have the <code>in-parallel</code> construct but no <code>in-nested</code> construct. There's the <code>for*/...</code> family, but that's syntactic, and can't be extended to an arbitrary number of sequences known o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-04T16:19:04.283",
"Id": "18402",
"Score": "0",
"body": "I could have used in-nested yesterday."
}
] | [
{
"body": "<p>Neat!</p>\n\n<p>It took me a while to see why your second form made sense; it seemed like the Wrong thing until I thought about having a general mechanism to allow later sequences to be closed over the values produced by earlier ones in the way that for* allows. It does have a strongly monadic fe... | {
"AcceptedAnswerId": "10503",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T15:57:20.767",
"Id": "10497",
"Score": "2",
"Tags": [
"scheme",
"racket"
],
"Title": "In-nested sequence generator for Racket scheme"
} | 10497 |
<p>I was using the jQuery form plugin to process form submission (found <a href="http://malsup.github.com/jquery.form.js" rel="nofollow">here</a>) on my page but now have to switch to using an purely jQuery AJAX based method (without using any the form plugin but I can use jQuery). What would be the best method of achi... | [] | [
{
"body": "<p>You can use jQuery's AJAX function for this directly and, you can pass object literals as parameters without using the form elements.</p>\n\n<pre><code>var params = {id : '1234'};\n$.ajax({\n type: 'GET',\n url: url, // action attribute from form element \n data: JSON.stringify(params),\n cont... | {
"AcceptedAnswerId": "10517",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T18:23:22.450",
"Id": "10501",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"ajax"
],
"Title": "AJAX alternative of using jQuery form UI"
} | 10501 |
<p>I am at the point where I feel that I am not doing it right. It works and does the job, but I am sure that there are more efficient and smarter ways of doing it.</p>
<p>I would like to see if there is a way of making it more efficient, clear, and easier to use.</p>
<p>This is my query getter:</p>
<pre><code> p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-01T02:21:50.897",
"Id": "16760",
"Score": "0",
"body": "ORM/data binding can help, but when you need hand-coded customization(such as not displaying everything, or displaying things differently), you might want to have a method return ... | [
{
"body": "<p>You might try using entity framework and direct data binding. Unless you are doing something fancy, you shouldn't have to manually loop through records to create UI elements.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-03T16:48:32.7... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T18:43:13.683",
"Id": "10504",
"Score": "0",
"Tags": [
"c#",
"sql",
"winforms"
],
"Title": "Getting data from database and then outputing it to the DataGridView"
} | 10504 |
<p>I use Python dictionaries to count words in a corpus:</p>
<p><code>words[a]</code> = number of times I saw <code>a</code> in the corpus.</p>
<p>Every time before incrementing a counter (<code>words[a] += 1</code>), I need to check a condition:
does the dictionary entry <code>words[a]</code> actually exists?</p>
... | [] | [
{
"body": "<p>For Python >= 2.5 you can use <a href=\"http://docs.python.org/library/collections.html#collections.defaultdict\" rel=\"noreferrer\">defaultdict</a> instead of dict:</p>\n\n<pre><code> from collections import defaultdict\n words = defaultdict(int)\n corpus = [\"your\", \"word\", \"corpus\"]\n for ... | {
"AcceptedAnswerId": "10527",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-31T12:53:21.213",
"Id": "10526",
"Score": "4",
"Tags": [
"python"
],
"Title": "Constantly checking existence of dictionary elements in Python: a better way?"
} | 10526 |
<p>I need some comments on the code that I "assembled". I want to know if it is efficient because I intend to use it on a live site.</p>
<p><a href="http://jsfiddle.net/Ace6h/" rel="nofollow">jsFiddle</a></p>
<p><strong>HTML:</strong></p>
<pre><code><div id="hourForm">
<div id="Monday-Friday" class="day">... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-02T10:19:17.597",
"Id": "16803",
"Score": "0",
"body": "Hmm, at least the first part of your code (\"building\" select elements) shouldn't be done in JavaScript like that, but should be part of the static HTML, possibly generated using... | [
{
"body": "<p>In the first and second <code>each</code>, I would build the entire HTML first (as a string), and then <code>append()</code> once.</p>\n\n<p><strong>Update:</strong></p>\n\n<p>I prefer something like this:</p>\n\n<pre><code>$('.day').each(function() { \n var day = $(this).attr('id'); \n var ... | {
"AcceptedAnswerId": "10567",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-31T13:07:25.633",
"Id": "10529",
"Score": "2",
"Tags": [
"javascript",
"performance",
"jquery",
"datetime"
],
"Title": "Hours of operation input form"
} | 10529 |
<p>Is this a proper way to implement an equality check? In <code>Equals</code> method, I am relying on <code>bad_cast</code> exception to know if the objects are of the same class or not. </p>
<p>Is there any other way to implement <code>Equals()</code> in C++?</p>
<pre><code>class Shape
{
public:
virtual ~... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-31T15:41:29.703",
"Id": "16749",
"Score": "3",
"body": "Why did you make operator== as non-virtual method?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-31T23:31:56.253",
"Id": "16758",
"Score": "... | [
{
"body": "<p><code>dynamic_cast</code> on <em>pointers</em> will never throw. Instead, it will return <code>0</code>.</p>\n\n<p>Furthermore, why do you actually have the <code>Equals</code> function? You can make <code>operator ==</code> virtual directly. This leaves us with:</p>\n\n<pre><code>class Circle : p... | {
"AcceptedAnswerId": "10533",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-31T13:55:42.347",
"Id": "10531",
"Score": "8",
"Tags": [
"c++",
"c++11"
],
"Title": "Equals method implemented in the class"
} | 10531 |
<p>I'm creating a system to generate math problems. As you know in mathematics, there are several different <em>kinds</em> of problems: Binary problems, fractions, decimals, comparating two numbers, etc.</p>
<p>I'm creating an abstract problem factory, where this one is like a black box, which receives a <code>Configu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-01T02:36:32.097",
"Id": "16761",
"Score": "3",
"body": "TOO MUCH CODE for a simple 2 + 3 = ? example. You studied the design patterns and wanted to implement one, but why? My problem with many patterns is that I do not see the point, t... | [
{
"body": "<p>This doesn't seem like factory pattern should handle. Factory pattern is more like creating objects without exposing the instantiation logic. It's best to use interfaces with this as well (like you have).</p>\n\n<p>Something I think you should check out is interpreter pattern. It's perfect for han... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-31T14:42:14.987",
"Id": "10532",
"Score": "33",
"Tags": [
"c#",
"design-patterns"
],
"Title": "I have a problem ...factory"
} | 10532 |
<p>I'm looking for some feedback on my implementation of MVC and functional inheritance (as described by Douglas Crockford in his book <em>The Good Parts</em>) in an app that uses the YouTube API.</p>
<p>This is my first time building anything remotely object-oriented so I'd really appreciate some advice on this app.<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-31T17:50:53.970",
"Id": "16752",
"Score": "1",
"body": "Your controller has SEVEN levels of indentation, if your levels of identation have gone over 4 then your doing it wrong, break your functions into smaller ones"
},
{
"Cont... | [
{
"body": "<p>I'm not a JavaScript expert, so just a few general notes:</p>\n\n<ol>\n<li><pre><code>var index = (i + 1) % 5,\n...\nindex: index === 0 ? index + 5 : (i + 1) % 5,\n</code></pre>\n\n<p>If I'm right, it could be written as:</p>\n\n<pre><code>index: index === 0 ? 5 : index,\n</code></pre></li>\n<li><... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-31T17:32:00.253",
"Id": "10534",
"Score": "1",
"Tags": [
"javascript",
"mvc",
"youtube"
],
"Title": "Functional inheritance using the YouTube API"
} | 10534 |
<p>This code will be brute force specific site using http POST method. </p>
<pre><code> def BruteForce(url, username, password):
userfile = open(username, "r")
userlist = userfile.read()
userlist = userlist.split("\n")
passfile = open(password, "r")
passlist = passfile.read(... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-05T09:52:12.830",
"Id": "16977",
"Score": "0",
"body": "It's probably a good idea to `close()` your files explicitly."
}
] | [
{
"body": "<p>First, improving the code:</p>\n\n<ol>\n<li><p>Reading lines from a file is as easy as <code>open(name, 'r').readlines()</code>. No need for three lines where one is enough.</p></li>\n<li><p><code>data</code> and <code>data2</code>, are on the face of it redundant (and are badly named). The redund... | {
"AcceptedAnswerId": "10537",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-31T20:18:54.527",
"Id": "10536",
"Score": "3",
"Tags": [
"python",
"http",
"authentication"
],
"Title": "Try every username and password from a list on a website"
} | 10536 |
<p>I have been writing a very slim MVC framework to drive a small personal website. It's nothing intricate, just mostly for fun and a learning experience. </p>
<p>Specifically, this is the initial part of the MVC and just the entry point. I don't want to develop all this logic for the models and views if my dispatcher... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-01T05:37:10.187",
"Id": "16766",
"Score": "0",
"body": "As far as I understand you post just \"C\" from \"MVC\" here (and may be not all its code). What is missing here is error handling and initialization: how do you load all `<head>`... | [
{
"body": "<p>You are basically on the right track though you could use:</p>\n\n<pre><code>$controller->$method($arguments);\n</code></pre>\n\n<p>instead of call_user_func_array.</p>\n\n<p>The reason that other routers are more complicated is because they do a lot more. For example, you have a direct map be... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-31T22:23:45.327",
"Id": "10538",
"Score": "4",
"Tags": [
"php",
"mvc",
"url-routing"
],
"Title": "Framework to drive a small personal site"
} | 10538 |
<p>I'm trying to implement TCP connection pooling and return a connection back to the pool using <code>IDisposable</code>. I'm wondering if my implementation is correct. It seems to be working but I think because the base class also implements <code>IDisposable</code> and finalize, my code might be leaky.</p>
<pre><co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-01T02:13:20.877",
"Id": "16759",
"Score": "1",
"body": "Superficial suggestion: `internal bool IsDisposed { get; private set; }`."
}
] | [
{
"body": "<p>I have basically introduced a wrapper for connection and also <code>IDisposable</code> on <code>PoolManager</code>, so it will dispose the connections when it is disposed. And also edited the <code>Dispose</code> methods slightly.</p>\n\n<pre><code> public class BaseClass : IDisposable\n {\n in... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-01T01:19:05.870",
"Id": "10539",
"Score": "7",
"Tags": [
"c#",
".net"
],
"Title": "Implementing IDisposable correctly to return TCP connection back to pool"
} | 10539 |
<p>I am creating a small Node.js application, but I think the file becomes unreadable. I am certain the file can be split into some better managable file.</p>
<p>Here is my app.js</p>
<pre><code>var sio = require('socket.io'),
fs = require('fs'),
express = require('express'),
conne... | [] | [
{
"body": "<p>Before trying to split the program into separate files, I would suggest first commenting your functions to explain what they are accomplishing in the context of your application. Then, add comments that group things under a specific \"section\", e.g.:</p>\n\n<pre><code> /* --- INITIALIZE ALL GL... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-01T13:59:05.823",
"Id": "10544",
"Score": "1",
"Tags": [
"javascript",
"node.js"
],
"Title": "Need some help splitting up my Node.js code"
} | 10544 |
<p>Are these methods <code>getNewId()</code> & <code>fetchIdsInReserve()</code> thread safe ?</p>
<pre><code>public final class IdManager {
private static final int NO_OF_USERIDS_TO_KEEP_IN_RESERVE = 200;
private static final AtomicInteger regstrdUserIdsCount_Cached = new AtomicInteger(100);
private... | [] | [
{
"body": "<p>Imagine this scenario: thread A arrives first and executes the entire <code>synchronized(IdManager.class)</code> block, but is interrupted before the row return <code>regstrdUserIdsCount_Cached.incrementAndGet();</code> so that the counter is not incremented.</p>\n\n<p>The arrives thread B. It ent... | {
"AcceptedAnswerId": "10573",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-01T15:31:32.917",
"Id": "10545",
"Score": "1",
"Tags": [
"java",
"multithreading",
"thread-safety"
],
"Title": "Is this method thread safe?"
} | 10545 |
<p>I am a C++ programmer new to Ruby and someone suggested that I post my code here since it doesn't quite match Ruby standards. Is there a more Ruby way of doing this?</p>
<p>I have created a 2D array full of MapTile class objects and then I draw the tiles to the screen by iterating through the 2D Array using a for l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-01T21:06:19.407",
"Id": "16781",
"Score": "1",
"body": "\"for\" blocks are kind of code smoke in Ruby. Whenever you find yourself writing one, you should think again. Alternative can be using `@mapSize.times { |i| some_operation }`"
... | [
{
"body": "<p>First of all your indentation is a bit wacky. Sometimes you indent by 4 spaces, sometimes by 2 (which is the default in the ruby community) and sometimes not at all (for example you didn't indent the call to <code>attr_accessor</code> or the contents of the initialize method). You should fix that.... | {
"AcceptedAnswerId": "10551",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-01T19:51:36.803",
"Id": "10550",
"Score": "8",
"Tags": [
"ruby",
"array"
],
"Title": "Creating a 2D array of map tiles"
} | 10550 |
<p>What do you think about this for a generic singleton?</p>
<pre><code>using System;
using System.Reflection;
/* Use like this
public class Highlander : Singleton<Highlander>
{
private Highlander()
{
Console.WriteLine("There can be only one...");
}
}*/
public class Singleton<T> where... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-01T21:28:30.083",
"Id": "16785",
"Score": "0",
"body": "So how do you stop someone from using the type `T` directly and creating multiple?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-01T22:36:08.537",
... | [
{
"body": "<p>From my tests you need to add the following code. The singleton class needs a private constructor to force the use of GetInstance().</p>\n\n<pre><code>private Singleton(){return;}\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2020-... | {
"AcceptedAnswerId": "10576",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-01T21:20:13.157",
"Id": "10554",
"Score": "7",
"Tags": [
"c#",
".net",
"singleton"
],
"Title": "A generic singleton"
} | 10554 |
<p>Here is a simple working Java implementation of primality test for Fermat numbers. Is there something that I could change in code to achieve a better running time?</p>
<pre><code>import java.math.BigInteger;
public class FPT
{
public static void main(String[] args)
{
double n;
n = Double.p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-03T07:14:15.123",
"Id": "16845",
"Score": "0",
"body": "I don't understand why you are using `double` when you are working with integers. You do realize doubles aren't infinite precision."
},
{
"ContentLicense": "CC BY-SA 3.0",... | [
{
"body": "<p>I still can't quite figure out the way to this algorithm =/. But, from the Java point of view, you can gain 9-10% by changing your loop to:</p>\n\n<pre><code>for (int i = 1; i <= c; i ++) {\n BigInteger temp = s.pow(2);\n s = temp.pow(2).subtract(BigInteger.valueOf(4).multiply(temp)).add(... | {
"AcceptedAnswerId": "10577",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-02T10:55:41.687",
"Id": "10560",
"Score": "6",
"Tags": [
"java",
"performance",
"primes"
],
"Title": "Fermat primality test"
} | 10560 |
<p>While working with Android GUI my approach to adding Listeners for GUI elements is usually:</p>
<pre><code>Button helpBt = (Button) findViewById(R.id.help_button);
helpBt.setOnClickListener(new View.OnClickListener() {
/* Code */
});
</code></pre>
<p>Currently, I am at learning stage. However, will this appro... | [] | [
{
"body": "<p>It depends on how much /* Code */ there is. If it's just a few lines, that's one thing. If it gets too large though, the reader will lose sight of the fact that you're creating an anonymous listener. I would say that if the anonymous listener is more than 5, or maybe 10 lines then you should use a... | {
"AcceptedAnswerId": "10565",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-02T14:15:21.107",
"Id": "10562",
"Score": "6",
"Tags": [
"java",
"android",
"gui"
],
"Title": "Anonymous Classes for Listeners"
} | 10562 |
<p>This is all about a whole lot of animations which should happen sequentially. That's why I am using <code>promise().done()</code> functions. In the end I'm binding a function to the mousemove event (similar to a dragging feeling on hover).</p>
<p>How can I optimize / shorten it?</p>
<pre><code>function showSpecial... | [] | [
{
"body": "<p>In the interest of eliminating all duplicate code, here's a way to make the nested showupN pieces of code all get executed in one function:</p>\n\n<pre><code>function showSpecialNavigation(){\n var showIndex = 1;\n var maxShowIndex = 5; // process from .showup1 to .showup5\n var allShow... | {
"AcceptedAnswerId": "10571",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-02T15:19:45.537",
"Id": "10568",
"Score": "1",
"Tags": [
"javascript",
"performance",
"jquery",
"animation"
],
"Title": "Sequential animations"
} | 10568 |
<p>I have implemented a simple generic wrapper for MemoryCache class. Its interface looks like ConcurrentDictionary class but I tried to keep it simple. I tried to keep operations atomic, hoping not to break the thread-safety. Is there a mistake about thread-safety? I also want to know if I there are some boxing-unboxi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-25T09:35:34.127",
"Id": "63343",
"Score": "0",
"body": "Hi there,came across your class.Planning to use with EF how do you use it?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-25T09:40:53.253",
"Id":... | [
{
"body": "<p>When implementing the Dispose interface it is advisable to use a two stage clean up. So that when you use this not inside a <code>using clause</code> the garage collection can also work correctly.</p>\n\n<p>Technically you can get away with it here; but I find it is useful to always use this patte... | {
"AcceptedAnswerId": "10575",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-02T18:44:35.497",
"Id": "10572",
"Score": "4",
"Tags": [
"c#",
".net",
"thread-safety"
],
"Title": "Generic wrapper for System.Runtime.Caching.MemoryCache"
} | 10572 |
<p>I used this code on my own site and now trying to transfer it to my new site which uses codeigniter. I'm not sure how I can eliminate some of this code and still maintain its purpose and functionality with merging it into my controller, model, and library.</p>
<pre><code><div id="headerCharacter">
... | [] | [
{
"body": "<p>First, you should really use <a href=\"http://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php\" rel=\"nofollow\">prepared statements</a> instead of stuff like <code>user_accounts.id = '\".$user_id.\"'\";</code>: this will avoid security issues. Let's look at your actual question no... | {
"AcceptedAnswerId": "10639",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-02T19:42:03.273",
"Id": "10574",
"Score": "1",
"Tags": [
"php",
"codeigniter"
],
"Title": "Updating Old Code Into Code Igniter Use"
} | 10574 |
<p>I've searched the web if there is a generic indexer in c# (4.0 / WPF) but could not find anything about it.</p>
<p>So I came up with my own solution and would like to share it with you. I hope to get some feedback on improvements.</p>
<pre><code>public dynamic this[string attribute, Type type]
{
get
{
... | [] | [
{
"body": "<p>You can use generics if you don't insist on it being an indexer:</p>\n\n<pre><code>public T GetAttribute<T>(string attribute)\n{\n return (T)base.GetAttribute(attribute);\n}\n</code></pre>\n\n<p>I'm not so sure about the other things you're doing. <code>Convert.ChangeType()</code> could j... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-02T22:32:43.247",
"Id": "10579",
"Score": "1",
"Tags": [
"c#"
],
"Title": "my solution for a typesafe indexer"
} | 10579 |
<p>I've a jQuery validation script to check all form fields for a valid value and prevent form submission and display an error message if any fields fail. It was requested that the validation script not check fields one by one, but that it check and highlight ALL fields that failed validation. It works perfectly. But I... | [] | [
{
"body": "<p>split the individual validations and complete form validation. generalize the validations, something like here</p>\n\n<pre><code>$(\"#footer_newsletter\").submit(function() {\n\n // send all fileds and their types to check form method \n var invalidFields = checkForm({\"type\":\"email\",\"... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-02T23:25:06.610",
"Id": "10582",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Simple jQuery validation script works but it uses a ton of if/else statements"
} | 10582 |
<p>I humbly ask that you review my simple (albeit a little over-done) program. The intention is to create a deck of cards, shuffle them, and draw the first five off the deck as a poker hand.</p>
<p>Can you offer some feedback, particularly if something can be done more efficiently? I intentionally left out much of th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-05T17:40:30.140",
"Id": "16989",
"Score": "1",
"body": "`CardEnum` sounds like the wrong name for that, if you're using it in a class called `Card`. I think I'd prefer `Face` or similar. And drop the `Enum` - it's noise."
},
{
... | [
{
"body": "<ol>\n<li>Using <code>name</code> coupled with <code>getSymbol</code> is confusing - the underlying property name should be the same. </li>\n<li>Do not omit <code>public</code>/<code>private</code>/<code>default</code> modifiers. </li>\n<li><p>Get rid of this method:</p>\n\n<pre><code>// A card shoul... | {
"AcceptedAnswerId": "10585",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-03T00:00:39.267",
"Id": "10583",
"Score": "3",
"Tags": [
"java",
"playing-cards"
],
"Title": "Basic Poker Draw"
} | 10583 |
<pre><code>#!/usr/bin/env python
"""
Safely copies .mpg files from one volume to another using
temporary filenames and hash verification
"""
import os
from datetime import datetime
from hashlib import sha256
from shutil import copy2
#ask user for origin (where to get files)
def choose_drive(drives, label):
while... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-03T14:26:07.533",
"Id": "16868",
"Score": "1",
"body": "No explanation, no nothing, we don't work for you. We are here for free and for fun, if you want our help you'll have to ask better."
},
{
"ContentLicense": "CC BY-SA 3.0"... | [
{
"body": "<p>Responses in comments starting with <em>koj -</em>.</p>\n\n<pre><code>#!/usr/bin/env python\n\n\"\"\"\nSafely copies .mpg files from one volume to another using\ntemporary filenames and hash verification\n\"\"\"\n\nimport os\nfrom datetime import datetime\nfrom hashlib import sha256\nfrom shutil i... | {
"AcceptedAnswerId": "10602",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-03T02:37:51.283",
"Id": "10584",
"Score": "3",
"Tags": [
"python"
],
"Title": "Robust .mpg file copier"
} | 10584 |
<p>I have the following code, to store a web service name value pair response into DB. I am saving it in xml column of DB. Kindly highlight the issues with this approach. Please note that the name value pair (i.e response.details) array is dynamic and i cannot directly map it to individual db columns.</p>
<pre><code>X... | [] | [
{
"body": "<p>You could achieve a little more readability using Linq2Xml like this:</p>\n\n<pre><code>var ex = new XElement(\"ServiceResponse\",\n response.details.Select(detail => \n new XElement(\"Details\", \n new XElement(CleanName(detail.name), detail.value))));\n</code></pre>\n\n<p... | {
"AcceptedAnswerId": "10590",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-03T08:53:10.613",
"Id": "10588",
"Score": "2",
"Tags": [
"c#",
"linq",
"xml"
],
"Title": "Converting NameValue pair entity to XML"
} | 10588 |
<p>With the help of some users here, I finally terminated the conversion of this code from C:</p>
<pre><code>#include <windows.h>
#include <stdio.h>
#define IS_IN_SEARCH(mb, offset) (mb->searchmask[(offset)/8] & (1<<((offset)%8)))
#define REMOVE_FROM_SEARCH(mb, offset) mb->searchmask[(off... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-03T12:42:25.823",
"Id": "16859",
"Score": "0",
"body": "Welcome to Code Review - please check out the [FAQ]. We ask that you put your code in the post, because it makes it a lot easier for us to review it. For example, I can't even get... | [
{
"body": "<p>First problem: <code>MEMBLOCK::next</code> in C is a pointer to a single <code>MEMBLOCK</code>, but in your Delphi code, it's an <em>array</em> of pointers. Declare it as a <code>PMemBlock</code> instead.</p>\n\n<p>The C definition of <code>WRITABLE</code> combines flags with the <em>or</em> opera... | {
"AcceptedAnswerId": "11436",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-03T12:39:40.883",
"Id": "10592",
"Score": "2",
"Tags": [
"c",
"delphi"
],
"Title": "Just compare if is conversion correct"
} | 10592 |
<p>I'm learning Haskell and I needed to work with <a href="http://en.wikipedia.org/wiki/Discrete_cosine_transform" rel="nofollow">discrete cosine transform matrices</a>, so I made a program that generates text (usable in WolframAlpha) containing the generated matrix.</p>
<p>The elements of the n-square matrix C are de... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-04T15:33:00.913",
"Id": "16952",
"Score": "0",
"body": "You have a bug: 0/0 is 1, and not 0."
}
] | [
{
"body": "<p>It is probably more in the spirit of functional programming to use pattern matches instead of long guard lists where possible. Your first function also has a few overlapping cases that could be eliminated in the interest of brevity:</p>\n\n<pre><code>showFraction _ 0 = error \"Division by zero.\"\... | {
"AcceptedAnswerId": "10622",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-04T06:02:00.800",
"Id": "10607",
"Score": "8",
"Tags": [
"haskell",
"mathematics",
"matrix",
"formatting",
"signal-processing"
],
"Title": "Computing a Discrete Cosine Tra... | 10607 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.