body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>Is the test flexible?</p>
<pre><code> describe "self.sort" do
before(:each) do
@tee = FactoryGirl.create :author, nickname: "tee jia hen", user: FactoryGirl.create(:user)
@jon = FactoryGirl.create :author, nickname: "jon", user: FactoryGirl.create(:user)
@tee_article1 = FactoryGirl.create :ar... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T06:47:13.077",
"Id": "23610",
"Score": "0",
"body": "As far as I can tell, that is a perfectly well-written rspec test. But we can't decided if it's flexible until you tell us what you might do with it."
}
] | [
{
"body": "<p>Provided you sort the active record results (as you have done), comparing to an array works fine. I'm not sure what you mean by 'flexible', but the test you've written looks pretty good (without knowing the internals of your 'sort' function).</p>\n\n<p>I'd only suggest adding some more tests to c... | {
"AcceptedAnswerId": "14974",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T03:22:11.153",
"Id": "14548",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails",
"rspec"
],
"Title": "Comparing an active record result with an array of object in a rspec test"
} | 14548 |
<p>I'm creating a MVC structured content management system as both a means to learn better OOP and redesign my tacky website to me more modular and simplistic. My aim is to approach everything with regard for minimalism so I want all my code to be precise and to the point. As this is my first go at both MVC and true OO... | [] | [
{
"body": "<p>Woah boy, sorry about the wall.</p>\n\n<p><strong>View</strong></p>\n\n<p>I'll start with the easiest section first to get it out of the way. Short tags should be avoided, even in views. Not all servers support them and its just easier to write it out the first time rather than worry about somethi... | {
"AcceptedAnswerId": "14670",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T10:14:49.520",
"Id": "14550",
"Score": "1",
"Tags": [
"php",
"object-oriented",
"mvc"
],
"Title": "MVC Structured CMS"
} | 14550 |
<p>I have written some code in Java that consists of two classes. I have tried my best and I want you to tell me if I can improve and how good this is.</p>
<p>Also, how important is OOP? Java is an object oriented language, so I have also tried my best to use it that way (although I don't know whether I have succeeded... | [] | [
{
"body": "<p>Your code is clear and readable. You are asking about how much your code fit with OOP and this is a good mindset.</p>\n\n<p>I won't be writing here abstract and theoretical concepts about OOP or design patterns, but just the first ideas which came up to my mind while I read your code.</p>\n\n<p><s... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T11:43:20.703",
"Id": "14551",
"Score": "8",
"Tags": [
"java",
"object-oriented",
"random",
"simulation",
"dice"
],
"Title": "Imitate randomness of a dice roll"
} | 14551 |
<p>I've written my first class to interact with a database. I was hoping I could get some feedback on the design of my class and areas that I need to improve on. Is there anything I'm doing below that is considered a bad habit that I should break now?</p>
<ul>
<li><code>public IEnumerable<string> ReturnSingleSet... | [] | [
{
"body": "<p>I believe it's much better to use some ORM together with LINQ, rather than writing raw SQL. It means more errors are checked at compile time, it will help you avoid some common mistakes and it will make your code much shorter.</p>\n\n<p>I would also always use parametrized SQL queries and never co... | {
"AcceptedAnswerId": "14554",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T13:00:59.323",
"Id": "14553",
"Score": "5",
"Tags": [
"c#",
"sql",
"ado.net"
],
"Title": "Interacting with a database"
} | 14553 |
<p>Basically, I have a list, <code>newtry</code> of blocks, and I want to find a value of <code>catchtype</code> that makes them all return true for <code>block.isCatchExtendable(newhandler, catchtype)</code> or report an error if this can't be done. <code>block.isCatchExtendable</code> returns two values, success and ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-12T15:31:44.010",
"Id": "23656",
"Score": "0",
"body": "Could you share the code or algorithm for isCatchExtendable?, I suspect a better interface for that could help here. But I don't know what its doing."
},
{
"ContentLicense... | [
{
"body": "<p>First off, a pet peeve of mine: <code>while 1</code> makes no semantical sense. You want <code>while True</code>.</p>\n\n<p>However, in your case you actually want <code>while ct_changed</code>:</p>\n\n<pre><code>ct_changed = True\nwhile ct_changed:\n ct_changed = False\n for block in newtry... | {
"AcceptedAnswerId": "14615",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T14:58:00.427",
"Id": "14556",
"Score": "4",
"Tags": [
"python"
],
"Title": "Checking if blocks are catch extendable"
} | 14556 |
<p>I'm currently in the process of learning scala, and I'm looking for some best practices/proper idioms for the use of pattern matching with <code>BigInt</code>s. I'm writing some algorithmic code (for Project Euler) as a way to learn the language.</p>
<p>The problem I am running into is what is the best idiomatic w... | [] | [
{
"body": "<p>Write your own <a href=\"http://codemonkeyism.com/scala-goodness-extractors/\">extractor</a>:</p>\n\n<pre><code>object Big {\n def unapply(n:BigInt) = Some(n.toInt)\n}\n\n//usage\ndef f(b:BigInt) = b match {\n case Big(0) => \"none\"\n case Big(1) => \"one\"\n case _ => \"many\"\n}... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T18:40:52.857",
"Id": "14561",
"Score": "5",
"Tags": [
"scala"
],
"Title": "Matching BigInts in Scala"
} | 14561 |
<p>Is there any room for improvement on this code?</p>
<p>I use mechanize to get the links of a job listing web site. There are pages with pagination (when jobs > 25) and pages without.</p>
<p>If there is, then the link number 5 is labelled after "Next >" and link number 6 is "Last >>".
In order to identify them, I m... | [] | [
{
"body": "<p>Here are some comments.\n- If you are only @page as a way to communicate with <code>scarpe_single_page</code>, why not make it a parameter?</p>\n\n<pre><code>def scrape_duty_station\n agent = Mechanize.new \n page = agent.get(web_link)\n</code></pre>\n\n<p>Avoid extra indent when one of the... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T10:38:50.197",
"Id": "14562",
"Score": "4",
"Tags": [
"optimization",
"ruby",
"web-scraping"
],
"Title": "Web scraper for job listings"
} | 14562 |
<p>I've spend the last several hours working on a <code>loop</code> designed to take items in an array and arrange them as a so to speak "gird" of <code>UIButton</code>s. As far as I've been able to see through testing this code works perfectly.</p>
<p>However, I am new to creating loops and I was wondering if anyone ... | [] | [
{
"body": "<p>you can write this code dramatically shorter like </p>\n\n<pre><code>self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];\n\nNSArray *array = [[NSArray alloc] initWithObjects:@\"Item #1\", @\"Item #2\", @\"Item #3\", @\"Item #4\", @\"Item #5\", @\"Item #6\", @\"Item #7\", @\"Item... | {
"AcceptedAnswerId": "14583",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T20:19:07.370",
"Id": "14564",
"Score": "1",
"Tags": [
"optimization",
"performance",
"objective-c",
"ios"
],
"Title": "Efficiency of grid generated by for-in loop"
} | 14564 |
<p>I redid a Python Reversi move preview routine that is online. I could use comments about using Python better and/or better OOP design since the original did not use classes. There are three main classes:</p>
<ol>
<li><code>Board</code> for the Reversi board</li>
<li><code>Location</code> to hold an x,y coordinate (... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-12T17:56:02.157",
"Id": "23664",
"Score": "0",
"body": "You've combined the _representation_ of the reversi board with the _information_ contained in the board. It's a good idea to separate the two. The board good be represented as a 2... | [
{
"body": "<pre><code>import unittest\nimport copy\nfrom bitarray import bitarray\n\nINITIAL_BOARD = \"\"\"\n|_|_|_|_|_|_|_|_|\n|_|_|_|_|_|_|_|_|\n|_|_|_|_|_|_|_|_|\n|_|_|_|B|W|_|_|_|\n|_|_|_|W|B|_|_|_|\n|_|_|_|_|_|_|_|_|\n|_|_|_|_|_|_|_|_|\n|_|_|_|_|_|_|_|_|\n\"\"\"\n\ndef other_player(playerId):\n return '... | {
"AcceptedAnswerId": "14582",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T22:47:09.977",
"Id": "14568",
"Score": "1",
"Tags": [
"python",
"classes"
],
"Title": "Reversi move class"
} | 14568 |
<p>I'm doing some coding challenges to get better practiced at my coding. I'm trying to do one that requires us to do a ROT13. I've got the implementation correct, and I just want to know a couple of things.</p>
<p>The space character is showing up as a crazy character in my terminal screen, which I'm assuming is be... | [] | [
{
"body": "<p>A few fairly minor things:</p>\n\n<hr>\n\n<p><strong>Constants for the characters</strong></p>\n\n<p>Instead of using the constants, you can just use a character inline:</p>\n\n<pre><code>if(input[index] >= 'a' && input[index] <= 'm')\n</code></pre>\n\n<p>It's worth noting though tha... | {
"AcceptedAnswerId": "14571",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T23:07:03.887",
"Id": "14569",
"Score": "4",
"Tags": [
"c++",
"caesar-cipher"
],
"Title": "ROT13 implementation"
} | 14569 |
<p>We're preparing for an exam at the moment, and our lecturer has given us a sample problem to work on. I have it completed, but would like to know a) If it is actually doing what it's supposed to, and b) if it could be done more efficiently or there are any questionable coding aspects. It certainly seems to be workin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-12T15:09:42.103",
"Id": "23653",
"Score": "1",
"body": "Looks good. Only issues is your indentation is not consistent (probably because you are mixing tabs a char most companies will tell you to pick one or the other but not to mix). A... | [
{
"body": "<p>I have a few minor points:</p>\n\n<ul>\n<li><p>put main() last to avoid the need for prototypes.</p></li>\n<li><p>any reason for exit(0) instead of return 0 (or EXIT_SUCCESS) in main() ?</p></li>\n<li><p>in initialise() don't cast the return from malloc()</p></li>\n<li><p>create the barrier after ... | {
"AcceptedAnswerId": "14599",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T23:10:45.730",
"Id": "14570",
"Score": "2",
"Tags": [
"c",
"multithreading",
"homework",
"linux",
"pthreads"
],
"Title": "Producer-consumer in C using pthread_barrier"
... | 14570 |
<p>I am trying to learn Mongodb and decided to build a simple blog application using Zend Framework and Mongodb (using <a href="https://github.com/coen-hyde/Shanty-Mongo" rel="nofollow">Shanty for ZF</a>).</p>
<p>I have the following document for Post</p>
<pre><code>class App_Model_Post extends Shanty_Mongo_Document
... | [] | [
{
"body": "<p>The correct answer depends on a few application design decisions.</p>\n\n<p>Reasons why you should embed Comments in Posts:</p>\n\n<ul>\n<li>You have a limit on the number of comments that can be on a post</li>\n<li>The comment limit is relatively small (mongodb docs have a hard limit\nof 4mb but ... | {
"AcceptedAnswerId": "14577",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-12T08:17:12.123",
"Id": "14576",
"Score": "1",
"Tags": [
"php",
"zend-framework"
],
"Title": "Mongodb Post/Comment use case"
} | 14576 |
<p>I'm working on my own PHP framework for a long while now.
Right now I'm in a refactoring process.</p>
<p>I'm came up with the question what a programmer would excpect what happens when he see following code:</p>
<pre><code>// working object orientated with a database.
$UserGroup = new UserGroupModel();
$UserGroup... | [] | [
{
"body": "<p>Without reading any documentation, huh? Well let me read you your code as I see it then.</p>\n\n<ol>\n<li>Create new Author</li>\n<li>Give it a name(instead of title? or is that really the book too?)</li>\n<li>Add it to the database.</li>\n<li>Create a new Book</li>\n<li>Give it a title</li>\n<li>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-12T14:14:32.890",
"Id": "14581",
"Score": "2",
"Tags": [
"php"
],
"Title": "Code behaviour: Working object orientated with a database"
} | 14581 |
<p>Anonymous functions are one of the best features of C++11. They make everything so beautiful! </p>
<p>However, one can get carried away and start overusing them.</p>
<p>This code calls a function that reads through a file and invokes a callback everytime that something matches a regex. Since I read two different f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T11:50:19.977",
"Id": "23693",
"Score": "0",
"body": "Meh, looks good to me. Just make the `node` argument `const&`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T11:55:12.823",
"Id": "23694",
... | [
{
"body": "<p>First of all, I will assume there is something like <code>template <typename T></code> somewhere in your code. Otherwise, I doubt it would compile.</p>\n\n<p>There is something you could do to improve your program: use <code>emplace_back</code> instead of <code>push_back</code> with an objec... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-12T19:21:48.077",
"Id": "14588",
"Score": "4",
"Tags": [
"c++",
"design-patterns",
"c++11",
"lambda"
],
"Title": "C++11 factory pattern with lambdas"
} | 14588 |
<p>Is this PDO wrapper structure dynamic? Can using <code>self::</code> rather than <code>$this</code> cause problems?</p>
<pre><code>class Database
extends PDO
{
/*@var mixed $stmt Used as a temporary variable to hold queries*/
private $stmt = Null;
/*@var $scopeSelectVar Used as a temporary variable to hold q... | [] | [
{
"body": "<p>When trying to make things like this, it's amazing how quickly it can become complicated and how many OOP ideas and principles can be involved.</p>\n\n<p>Anyway, there's a lot to cover here, so I'm just going to glaze over a few things and may come back and edit more detail in later.</p>\n\n<p>For... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-12T19:45:27.950",
"Id": "14589",
"Score": "7",
"Tags": [
"php",
"object-oriented",
"sql",
"pdo"
],
"Title": "PDO wrapper structure"
} | 14589 |
<p>I built my first long running AJAX heavy app and memory leaks are eating me alive.
I don't want to post too much code because it should be my job to fix it all, but I need some help.</p>
<p>Does this code leak? Where? Why? and if you'd be so kind as to suggest a fix.</p>
<pre><code>function list_stuff(data, type,... | [] | [
{
"body": "<p>javascript is garbage collected, unless you're making huge(tens of MB of XML/JSON) data transfers every couple of seconds and keep references to that data, there should be \"no memory leak\" unless the browser is doing a lousy job.</p>\n\n<p>I would put \"items\" array as global variable so that w... | {
"AcceptedAnswerId": "14716",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T00:07:03.587",
"Id": "14592",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"memory-management",
"ajax"
],
"Title": "Possible leak in heavy app"
} | 14592 |
<p>I have followed the TGA specs described <a href="http://local.wasp.uwa.edu.au/~pbourke/Dataformats/tga/" rel="nofollow">here</a> (the info at the end of the page is what this method is based on) and have written a method that takes a TGA file's pixel data section and creates a bitmap out of it.</p>
<p>It works, but... | [] | [
{
"body": "<p>The 128 case can be optimized as:</p>\n\n<pre><code> if (packetType == 128) \n { \n // packet stores number of times following pixel is repeated \n repeat = (packetHdr & ~(1 << 7)) + 1; \n bytes = inFile.ReadBytes(bytesPerPixel);\n for (int j = 0; j <... | {
"AcceptedAnswerId": "14594",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T03:37:04.713",
"Id": "14593",
"Score": "2",
"Tags": [
"c#"
],
"Title": "Refactoring a TGA image parser"
} | 14593 |
<p>I want to get just the first line of a big string. Currently, here's how I do it:</p>
<pre><code>def getFirstParagraph(txt: String) = {
val newLineIdx = txt.indexOf("\n") match {
case i: Int if i > 0 => i
case _ => txt.length
}
txt.substring(0, newLineIdx)
}
</cod... | [] | [
{
"body": "<pre><code>scala> def getFirstParagraph(txt: String) = {\n Option(txt).map(_.takeWhile(c => c != '\\n')).orNull\n }\ngetFirstParagraph: (txt: String)String\n\nscala> getFirstParagraph(null)\nres2: String = null\n\nscala> getFirstParagraph(\"fsdfasf\")\nres3: String = fsdfasf... | {
"AcceptedAnswerId": "14598",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T01:52:15.360",
"Id": "14596",
"Score": "6",
"Tags": [
"strings",
"functional-programming",
"scala",
"exception-handling"
],
"Title": "A safer way to cut a string"
} | 14596 |
<p>Trying to come up with a way to have a fixed space (eg <code>20px</code>) between two blocks on a single line which dynamically resize to fit that line (<code>50%</code> each minus the fixed space between).</p>
<p>I ended up with the <a href="http://jsfiddle.net/XfStv/" rel="nofollow">following code (demo)</a>:</p>... | [] | [
{
"body": "<p>I guess this is the proper way to have fixed space between to half-fitted blocks, but maybe later you'll have small issuer with container DIV, because child elements are absolute position and parent - relative, so it will not follow heights of child elements. </p>\n\n<p>for example: <a href=\"htt... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T07:14:31.913",
"Id": "14602",
"Score": "1",
"Tags": [
"html",
"css"
],
"Title": "Fixed space between two dynamically sized blocks"
} | 14602 |
<p>I have written some code for finding a level in a binary tree, having a maximum number of elements. I have a few questions:</p>
<ol>
<li>Is it a good design? I have used 2 queues but the total sum of elements both queues store will be less than n. So I think it should be OK.</li>
<li>Can there be a better design?</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T10:57:54.223",
"Id": "23688",
"Score": "1",
"body": "This looks pretty complex. What’s the “level” (since you are obviously not using the usual definition by returning an `int`)? Does it correspond to the depth of a node? If so, the... | [
{
"body": "<p>My initial criticism is that your method doesn't have javadoc comments that state <em>clearly and unambiguously</em> what the method is supposed to do. </p>\n\n<p>Why am I saying that?</p>\n\n<p>Well, mainly because your Question has exactly the same problem! You say:</p>\n\n<blockquote>\n <p>I... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T07:55:39.310",
"Id": "14603",
"Score": "4",
"Tags": [
"java",
"algorithm",
"queue"
],
"Title": "Binary tree max sum level - better design?"
} | 14603 |
<p>I need to create an image on the fly where one large image covers a small image. The large image is a mask which makes the underlying image visible. Here is a quick sketch of what I'm trying to accomplish: </p>
<p><a href="https://i.stack.imgur.com/TTf4P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T13:04:46.827",
"Id": "23700",
"Score": "0",
"body": "How long does your code take to run? Would there be any benefit in finding another method? (In other words, are you trying to over-optimise?)"
},
{
"ContentLicense": "CC B... | [
{
"body": "<p>First of all don't save your temporary file as tmp.jpg, think about what happends if there are 2 requests for an image at the same time, the first tmp.jpg will be overwritten by the second one (very unlikely, but still possible and very hard to debug / reproduce bug)..</p>\n\n<p>Second saving to t... | {
"AcceptedAnswerId": "14824",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-08-13T13:00:08.513",
"Id": "14612",
"Score": "3",
"Tags": [
"php"
],
"Title": "Dynamic image using PHP"
} | 14612 |
<p>I watched <a href="http://www.youtube.com/watch?v=mtvoOIsN-GU" rel="nofollow">this live coding of Sokoban</a> in Haskell and thought I'd take a crack at writing it using State and lenses, since I've never tried that before. My problem is that the control flow seems to be complicated by <code>isWall</code> and friend... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T18:09:40.423",
"Id": "23718",
"Score": "1",
"body": "I found it very hard to give a good example of exactly what I \"feel\" is bad code, but I've tried to give the ones I think are most obvious now. Thank you for the feedback. :)"
... | [
{
"body": "<p>I think the <code>is*</code> functions are a bad idea - Haskell has pattern matching for this.</p>\n\n<p>Also you can 'unwrap' your <code>World</code> when necessary and get unwrapped data from it.</p>\n\n<pre><code>data Cell = Wall | Crate | Storage | Worker | Empty\n\ncellContents coords world =... | {
"AcceptedAnswerId": "15312",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T15:20:43.370",
"Id": "14616",
"Score": "5",
"Tags": [
"haskell"
],
"Title": "Rewrite of Sokoban using State"
} | 14616 |
<p><a href="https://codereview.stackexchange.com/questions/14674/referential-mysql-design">A modified review request has been made here.</a></p>
<p>Can I please have someone review this simple database design below and tell me if this is the correct way to achieve what I want to do? </p>
<p><strong>What I am trying t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T19:15:24.867",
"Id": "23724",
"Score": "0",
"body": "Could you write something about the specification? Some sample data also could help."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T23:11:49.893",... | [
{
"body": "<ol>\n<li><p>I'd use longer attribute names (<code>firstName</code> instead of <code>fName</code>, <code>middleName</code>, <code>lastName</code>). \nIt's easier to read and maintain.</p></li>\n<li><p>Are you sure that <code>latin1</code> is enough for every data? Consider using <code>UTF-8</code>.</... | {
"AcceptedAnswerId": "14629",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T17:33:49.637",
"Id": "14619",
"Score": "1",
"Tags": [
"mysql",
"sql"
],
"Title": "MySQL database with foreign key support"
} | 14619 |
<p>I am currently working on an unfinished project about Chess, it will (at some point) be able to help me to make some chess variations just by pasting the FEN position while I play online.</p>
<p>But before continuing, my code must have good structure or it will become a nightmare to fix it later. So now that I have... | [] | [
{
"body": "<p>The first thing I noticed are the escaping orgies. Both HTML and JavaScript allow you to use either <code>'</code> or <code>\"</code> to quote strings. Don't use the same for both and you can get rid of all those ugly backslashes.</p>\n\n<p>You can also get rid of the (badly-named) <code>bol</code... | {
"AcceptedAnswerId": "14622",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T18:07:00.273",
"Id": "14620",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Can someone have a look to my Chess Project?"
} | 14620 |
<p>How can I format this code so it's more readable?</p>
<pre><code>$(".card").click(function(){
$(this).stop().animate({
width:'0px',
marginLeft: margin+'px',
opacity: 0.5},
500,
function(){
$(this).siblings('.card').animate({
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T19:07:53.580",
"Id": "23721",
"Score": "1",
"body": "I just read it...."
}
] | [
{
"body": "<p>This is a very subjective question </p>\n\n<p>I am a fan of separating things so each is identifiable and easily maintained in the future. However some will argue this does lead to more code, but more readable code in my opinion. </p>\n\n<pre><code>var animateCallback = function() {\n var props... | {
"AcceptedAnswerId": "14625",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T18:13:21.430",
"Id": "14621",
"Score": "4",
"Tags": [
"javascript",
"formatting"
],
"Title": "How would I format this JavaScript code so it's more readable"
} | 14621 |
<p>I have a jQuery function using a series of <code>if</code> and <code>else</code> statements. I am wondering if there is a more elegant way I can code this. I am thinking I could create an array with my "hashtag names" and then loop it through a function. However, I am not quite sure how to go about doing that.</p>
... | [] | [
{
"body": "<p>You can just parse the number right out of the location like this:</p>\n\n<pre><code>setTimeout(function() {\n var matches = window.location.hash.match(/^#page(\\d+)$/);\n if (matches) {\n scroll(+matches[1] - 1);\n }\n}, 500);\n</code></pre>\n\n<hr>\n\n<p>OK, now that you've chang... | {
"AcceptedAnswerId": "14632",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T19:16:11.880",
"Id": "14630",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Loop function using an array"
} | 14630 |
<p>This is just a simple login form with a very vanilla HTML markup, but I just wanted to get some professional feedback. I know about jslint and try to adhere to there principals where possible.</p>
<pre><code><script>
//event listeners
$('#sign_in_button').on('click', sign_in);
$('#create_new_account').on('cl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T12:53:06.270",
"Id": "23853",
"Score": "0",
"body": "\"As professionals, is there anything clearly amateurishness about this code that I could improve?\" - the over-use of $()"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cre... | [
{
"body": "<ul>\n<li><p>It's in the HTML (script tag). Link it. Keep 'em separated whenever possible.</p></li>\n<li><p>Not a big deal but when declaring vars you can do them with one var statement, e.g. <code>var a = 0, b = 3;</code></p></li>\n<li><p>Add 'use strict;' to look super cool (but I've seen at least ... | {
"AcceptedAnswerId": "14640",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T01:20:57.773",
"Id": "14639",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"form"
],
"Title": "Simple login form with vanilla HTML markup"
} | 14639 |
<p>It seems it could be written shorter. It's especially annoying when I have to do this in multiple languages, so the button labels will be different.</p>
<pre><code><button id="egyes" class="btn btn-danger">Hide</button>&nbsp;some text
<button id="kettes" class="btn btn-warning">Hide</button... | [] | [
{
"body": "<p>if you add the parent div class into the data attributes:</p>\n\n<pre><code><button id=\"egyes\" class=\"btn btn-danger\" data-parentclass=\"progress-danger\">Hide</button>&nbsp;some text \n<button id=\"kettes\" class=\"btn btn-warning\" data-parentclass=\"progress-warning\">... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T05:44:10.713",
"Id": "14644",
"Score": "2",
"Tags": [
"javascript",
"performance",
"jquery"
],
"Title": "jQuery button text changer script"
} | 14644 |
<p>I'm just getting into SQL injection and data sanitization and seeking some advice on my script to get started. I have made this simple program which allows the user to enter their name into a form and the information gets saved into the database. There is also a button that lists all the current names in the databas... | [] | [
{
"body": "<p>Can't help you much here, not much of a SQL person. However, right off the bat you are going to want to validate and sanitize your data. You never want to use raw user data. That's always bad. You are doing an ok job in validating using the <code>isset()</code> function. But there's more to it. Yo... | {
"AcceptedAnswerId": "14684",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T06:57:56.767",
"Id": "14646",
"Score": "3",
"Tags": [
"php",
"security",
"mysqli"
],
"Title": "Protecting a database from bad data"
} | 14646 |
<p>For a website I'm working on, I had to get all the unique entries in an array and count their occurrence. It is possible a certain entry is only found once, but it can also be found 20 times. So I designed the following bit of code:</p>
<pre><code>for ($i = 0; $i < count($nodes); $i++)
{
for ($j = 0; $j <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T09:06:20.120",
"Id": "23772",
"Score": "0",
"body": "Post an example of your array structure"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T09:52:00.617",
"Id": "23775",
"Score": "0",
"bo... | [
{
"body": "<p>I think the associative array approach is good. You could probably get away with:</p>\n\n<pre><code>for ($i = 0; $i < count($nodes); $i++)\n for ($j = 0; $j < count($nodes[$i]); $j++)\n $uniekenodes[$nodes[$i][$j]]++;\n</code></pre>\n\n<p>As incrementing NULL values results in 1.</p>\n",... | {
"AcceptedAnswerId": "14663",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T07:09:38.493",
"Id": "14647",
"Score": "1",
"Tags": [
"php",
"drupal"
],
"Title": "Get unique entries from array"
} | 14647 |
<p>Based on a python name generator grammar I found <a href="http://jerith.za.net/code/cfnamegencode.html" rel="nofollow">here</a> I've decided to write my own in objective-C. The idea is I can load the grammar from a plist file and generate random names from it.</p>
<p>I'm looking for a general code review and any co... | [] | [
{
"body": "<p>It generally looks like good code to me, so these come under \"nits\":</p>\n\n<ul>\n<li><p>In <code>-initWithGrammar:</code> you're actually passing the <em>name</em> of the grammar, not the grammar itself. Perhaps <code>-initWithGrammarName:</code> would be better.</p></li>\n<li><p>It's conventio... | {
"AcceptedAnswerId": "14659",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T07:59:28.567",
"Id": "14649",
"Score": "2",
"Tags": [
"objective-c",
"random",
"generator"
],
"Title": "Objective-C CF Random Name Generator"
} | 14649 |
<p>I'm very new to C++, but I really want to write good code and increase my development skill, so I ask you for some review.</p>
<p><a href="http://www.gliffy.com/go/publish/3797990/" rel="nofollow noreferrer" title="scheme">Scheme of socket server</a></p>
<p>This is the scheme of how my socket server works. It crea... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T18:43:44.100",
"Id": "23811",
"Score": "1",
"body": "Using a thread per connection is not very scalable. Its OK if your expect your connection count to be in the low teens but after that not so much. Have a look at `select()` as a s... | [
{
"body": "<pre><code>#include <iostream>\n#include <string.h>\n#include <stdio.h>\n#include <vector>\n#include <arpa/inet.h>\n#include <sys/socket.h>\n#include <pthread.h>\n#include \"Observer.h\"\n\nusing namespace std;\n</code></pre>\n\n<p>This is fine for trivial de... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T08:38:01.927",
"Id": "14650",
"Score": "6",
"Tags": [
"c++",
"beginner",
"linux",
"tcp"
],
"Title": "TCP socket server for UNIX"
} | 14650 |
<p>This is a buy and sell game. I've revised it, though it's still unfinished. I would appreciate it if someone could review it again for me. </p>
<pre><code>#include<stdio.h>
#include<conio.h>
#include<time.h>
#include<stdlib.h>
void end()
{
system("cls");
int P, L, choice;
printf(" ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T10:41:52.087",
"Id": "23776",
"Score": "0",
"body": "It is just a minor suggestion, but try not to put actual values in numbers in code. For example: *phoenixdown=rand()%(1200-500+1)%650 . Define what 1200, 500 or 650 mean. Use prop... | [
{
"body": "<p>I don't know any C, so I can't comment on the actual code. But it seems to me like you could move the text to txt files or xml files, instead of literally placing it in your code. You could probably walk through the txt file and print the text in a loop, rather than each line on its own. </p>\n\n<... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T09:39:07.617",
"Id": "14652",
"Score": "4",
"Tags": [
"c",
"game"
],
"Title": "\"Buy and Sell\" game project"
} | 14652 |
<p>The following code is pretty ugly. I suspect that there is a more functional and elegant way of achieving this result.</p>
<pre><code>var lines =
new[]{
new{Head="A",Value="1"},
new{Head="",Value="2"},
new{Head="",Value="3"},
new{Head="",Value="4"},
new{Head="B",Value="5"},
new{Head="B",Va... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T12:03:31.037",
"Id": "23782",
"Score": "2",
"body": "I don't see a hierarchical list here — I see a bunch of empty keys (and your code depends on the ordering of the array). Do you have any control over the creation of the array, an... | [
{
"body": "<p>You need to look through your code with an analytical eye and discover the pattern that you are implementing. I call it <strong>default if</strong> (null or) <strong>empty</strong>.</p>\n\n<p>So I created an extension method to implement that pattern.</p>\n\n<pre><code>public static string Default... | {
"AcceptedAnswerId": "14661",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T11:48:11.463",
"Id": "14657",
"Score": "2",
"Tags": [
"c#",
"linq"
],
"Title": "LINQ transforming hierachical data to flat list"
} | 14657 |
<p>JavaScript is the language everyone uses without bothering to learn it first, and I'm no exception. I'm trying to set up autorefresh with longpolling. What I have on the client side is the following:</p>
<pre><code>var getAjaxer = function(element) {
return function() {
$.ajax({
url: "/path... | [] | [
{
"body": "<p>I can't say whether yours is right or wrong but there were a couple of things that seemed odd to me.</p>\n\n<p>I wouldn't add functions to variables unless you intend to use them more than once. (or it adds to the readability)</p>\n\n<pre><code>var startAjaxing = function() {\n myajaxer = getAj... | {
"AcceptedAnswerId": "14680",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T15:05:39.233",
"Id": "14664",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Setting up longpolling"
} | 14664 |
<p>I've got the following code, which works, but seems repetitive. Under DRY principle, how can I clean this up?</p>
<pre><code>puts "Blurt out a word"
word = gets.chomp
word_list = []
word_list.push word
until word == ""
word = gets.chomp
word_list.push word
end
puts word_list.sort
</code></pre>
| [] | [
{
"body": "<pre><code>puts \"Blurt out a word\"\nword_list = []\nwhile word_list.last != \"\"\n word_list << gets.chomp\nend\nputs word_list.sort\n</code></pre>\n\n<p>If you prefer the <code>until</code>:</p>\n\n<pre><code>puts \"Blurt out a word\"\nword_list = []\nuntil word_list.last == \"\"\n word_li... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T18:13:51.860",
"Id": "14666",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "Clean up this Ruby code under DRY principle"
} | 14666 |
<p>I would like to convert ($<code>data</code>):</p>
<pre><code>Array
(
[login] => Log in
[logout] => Log out
[label] => Array
(
[email] => test@test.com
[name] => Some name
)
[controllers] => Array
(
[page] => Array
... | [] | [
{
"body": "<blockquote>\n <p>So I probably need some kind of recursion, but I have no clue how to get around that with PHP</p>\n</blockquote>\n\n<p>Recursion in PHP is the same as basically any language (well... at a very high level).</p>\n\n<p>I'm very torn on if I think your question is on topic or not, but ... | {
"AcceptedAnswerId": "14685",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T20:58:03.310",
"Id": "14671",
"Score": "2",
"Tags": [
"php",
"array"
],
"Title": "Flaten array to 1D and assigning 'associative' keynames recursively"
} | 14671 |
<p>How does this look? It has been over a year since my database concepts class and I have never worked with MySQL. I have chosen InnoDB as my engine because of foreign key support using UTF-8 based on advice from an <a href="https://codereview.stackexchange.com/questions/14619/mysql-database-design-review">earlier r... | [] | [
{
"body": "<p>You should consider normalizing <code>Survey</code> further, in that having many fields with only a differing numeric suffix indicates that it should be a single field with another key.</p>\n\n<pre><code>CREATE TABLE `Survey` (\n `cardID` int(11) NOT NULL,\n `trackID` int(11) NOT NULL,\n `question... | {
"AcceptedAnswerId": "14720",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T22:56:25.423",
"Id": "14674",
"Score": "3",
"Tags": [
"sql",
"mysql"
],
"Title": "Database of survey information"
} | 14674 |
<p>I have a class called <code>Foo</code> </p>
<pre><code>public class Foo {
private String optionalProperty;
private String name;
private long uniqueId;
// getters/setters for above properties
}
</code></pre>
<p>For some business reason I need to create an Identifier which I can use to 'identify' Foo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-14T19:53:10.587",
"Id": "25408",
"Score": "0",
"body": "Did you ever decide on an approach for this?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-14T20:31:47.623",
"Id": "25417",
"Score": "0",
... | [
{
"body": "<p>Assuming you need to retrieve the string or long values (I don't see getters for them in the single class) I prefer the three classes, with the getter methods also in the base class to avoid a cast. Each derived class would unconditionally throw an exception if the inappropriate getter method is c... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T11:19:17.440",
"Id": "14687",
"Score": "3",
"Tags": [
"java",
"object-oriented",
"classes"
],
"Title": "Subclassing or not?"
} | 14687 |
<p>I was looking at this website:</p>
<p><a href="http://www.devshed.com/c/a/MySQL/Creating-User-Models-in-PHP-and-MySQL/1/" rel="nofollow">http://www.devshed.com/c/a/MySQL/Creating-User-Models-in-PHP-and-MySQL/1/</a>
and
<a href="http://www.devshed.com/c/a/MySQL/Creating-User-Models-in-PHP-and-MySQL/2/" rel="nofollow... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T20:23:23.847",
"Id": "23855",
"Score": "0",
"body": "possible duplicate of [Best way to prevent SQL Injection in PHP](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php)"
},
{
"ContentLicense":... | [
{
"body": "<p><a href=\"http://martinfowler.com/eaaCatalog/activeRecord.html\" rel=\"nofollow noreferrer\">Active record</a> instances are not \"models\". They are anti-patterns which RoR likes call that way. And what you are implementing there is an active record.</p>\n\n<p>And no, those queries are not safe. ... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T20:21:26.323",
"Id": "14688",
"Score": "1",
"Tags": [
"php",
"mvc"
],
"Title": "Are these MySQL Abstraction Classes safe from SQL Injection? Can they be made safe?"
} | 14688 |
<p>This might be a dumb question for you advanced developers.</p>
<p>Below is a script on my own website that I want to modify, in order to <strong>avoid declaring same variables in each function</strong>. I want to avoid declaring variables in the main script structure.</p>
<p>Below code works, still wanted to know ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T14:44:37.907",
"Id": "23862",
"Score": "4",
"body": "why have you doubled `function function`?? Also where is this error? http://jsfiddle.net/rlemon/fxhK7/ I do not see it?? Unless you want to pass around the object, in what you hav... | [
{
"body": "<pre><code>var var1 = \"hello\";\nvar var2 = \"hello2\";\n\nfunction foo1(){\n var1 += \"world\";\n var2 += \"world2\";\n}\nfunction foo2(){\n var1 += \"2world\";\n var2 += \"2world2\";\n}\n</code></pre>\n\n<p>try that. you had double function keyword , and you forgot braces to close</p>\... | {
"AcceptedAnswerId": "14692",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-13T14:42:39.827",
"Id": "14690",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Better writing JS - from general variables to object"
} | 14690 |
<p>I have built a JavaScript PNG sequence engine that allows for playing, pausing and stopping and a time change event. I am asking for genuine opinions if the code is actually good. Its ONLY for the iDevice range (not for desktop browsers or anything) and here is the code and a link to the gist if you wanted to edit i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T15:21:34.367",
"Id": "23884",
"Score": "1",
"body": "As per the FAQ, you should include the code in the question. If the gist is changed or deleted the answers no longer match the question they were answering..."
}
] | [
{
"body": "<p>I would suggest a few minor changes:</p>\n\n<ol>\n<li><p>Use <code>setTimeout</code> instead of <code>setInterval</code> to ensure that callbacks don't stack up if they can't be serviced on time. This implies re-invoking <code>this.interGo</code> at the end of the callback to re-trigger the timer... | {
"AcceptedAnswerId": "14696",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T13:36:37.527",
"Id": "14694",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "The efficiency and options of my PNG sequence JS class"
} | 14694 |
<p>I wrote this <code>downloadContent()</code> function.</p>
<p>Is there some other way to download the content faster?</p>
<pre><code>private string downloadContent()
{
try
{
WebRequest request = WebRequest.Create(testingUrl);
request.Proxy = null;
request.Method = "GET";
res... | [] | [
{
"body": "<p>I don't know about faster, but please make sure you wrap your disposable resources (classes which implement <code>IDisposable</code>) in <code>using</code> statements to properly and deterministically manage resources:</p>\n\n<pre><code> private string downloadContent() \n {\n try\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T13:49:25.337",
"Id": "14695",
"Score": "2",
"Tags": [
"c#"
],
"Title": "Downloading content in the background"
} | 14695 |
<p>I am trying to use a map as a way to implement an object factory. In Python it is possible to store a class type in a map, and use it later to create objects from that type:</p>
<pre><code>class Foo:
# ...
class Bar:
# ...
factory_map = { 'foo' : Foo, 'bar' : Bar }
foo_object = factory_map['foo']()
</code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T17:26:49.780",
"Id": "23899",
"Score": "0",
"body": "I would not say if/else is more traditional. I would say that using a map was more traditional (were do you think python got that pattern from)."
},
{
"ContentLicense": "C... | [
{
"body": "<p>The common argument for preferring one over the other for a dictionary (map) look up and a conditional (switch) look up is performance over maintainability.</p>\n\n<p>The dictionary look up usually makes it easier to separate concerns. It also makes the code more concise and arguably more readable... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T14:08:39.837",
"Id": "14698",
"Score": "2",
"Tags": [
"c++",
"c++11"
],
"Title": "Creating a class object just based on the class type"
} | 14698 |
<p>My application hangs up on IE and mobile browsers when these functions are fired. Is there anything that stands out as being obviously performance-killing?</p>
<pre><code>$this.find('input.bundle-check').live('change', function() {
var $box = $(this),
ntn = $box.data().ntn,
price = $box.data().price,
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T14:44:51.150",
"Id": "23881",
"Score": "1",
"body": "well... live() should no longer be used.. it is deprecated. In newer versions use .on() and in older versions use .delegate() - not sure if this will impact performance ***that***... | [
{
"body": "<p>There are a few things which stand out to me:</p>\n\n<pre><code>var $box = $(this),\nntn = $box.data().ntn,\nprice = $box.data().price,\nsavings = $box.data().savings;\n</code></pre>\n\n<p>You use <code>$box.data()</code> several times; it may be faster to cache the return value of that function. ... | {
"AcceptedAnswerId": "14703",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T14:38:50.020",
"Id": "14699",
"Score": "-3",
"Tags": [
"javascript",
"performance",
"jquery"
],
"Title": "Functions Giving Performance Issues"
} | 14699 |
<p>I made the following class to wrap <code>mysqli</code> for PHP using prepared statements. It seems to work well, but I was hoping to get opinions (on overall structure, performance, usage, etc.). Thanks for the insight.</p>
<pre><code><?php
class database {
private $conn, $stmt, $arr, $eof=true, $error;
... | [] | [
{
"body": "<p>Instead of assigning your properties null or empty values from the start, just define them with no values. If they aren't initialized, then they will resolve to null. Although, from what I can tell, you aren't doing much checking of these properties anyways, so I don't understand why you had defau... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T15:31:34.067",
"Id": "14701",
"Score": "4",
"Tags": [
"php",
"mysqli"
],
"Title": "mysqli wrapper class"
} | 14701 |
<p>It's an interview question, I was asked to compare 2 strings, and the number in the string are evaluated to integers when comparing. </p>
<p>I can use C/C++ and can not use stl or stdlib. Some test cases are showed in the code.</p>
<p>I submitted the code below but failed. The interviewer said that the code is not... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T18:41:21.880",
"Id": "23907",
"Score": "0",
"body": "The requirements are not really clear: from the code it seems that the return value of the function is the value stored in the strings if both strings are the same. What about whe... | [
{
"body": "<p>First pick a language.</p>\n\n<p>Either use C or use C++. Do <strong>NOT</strong> use a mixture of the two (its sloppy and can introduce bugs). So first off you should have picked a language. You seem to have picked both:</p>\n\n<pre><code> #include <cmath> // C++\n p... | {
"AcceptedAnswerId": "14706",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T17:26:04.520",
"Id": "14705",
"Score": "1",
"Tags": [
"c++",
"c",
"interview-questions"
],
"Title": "C/C++ code to do customized string comparing"
} | 14705 |
<p>I was selected for the third round of MS internships for third years. We were surprisingly asked a very easy question: “Make a program that counts the number of times the WORD "a" or "A" occurs”. I wrote the code below and was rejected from attending the final interview.</p>
<p>What is wrong with my code? Please t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T18:17:11.750",
"Id": "23902",
"Score": "1",
"body": "What version of C++ are you using? I'm not familiar with the `included` statement."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T18:19:51.500",
... | [
{
"body": "<p>You should do this by using the standard library to its fullest:</p>\n\n<pre><code>std::istringstream ss(str);\nauto count = std::count_if(std::istream_iterator<std::string>(ss), std::istream_iterator<std::string>(), \n [](const std::string& s){ return s == \"a\" || s =... | {
"AcceptedAnswerId": "14773",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T18:13:09.237",
"Id": "14711",
"Score": "9",
"Tags": [
"c++",
"strings",
"interview-questions"
],
"Title": "Count the number of occurrences of a word"
} | 14711 |
<p>At work I've recently been tasked with creating an XSLT to transform some XML as it is being generated on a scanner. The point being to disregard some pages that we are not interested in for further processing, and this is what I've come up with:</p>
<pre><code> <?xml version="1.0" encoding="utf-8"?>
... | [] | [
{
"body": "<p>I'd go with a <code><xsl:key ...></code> index, like so (at top level):</p>\n\n<pre><code><xsl:key name=\"contains_RETURN\" match=\"Barcode\" use=\"contains(text(), 'RETURN')\"/>\n</code></pre>\n\n<p>and then rewrite your hotspot to:</p>\n\n<pre><code><xsl:when test=\"count(key('con... | {
"AcceptedAnswerId": "14728",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T19:28:27.460",
"Id": "14715",
"Score": "4",
"Tags": [
"xml",
"xslt"
],
"Title": "Transforming XML as it is being generated on a scanner"
} | 14715 |
<p>I was asked to create a TODO manager using JavaScript and CSS. I did not get a good review on the code nor specific comments on how to improve it.</p>
<p>Can someone here help by give me tips on what is bad with my implementation?</p>
<pre><code><html>
<head>
<script src="https://ajax.googleapi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T20:29:09.430",
"Id": "23921",
"Score": "1",
"body": "[Read the FAQ](http://codereview.stackexchange.com/faq). This website is not for full code reviews, only for small snippets, algorithms, and such."
},
{
"ContentLicense": ... | [
{
"body": "<p>You code look ok but I suggust using a MVC library, since this will abstract and simplify your logic.</p>\n\n<p>Check out this project on github, called <a href=\"https://github.com/addyosmani/todomvc\" rel=\"nofollow\">TodoMVC</a>.\nTodoMVC shows how to use popular <a href=\"http://en.wikipedia.o... | {
"AcceptedAnswerId": "15329",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T20:17:59.490",
"Id": "14718",
"Score": "3",
"Tags": [
"javascript",
"css",
"html5",
"jquery-ui",
"to-do-list"
],
"Title": "JavaScript implementation of a TODO manager"
... | 14718 |
<p>The way I am using this method assumes all data is byte-aligned, so I don't really care about the rest of the bits.</p>
<p>This method is written in an extension of BinaryReader which provides more methods when I'm reading binary data from files. The BinaryReader provided does not appear to support reading bits.</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T22:30:40.083",
"Id": "23932",
"Score": "0",
"body": "I don't think so. For example you read 4 bits and it tells the length of the following data. I'd want it as an int or a byte."
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<p>I have not tested this that well. If anyone finds a bug, please let me know.</p>\n\n<pre><code>// Throws away the unused bits\npublic byte ReadFirstNBits(int n)\n{\n Contract.Requires(n >= 0 && n <= 8, \"Code contract may be too slow for your needs\");\n byte val = base.ReadByt... | {
"AcceptedAnswerId": "14725",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T21:42:45.623",
"Id": "14721",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Reading the first n bits of a byte"
} | 14721 |
<p>I want to check if all items of a list meet a set of criteria:</p>
<pre><code>bool AreValid(list<string> vals)
{
bool allValid=true;
foreach(string val in vals)
{
if(!condition1)
...
allValid=false;
else if(!condition2)
...
allValid=false;
}
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T01:40:54.610",
"Id": "23948",
"Score": "3",
"body": "Why don't you just return false if any of the conditions fail?"
}
] | [
{
"body": "<p>It's safe. A few things to consider: </p>\n\n<ol>\n<li><p>When the list is empty you might want to return <code>false</code>.</p></li>\n<li><p>Consider using an abstract data type (instead of string) which stores your data (the string) and move the validation logic to there.</p></li>\n<li><p>As <e... | {
"AcceptedAnswerId": "14729",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-15T22:12:18.290",
"Id": "14723",
"Score": "1",
"Tags": [
"c#",
"asp.net"
],
"Title": "Validation default value"
} | 14723 |
<p><a href="http://www.codeproject.com/Articles/11015/The-Impossibly-Fast-C-Delegates" rel="nofollow">This legendary C++ delegate article</a> can be easily converted into C++11, without the need for fancy preprocessor magic in the original. I'd like to know if I got all the necessary C++11 nuances right. Suggestions?</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-05T11:51:53.470",
"Id": "43958",
"Score": "0",
"body": "Is there any reason for using this instead of `std::function`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-05T12:32:34.313",
"Id": "43961",
... | [
{
"body": "<p>It looks by and large OK. Just some nitpicks</p>\n\n<ul>\n<li><p>the default constructor could just be <code>delegate() = default;</code>, or otherwise initialize <em>all</em> members... or remove it entirely if it makes no sense.</p></li>\n<li><p>the copy constructor should use initialization, no... | {
"AcceptedAnswerId": "14795",
"CommentCount": "16",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T07:02:36.217",
"Id": "14730",
"Score": "29",
"Tags": [
"c++",
"c++11"
],
"Title": "Impossibly fast delegate in C++11"
} | 14730 |
<p>What needs to be corrected, added, or subtracted here?</p>
<pre><code>class mutexLocker
{
private:
/* Declaration of a Mutex variable `mutexA`. */
pthread_mutex_t &mutexA;
/* `mutexStatus` holds the return value of the function`pthread_mutex_lock `.
This value has to be returned to the cal... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T01:56:18.250",
"Id": "24002",
"Score": "0",
"body": "What's wrong with the standard threading library? Or, if you don't have it, boost thread?"
}
] | [
{
"body": "<p>If you are keeping a reference to an object you should pass that object to the constructor as a reference:</p>\n\n<pre><code>mutexLocker (pthread_mutex_t argMutexVariable) \n // ^^^ Missing reference.\n</code></pre>\n\n<p>You return the state of the lock operation:</p>\n... | {
"AcceptedAnswerId": "14758",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T07:41:21.703",
"Id": "14731",
"Score": "1",
"Tags": [
"c++",
"multithreading",
"pthreads"
],
"Title": "Mutex locker class in C++"
} | 14731 |
<p>I'm just learning the basics of animating with Javascript and HTML5. I'm trying to create this scrolling logos element for my site, and I'm pretty sure that my code is very inefficient. Can anyone give me any tips on how to do a better job of what I'm trying to do here?</p>
<p><a href="http://jsbin.com/anagug/1/edi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T06:25:29.833",
"Id": "23956",
"Score": "3",
"body": "drawing objects is always going to be expensive. It would be much smoother to draw those elements before the timer function starts, so that you're not expending resources to draw ... | [
{
"body": "<p>Always do a <code>clearInterval()</code> before doing a new <code>setInterval()</code> on the same variable. Doesn't matter if it has been cleared or not.</p>\n\n<p>e.g.</p>\n\n<pre><code>clearInterval(revealImage);\nrevealTimer = setInterval(revealImage,100);\n</code></pre>\n\n<p>You're code has ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T05:44:50.843",
"Id": "14734",
"Score": "3",
"Tags": [
"javascript",
"html5"
],
"Title": "How to optimize this HTML5 animation?"
} | 14734 |
<p>I'm making requests to <a href="http://www.parse.com" rel="nofollow">Parse.com</a> to 3 different objects that are needed to render a View.
I'd like to know what's the general/best approach in cases like these in which there are multiple requests before actually handling the data.</p>
<p><strong>Code:</strong></p>
... | [] | [
{
"body": "<p>Use <a href=\"https://github.com/creationix/step/\" rel=\"nofollow\">Step.js</a> or <a href=\"https://github.com/caolan/async/\" rel=\"nofollow\">async.js</a> to make this look cleaner. Step.js is simpler, but async.js gives you more flexibility. </p>\n\n<p>Also, your function single needs to ha... | {
"AcceptedAnswerId": "14737",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T10:28:31.370",
"Id": "14736",
"Score": "1",
"Tags": [
"javascript",
"node.js",
"asynchronous"
],
"Title": "Node.js Nested Callbacks, multiple requests"
} | 14736 |
<p>I have many <code><spans></code>s which need to group to change opacity after hover. All of them need to have unique IDs. Is there a way to combine all these hover functions to one function?</p>
<p><strong>jQuery</strong></p>
<pre><code>//09
$('#c_09_241a, #c_09_241b, #c_09_241c, #c_09_241d').hover... | [] | [
{
"body": "<pre><code>var groups = [\n '09_241', '09_242', '09_245', '09_246',\n '08_235', '08_236', '08_239', '08_240',\n '07_227', '07_228', '07_007', '07_008'\n];\n\n$.each(groups, function(i, group) {\n\n var $group = $('[id^=c_' + group + ']');\n\n $group.hover(function() {\n $group.s... | {
"AcceptedAnswerId": "14747",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T12:32:22.357",
"Id": "14738",
"Score": "0",
"Tags": [
"javascript",
"jquery"
],
"Title": "Combining hover functions"
} | 14738 |
<pre><code>function check_itv(key) {
if (key.length){
if(key=="left"){
left_itv = setInterval(left,100);
check_left= false;
check_right=true;
check_up=true;
check_down=true;
clearInterval(right_itv);
clearInterval(down_itv);
clearInterval(up_itv);
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T13:07:31.173",
"Id": "23966",
"Score": "0",
"body": "http://stackoverflow.com/questions/1470488/difference-between-using-var-and-not-using-var-in-javascript"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-0... | [
{
"body": "<p>Without changing too much, here are some tips on improving your code.</p>\n<p>Assumptions:</p>\n<ul>\n<li>You're working in modern web browser.</li>\n<li>left, up, down, right are defined else where.</li>\n</ul>\n<h1>1)</h1>\n<p>Define all the variables at the top. I'm not sure where the fucntions... | {
"AcceptedAnswerId": "15332",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T12:39:43.367",
"Id": "14739",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "Better jQuery function argument with if-statement?"
} | 14739 |
<p>This is one idea of implementation:</p>
<pre><code> Array.prototype.unique = function () {
unique_array = [];
for (var i = 0, l = this.length; i < l; i++) {
if(unique_array.indexOf(this[i]) == -1){
unique_array.push(this[i]);
}
}
return unique_array;
}
</code></pre>
<p>This version uses O... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-11T21:05:45.223",
"Id": "25200",
"Score": "1",
"body": "I'm not entirely sure, but I think you're asking a similar question to mine, [on SO](http://stackoverflow.com/questions/12041837/javascript-unique-method-for-array-prototype). I w... | [
{
"body": "<p>For me, I'd always avoid methods that require lots of includes to things get working - and in my mind, the more code used.. the slower things will be <em>(unless some form of caching is used)</em>. Which is why I would opt for a simple JavaScript solution. Your idea will work, but I think this one... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T12:53:18.210",
"Id": "14741",
"Score": "10",
"Tags": [
"javascript",
"optimization"
],
"Title": "Optimize/Refactor Javascript Unique Array function"
} | 14741 |
<p>I have the following code, which acts like a turntable and plays Sgt. Pepper when you load the page. This works only in Safari (I suppose I can delete the FF parts then), so I'm wondering how I can make the code better. The reason for there being a <code>first</code>, <code>last</code>, and <code>main</code> class o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-17T14:40:39.220",
"Id": "83190",
"Score": "0",
"body": "is this even real code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-17T14:43:14.160",
"Id": "83191",
"Score": "4",
"body": "So real yo... | [
{
"body": "<p>One of the first things that you can to do improve the HTML is to remove the <code><br /></code> tags, and to replace the <code><label></code> tags with <code><span></code> tags. Labels in HTML should only be found in forms.</p>\n\n<p>To achieve the same effects that the line bre... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T15:43:50.820",
"Id": "14748",
"Score": "2",
"Tags": [
"html",
"css",
"html5",
"animation"
],
"Title": "CSS3 animations of a turntable"
} | 14748 |
<p>I have a central domain assembly which contains various rich domain models. Lots of business logic, etc. To keep this example simple, here's probably the simplest one:</p>
<pre><code>public class Location
{
private int _id;
public int ID
{
get { return _id; }
private set
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-06T23:08:47.420",
"Id": "24971",
"Score": "0",
"body": "I wonder if something like [AutoMapper](https://github.com/AutoMapper/AutoMapper) would work for you. It probably wouldn't completely solve the problem though, as it would only r... | [
{
"body": "<p>I was just playing around with this concept today. I have a User class defined in another assembly. Then I created three classes \"based on\" (but not derived from) that User class: CreateUser, EditUser, and DetailsUser. Each contains View-specific DataAnnotations (Required, DataType, etc.).</p>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T17:17:10.160",
"Id": "14752",
"Score": "31",
"Tags": [
"c#",
"asp.net-mvc-3"
],
"Title": "Separating Models and ViewModels"
} | 14752 |
<p>This is a slightly specialised A* algorithm, basically it allows you to search to and from disabled nodes. It's for a game and we the entities spawn in houses and go into them. The rest of the search behaves normally, it doesn't traverse any disabled nodes in between the start and end points.</p>
<p>NavData is a cl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T18:01:13.927",
"Id": "23989",
"Score": "0",
"body": "if it would be helpful I'll happily share the class that instantiates the data structures the search uses."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "201... | [
{
"body": "<p>There are a few things you could do here.</p>\n\n<p>A common optimization is to break ties towards smaller h-values. See <a href=\"http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html#breaking-ties\" rel=\"nofollow noreferrer\">here</a>. This will cause your pathfinder to try the mo... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T18:00:33.087",
"Id": "14753",
"Score": "3",
"Tags": [
"c#",
"lookup",
"pathfinding"
],
"Title": "How can I make my A* algorithm faster?"
} | 14753 |
<p>I have created a class for reading data from an Excel sheet and holding on the variable. I am not sure if my code is optimized, meaning I will be reading heavily from Excel.</p>
<p>Is there a room to further optimized this code? I will be using this class heaving in my code, and I wanted to get some opinions/feed... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T21:12:40.507",
"Id": "23994",
"Score": "1",
"body": "Do you HAVE to read from Excel? Reading from a CSV file is a lot easier. Where does this data in Excel come from? It would help if the source Excel had named ranges. Also, you do ... | [
{
"body": "<p>Variable names make sense, except the r one.</p>\n\n<p>Good use of white space and tabs.</p>\n\n<p>I'm not sure if this can be optimized any more, but I do notice this method will not work</p>\n\n<pre><code>private string ExcelScanIntenal(Workbook workBookIn, string sheetName)\n{\n Worksheet sh... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T20:10:18.630",
"Id": "14756",
"Score": "5",
"Tags": [
"c#",
"optimization",
"excel"
],
"Title": "Reading from an Excel sheet"
} | 14756 |
<p>I'm working an <a href="http://www.groovyexamples.org/2010/05/03/list-all-files-in-a-directory/" rel="nofollow">example to list directory contents</a>. When I process each directory the code works. Now I'd like to put both directories in an array and iterate the array. I get an error when I declare 'dir_c' because I... | [] | [
{
"body": "<p>Do you mean like this:</p>\n\n<pre><code>def searchDir = [\"z:/pathA/pathB\",\"z:/pathA/pathQ\"]\nsearchDir.each { d ->\n new File( d ).eachFile {\n if (it.isFile()) {\n outfile.append( \"$it.name\\n\" )\n }\n }\n}\n</code></pre>\n",
"comments": [],
"meta_... | {
"AcceptedAnswerId": "14760",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-16T20:19:25.710",
"Id": "14757",
"Score": "0",
"Tags": [
"groovy"
],
"Title": "How can use array to imitate repeated individual instances?"
} | 14757 |
<p>I need to solve this problem in Python 3 (within 3 sec):</p>
<blockquote>
<p><code>A</code> is a given (NxM) rectangle, filled with characters "a" to "z".
Start from <code>A[1][1]</code> to <code>A[N][M]</code> collect all character which is only
one in its row and column, print them as a string.</p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T19:21:32.937",
"Id": "24060",
"Score": "4",
"body": "Not an observation about optimization, but why aren't you using [PEP8 guidelines](http://www.python.org/dev/peps/pep-0008/) to write your code? It's not a dealbreaker by any means... | [
{
"body": "<p>I would suggest to create a 1000x1000 testcase and measure the performance before the optimization process. Please use the following test generator:</p>\n\n<pre><code>import os\nimport random\n\nf = open('1000x1000.in','w')\nf.write('1000 1000\\n')\nALPHABET = 'abcdefghijklmnopqrstuvwxyz'\nfor _ i... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T04:54:45.727",
"Id": "14766",
"Score": "5",
"Tags": [
"python",
"performance"
],
"Title": "Printing characters in a matrix as a string"
} | 14766 |
<p>I have to display a menu where some buttons have dropdown submenus and show if the current button is active or not and put a CSS class to it for each of the two situations (or in both).</p>
<pre><code><?php
$menus_array = array(
array('item1', false),
array('item2', true),
array('item3', false)
);
... | [] | [
{
"body": "<p>A few things first:</p>\n\n<ul>\n<li><code>$menu_item == $active_item</code> should probably be <code>$menu_item[0] == $active_item</code></li>\n<li>Depending on where that array is coming from, it should probably be associative. Imagine if you came across the code out of context. You'd quickly ... | {
"AcceptedAnswerId": "14772",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T09:11:36.470",
"Id": "14769",
"Score": "1",
"Tags": [
"php"
],
"Title": "Showing a menu with buttons with dropdown submenus"
} | 14769 |
<p>I had previously asked <a href="https://stackoverflow.com/q/11851147/250725">this question</a> on SO. The answer pointed me towards using the task parallel library for multiple parallel downloads. I'm not actually utilizing this exact code, but it got me to rethink my design.</p>
<p>The one open issue that wasn't... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T11:52:41.120",
"Id": "24020",
"Score": "1",
"body": "Why are you trying to avoid using a field? That's exactly what they're for: storing objects that are needed for more than just one method call."
},
{
"ContentLicense": "CC... | [
{
"body": "<p>I am not able to comment on your post due to a lack of reputation, but when I did something similar to this, I used a <a href=\"https://msdn.microsoft.com/en-us/library/system.threading.cancellationtoken(v=vs.100).aspx\" rel=\"nofollow noreferrer\"><code>CancellationToken</code></a>. It's been aro... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T09:45:30.393",
"Id": "14771",
"Score": "2",
"Tags": [
"c#",
"asynchronous"
],
"Title": "Cancelling Local WebClient ASync Operation"
} | 14771 |
<p>I am trying to write a simple (trivial?) "compare" program for Eclipse preferences files.</p>
<p>Eclipse preferences files take more of less this form:</p>
<blockquote>
<pre><code># optional comment line
/a/sequence/of/path/elements=string
/another/sequence/of/path/elements=42
# ... (possibly repeated)
</code></pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T03:52:44.607",
"Id": "24014",
"Score": "0",
"body": "Where's the profiler output?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T03:53:13.997",
"Id": "24015",
"Score": "0",
"body": "I don... | [
{
"body": "<p>Don't optimize unless your profiler says so.</p>\n\n<p>You could start with the simplest code that works e.g., here's a straightforward translation of your requirements: </p>\n\n<pre><code>import sys\n\ndef get_entries(filename):\n with open(filename) as file:\n # extract 'key = value' e... | {
"AcceptedAnswerId": "14775",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T03:50:55.487",
"Id": "14774",
"Score": "4",
"Tags": [
"python",
"parsing",
"eclipse"
],
"Title": "\"Compare\" program for Eclipse preference files"
} | 14774 |
<p>This is a solution to the problem: <a href="http://webcache.googleusercontent.com/search?q=cache%3a-RiwllI4gAsJ%3auva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2146%20&cd=1&hl=da&ct=clnk&gl=dk" rel="nofollow">"The Broken Pedometer"</a> on the UVA online judge. (No... | [] | [
{
"body": "<p>Just some hints to improve your C++ code if not the algorithm logic:</p>\n\n<ul>\n<li>Use const references for passing big objects like vectors to functions. For example, replace <code>vector<string> leds</code> by <code>const vector<string>& leds</code> in <code>any_duplicates</co... | {
"AcceptedAnswerId": "14785",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T12:03:35.760",
"Id": "14777",
"Score": "2",
"Tags": [
"c++",
"algorithm"
],
"Title": "\"The broken pedometer\" optimizations"
} | 14777 |
<p>I created a Matrix class. I tested it and it seems to work.</p>
<ol>
<li>Can someone tell me if this class is good?</li>
<li>Can I improve it?</li>
<li>Can I use more move semantics (where)? What do I have to modify?</li>
<li>Are there some logic/programming errors?</li>
</ol>
<p></p>
<pre><code>#ifndef MATRIX_H... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T15:15:23.540",
"Id": "24033",
"Score": "0",
"body": "i would rename get_row() to get_row_size(). I would expect a method called `get_row` to take an index and return a row vector if this index is between 0 and the row size"
}
] | [
{
"body": "<p>I would make several improvements.</p>\n\n<p>I really don't like the fact that the interface has no names on parameters. You can skip all the names you want on the definitions, but when I look at a declaration I want to know what the parameters are.</p>\n\n<p>Still on the interface part, I'd renam... | {
"AcceptedAnswerId": "14786",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T15:00:59.603",
"Id": "14784",
"Score": "3",
"Tags": [
"c++",
"optimization",
"matrix"
],
"Title": "Templated Matrix class"
} | 14784 |
<p>I've created the below script and would appreciate any feedback. </p>
<pre><code># svn directory ^/tags/release/
# 1/
# 2/
# 3/
# 4/
# usage: svnnextrelease fixes email formatting
# generated line: svn cp ^/trunk ^/tags/release/# -m'fixes email formatting'
function svnnextrelease(){
NextVersion=$(svn ls ^/tags/re... | [] | [
{
"body": "<p>Here is a small improvement.</p>\n\n<pre><code>svnnextrelease() {\n v=$(svn ls ^/tags/release | tail -n 1)\n svn cp ^/trunk ^/tags/release/$((${v%/} + 1 )) -m \"$@\"\n}\n</code></pre>\n\n<ul>\n<li>You can use $(( )) as a replacement for expr in bash. (depends on your taste.)</li>\n<li>bash can c... | {
"AcceptedAnswerId": "14811",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T15:38:00.943",
"Id": "14789",
"Score": "3",
"Tags": [
"bash",
"svn"
],
"Title": "Bash function to create the next SVN release tag"
} | 14789 |
<p>I am never to sure when it comes to <code>ifstream</code> and reading lines. I am often confused with the <code>good()</code>, <code>bad()</code>, <code>eof()</code> and so on.</p>
<p>Could anyone tell me if I am doing it right?</p>
<pre><code>int parseLine(std::ifstream & _file)
{
while( std::getline( _f... | [] | [
{
"body": "<p>Too complicated. Just say:</p>\n\n<pre><code>for (std::string line; std::getline(_file, line); )\n{\n // process \"line\"\n}\n</code></pre>\n\n<p>The function <code>std::getline</code>, like most iostreams operations, returns a reference to the stream object itself, which can be evaluated in a ... | {
"AcceptedAnswerId": "14792",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T15:40:30.407",
"Id": "14790",
"Score": "3",
"Tags": [
"c++",
"parsing"
],
"Title": "Is this the right way to read every line?"
} | 14790 |
<p>I've noticed a tendency towards two styles of conditionally executing methods:</p>
<ol>
<li><p>Conditional before the call</p>
<pre><code>def foo(thing)
puts thing
end
if thing
foo(thing)
end
</code></pre></li>
<li><p>Conditional within the call</p>
<pre><code>def foo(thing)
return unless thing
puts thin... | [] | [
{
"body": "<p>I think that one of the pros you listed for style 2 - \"Conditional is centralized in one location and not duplicated\" is sufficient all by itself to tip the scale to style 2.</p>\n\n<p>Non-duplication of code is a very powerful idea, particularly in a system under development. There is always th... | {
"AcceptedAnswerId": "14798",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T16:33:27.203",
"Id": "14791",
"Score": "4",
"Tags": [
"ruby"
],
"Title": "Placement of Conditionals"
} | 14791 |
<p>I'm having trouble thinking of a good name for the following extension method:</p>
<pre><code>public static IEnumerable<T> TrimOrExpand<T>(this T[] items, int desiredCount)
{
var ratio = (double)items.Length / desiredCount;
for (int i = 0; i < desiredCount; i++)
yield return items[Con... | [] | [
{
"body": "<p>I think if you look at the objects within the IEnumerable as a statistical numeric value than you could use the term <a href=\"http://en.wikipedia.org/wiki/Normalization_%28statistics%29\" rel=\"nofollow\">Normalize</a>. In this case you are \"normalizing\" your values (objects) to a desired count... | {
"AcceptedAnswerId": "14804",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T19:13:13.047",
"Id": "14800",
"Score": "2",
"Tags": [
"c#",
"extension-methods"
],
"Title": "Filtering or repeating elements as needed"
} | 14800 |
<p>A prospective employer asked me for a code sample, but unfortunately this is the best project I've done, most of my other programs were very short (~100 lines). Should I send this in/try to refactor it? Or would it be best to send a shorter sample, or quickly write a new project?</p>
<pre><code>#!/usr/bin/python
... | [] | [
{
"body": "<p>I have little experience with python, so I can't offer critique on the finer points of your code, just the big picture. That said, several things stick out to me. </p>\n\n<p>First, you have some large chunks which are duplicated two, three, or even four times (see lines 198-215). Scour through the... | {
"AcceptedAnswerId": "14806",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T19:40:13.973",
"Id": "14801",
"Score": "4",
"Tags": [
"python",
"interview-questions"
],
"Title": "Is this code too messy to send to an employer as a code sample?"
} | 14801 |
<p>I would really appreciate any feedback on the back-end of my mobile application.
I tried to keep an MVC pattern, where I considered the app to be my view.
Perhaps an REST framework would have been good to use, but for now I am not attempting cross domain requests.</p>
<p><strong>Controller</strong></p>
<p>The Grou... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-20T08:41:55.507",
"Id": "24139",
"Score": "0",
"body": "It looks pretty good to me. Like you said, i'd convert to PDO for my database."
}
] | [
{
"body": "<p>If you want to apply the MVC pattern then you should learn the main <strong>OO</strong> principles (<strong>SOLID</strong> is a great word for this). The actual state of your code smells. <strong>Global</strong> variables half OO and half <strong>procedural</strong> style and you are creating <str... | {
"AcceptedAnswerId": "14909",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T23:48:57.010",
"Id": "14809",
"Score": "1",
"Tags": [
"php",
"object-oriented",
"mvc",
"json"
],
"Title": "PHP backend for an HTML5/JS mobile app"
} | 14809 |
<p>This is a function that checks that when users register into the site, they only create one single account per email. The little twist is that <strong>all emails in the DB are hashed with unique salts</strong> (=<em>Input2</em>). Because <strong>hashing the new mail input with all unique salts</strong> (=<em>STEP 2<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-18T09:11:42.413",
"Id": "24085",
"Score": "1",
"body": "Why would you hash the email? If you need the email in plain text, just keep the email in plain text. Emails aren't particularly sensitive information."
},
{
"ContentLic... | [
{
"body": "<p>I have to agree with Corbin, while I would be annoyed if my email address got leaked, I would not be overly concerned. Spam filters are pretty decent now, and without a password all they can do is spam me. Or, if I have a gmail account, WoW hackers can find more loopholes that allows them to spam ... | {
"AcceptedAnswerId": "14878",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-18T09:10:31.523",
"Id": "14814",
"Score": "2",
"Tags": [
"php",
"performance",
"sql",
"email"
],
"Title": "Single-account-per-email verification"
} | 14814 |
<p>This is part of the code from a spectral subtraction algorithm. I'm trying to optimize it for Android.</p>
<p><strong>Matlab code:</strong></p>
<pre><code>function Seg=segment(signal,W,SP,Window)
% SEGMENT chops a signal to overlapping windowed segments
% A= SEGMENT(X,W,SP,WIN) returns a matrix which its columns... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-24T13:09:12.063",
"Id": "24377",
"Score": "0",
"body": "you could start by flattening your `double[][]` to `double[]`. If every little bit counts, there's some RAM and speed you can gain by it."
},
{
"ContentLicense": "CC BY-SA... | [
{
"body": "<p>I don't have a clue about spectral subtraction, so just some minor, general notes about code:</p>\n\n<ol>\n<li><blockquote>\n<pre><code>public int fix(double val) {\n if (val < 0) {\n return (int) Math.ceil(val);\n }\n return (int) Math.floor(val);\n}\n</code></pre>\n</blockquot... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-18T10:21:23.987",
"Id": "14815",
"Score": "7",
"Tags": [
"java",
"optimization",
"android",
"mathematics",
"matrix"
],
"Title": "Optimizing code from spectral subtraction alg... | 14815 |
<p>I have the two functions that calculate whether or not a given coordinate (x, y) is a diagonal or anti-diagonal of another coordinate that is a power of 2. In other words if (x+/-k, y+/-k) == (cx, cy) where cx or cy is a power of 2, then the binary representation of (x+/-k, y+/-k) follows known patterns.</p>
<ul>
<... | [] | [
{
"body": "<p>The patterns I see are probably better produced by bit-shifting than by hard-coding:</p>\n\n<pre><code> ...\n bytes = number.ToByteArray();\n foreach (byte b in bytes)\n {\n byte temp = 0;\n if (moreOnesPossible)\n {\n whi... | {
"AcceptedAnswerId": "14818",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T21:21:43.360",
"Id": "14817",
"Score": "4",
"Tags": [
"c#",
"performance",
".net"
],
"Title": "Optimizing function that searches for binary patterns"
} | 14817 |
<p>Fairly new to jquery, can i improve this code please?</p>
<h2>HTML</h2>
<pre><code><a href="#" class="dialog" id="login">login</a>
</code></pre>
<h2>Javascript</h2>
<pre><code>function Dialog() {
// Event handler for a dialog click.
$('a.dialog').click(function () {
var dialog = $("... | [] | [
{
"body": "<ul>\n<li><p>In JavaScript it is custom to give functions names that start with a lowercase letter so that they are not confused with objects.</p></li>\n<li><p>Personally I'd avoid \"hardcoding\" the connection of the id of the link with the id of the dialog. (<code>login</code> -> <code>login_dialog... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-19T09:01:07.163",
"Id": "14826",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Can I improve my jquery dialog code, critisicm welcome"
} | 14826 |
<p>Here's the exercise:</p>
<blockquote>
<p>Given a string of X's and O's and a maximum number of swaps, determine
the longest possible sequence of X's after swaps.</p>
</blockquote>
<p>Here's my solution using itertools.</p>
<pre><code>import itertools as iter
def swaps_gen(s):
'''This generator yields all... | [] | [
{
"body": "<pre><code>import itertools as iter\n</code></pre>\n\n<p>I dislike abbrevations like this. Itertools is widely used within the python community, and it only hinders code readability by using <code>iter</code> instead of <code>itertools</code></p>\n\n<pre><code>def swaps_gen(s):\n '''This generator... | {
"AcceptedAnswerId": "14830",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-19T10:01:52.837",
"Id": "14827",
"Score": "0",
"Tags": [
"python"
],
"Title": "Criticize my first attempt at using the itertools module"
} | 14827 |
<p>I wrote a program to take a list of letters and from every permutation of them and check that against the dictionary and print out valid words. The constraints are that there is a control letter which means that letter must be in the word, and you can't repeat any letters.</p>
<p>Everything works, but the running ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-08T14:32:15.810",
"Id": "99399",
"Score": "0",
"body": "This is a good question, thank you for taking the time to form it so that we can help show you the proper coding styles and techniques. We all look forward to seeing more of your ... | [
{
"body": "<pre><code>import itertools\nfrom multiprocessing import Process, Manager\n\ndictionary_file = '/usr/share/dict/words'\nletter_list = ['t','b','a','n','e','a','c','r','o']\ncontrol_letter = 'e'\n</code></pre>\n\n<p>By convention, global constant should be named in ALL_CAPS</p>\n\n<pre><code>manager =... | {
"AcceptedAnswerId": "14831",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-19T11:48:10.010",
"Id": "14828",
"Score": "6",
"Tags": [
"python",
"combinatorics"
],
"Title": "Generating words based on a list of letters"
} | 14828 |
<p>I was looking for a PHP class to handle all database operations (MySQL) and came across the following class. Someone please help me telling if this uses Prepared Statements correctly to make my web app safe from SQL injection.</p>
<pre><code>class db extends PDO {
private $error;
private $sql;
private $bind;
privat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T14:16:17.630",
"Id": "24207",
"Score": "0",
"body": "I am using this as well...i was wondering the same thing.... but I know that the PDO class has a $pdo->quote function that you can use to escape stuff... but the class is good as ... | [
{
"body": "<p>Seams to me safe but it's not easy to use. You can create somthing similar to the insert logic for the update (your are naming twice your parameters). In you constructor there is no reason to use that try-catch block and this is true for your debug mathod it is unnecessary with the try-catch block... | {
"AcceptedAnswerId": "14849",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-19T16:00:27.277",
"Id": "14832",
"Score": "2",
"Tags": [
"php",
"mysql",
"security"
],
"Title": "Database class for handling operations"
} | 14832 |
<p>I created script that generates maze or some kind of dungeons that looks like this:
<a href="http://s13.postimage.org/4uify3jxj/blocks.jpg" rel="nofollow">http://s13.postimage.org/4uify3jxj/blocks.jpg</a></p>
<p>I have problem with optimize, because when I've tried to add blockade to not overwrite existing blocks, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-19T17:04:11.147",
"Id": "25610",
"Score": "1",
"body": "The first part of your question (\"how do I optimize this\") was on-topic. The rest of the question (\"how to I add this functionality\") was off-topic. Questions can be re-opened... | [
{
"body": "<p>Begin your optimizations by not having classes for the sake of having a class. For instance, <code>dungeon_block</code> is not a class. You made it one, but nothing about it says that it is one. Its just a glorified data repository. OOP does not just mean instantiating a class, there's more to it.... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-19T17:09:50.497",
"Id": "14833",
"Score": "0",
"Tags": [
"php",
"html",
"php5"
],
"Title": "Optimizing blocks-maze generation script php"
} | 14833 |
<p>I have written an implementation of the observer pattern that allows messages to be passed to listeners in what would normally be the <code>notify()</code> method. For example a subscriber sub-class might look like the pseudo-code below, where <code>Message</code> is a simple class that can be subclassed and made to... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-20T19:54:09.030",
"Id": "24132",
"Score": "0",
"body": "You have some double checks: checking for type and the value of a string. I'd suggest using an enum and forget about the type checking, since everything appears to be a message in... | [
{
"body": "<p>Personally I prefer <a href=\"http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism\" rel=\"nofollow\">polymorphism instead of conditions</a> in such cases, as it helps to keep big conditions in a clean fashion - each condition in it's own class. As an example, in .NET they hav... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-19T17:13:45.627",
"Id": "14834",
"Score": "2",
"Tags": [
"java",
"callback"
],
"Title": "Allowing messages to be passed to listeners"
} | 14834 |
<p>I was hoping I could get some of you to look over a program I wrote. I am just beginning to learn about Python (for the last month or so). Therefore, I may not be aware of techniques that would make this program better. Currently I'm studying Python 2.7. Any advice or suggestions you could provide would be appreciat... | [] | [
{
"body": "<p>Here's a step by step Pythonization walk-trough.</p>\n\n<h2>Trivial simplifications</h2>\n\n<p>Before:</p>\n\n<pre><code>answer_total = float(right_answer_total + wrong_answer_total)\npercentage = 100 * (float(right_answer_total) / float(answer_total)) \n</code></pre>\n\n<p>After:</p>\n\n<pre><cod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-19T20:50:45.567",
"Id": "14838",
"Score": "3",
"Tags": [
"python",
"python-2.x"
],
"Title": "Multiple Choice Quiz with Stat Tracking"
} | 14838 |
<p>This code works fine but is way to bulky for my liking. Is there a better way to go about filtering classes and adding a style to them?</p>
<pre><code> $('.leftNav li a').click(function() {
$('.leftNav li a').removeClass('active');
$(this).addClass('active');
$('span.... | [] | [
{
"body": "<p>You have a ton of duplicate code. You can easily extract a common function out, and determine what is variable. This will give you something a little more manageable like the following:</p>\n\n<pre><code>var setup = function(filter, overlayFilter){\n $('.leftNav li a' + filter).click(function()... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-20T11:08:07.557",
"Id": "14850",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Filtering classes with jQuery"
} | 14850 |
<p>Base functionality:</p>
<ol>
<li>Reading a CSV file and inserting in database after replacing values with web macro.</li>
<li><p>Reading values from CSV @ first header information NO,NAME next to that, then read one by one values from CSV and put into web macro context like below:</p>
<pre><code>context.put("1","R... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-22T13:32:42.783",
"Id": "24244",
"Score": "0",
"body": "The way this question is worded, it is hard to follow exactly what you are asking. Also, the indentation of the code is not correct, and this is making it hard to understand."
}... | [
{
"body": "<p>It appears that you are reading records from a file, processing them in some way and then using the processed data to insert records into a table. Some of the processing involves getting data out of the database.</p>\n\n<p>It looks like you are creating one insert statement for each row from the s... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-20T17:25:03.300",
"Id": "14866",
"Score": "2",
"Tags": [
"java",
"performance",
"csv",
"oracle"
],
"Title": "Merging CSV data into database"
} | 14866 |
<p>It's based on the <a href="http://en.wikipedia.org/wiki/Hardy%E2%80%93Weinberg_principle" rel="nofollow">Hardy-Weinberg formula</a>. I used the easygui module because I don't fully understand events in Tkinter yet. It's my first relatively useful script so any constructive criticism would be helpful.</p>
<pre><code... | [] | [
{
"body": "<p>Some suggestions:</p>\n\n<ul>\n<li>call variables <code>this_way</code> not <code>thisWay</code></li>\n<li>use less comments</li>\n<li>put your interaction with user into separate functions</li>\n<li>if code will be splited properly you will be able to user <code>return</code> and <code>while True... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-20T19:08:26.163",
"Id": "14869",
"Score": "2",
"Tags": [
"python"
],
"Title": "A simple calculator to calculate the frequency of a recessive allele"
} | 14869 |
<p>I'm trying to clean up this function to target individual <code>#hdid</code>. I'm also using <code>$this</code>, but with no success. </p>
<pre><code><script>
$(function() {
$(".delete").click(function() {
$('#load').fadeIn();
var commentContainer = $(this).... | [] | [
{
"body": "<p>If you refactor your code a bit you can do it this way. I'm also making the assumption that you mean <code>.hdid</code> instead of <code>#hdid</code> there should only be one hdid per page if it's really an ID and not a CLASS. <a href=\"http://jsfiddle.net/p5dTt/1/\" rel=\"nofollow\">Here's</a> a ... | {
"AcceptedAnswerId": "14883",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-20T21:08:29.863",
"Id": "14872",
"Score": "0",
"Tags": [
"javascript",
"jquery"
],
"Title": "jQuery to target each #hdid"
} | 14872 |
<p>The goal is to solve an ODE numerically with forward Euler method. The programs works well (numerical solution really near analytical one). The problem I see is that the Euler scheme don't jump to eyes, probably because of <code>push_back()</code> functions. This approach is the only one I found to let the time of s... | [] | [
{
"body": "<p>The smallest change that might make it more readable is to <code>resize</code> the vectors first, so you can index the elements rather than calling <code>push_back</code>.</p>\n\n<p>It's generally a good idea to <code>reserve</code> vectors before a loop anyway if you know how big they're going to... | {
"AcceptedAnswerId": "14889",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-20T21:48:36.793",
"Id": "14877",
"Score": "3",
"Tags": [
"c++",
"c++11",
"numerical-methods",
"physics"
],
"Title": "Solving an ODE numerically with forward Euler method"
} | 14877 |
<p>I wrote the following code to test a score-keeping class. The idea was to keep score of a game such that the score was kept across multiple classes and methods. </p>
<p>I'm looking for any input on being more efficient, more 'pythonic' and/or just better.</p>
<pre><code>import os
class Foo():
def __init__(se... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T13:41:33.970",
"Id": "24154",
"Score": "0",
"body": "Like Matt, I can't really tell what you're trying to achieve: this code is obviously incomplete (there are several references to a `foo` that is never declared), and seems far fro... | [
{
"body": "<p>I'm confused on what you are trying to achieve with the code example above, but in general it's usually a bad idea to modify the instance fields of a class from outside of that class. So updating foo.stored_end from another class directly (versus creating a method in foo that takes the new value a... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T03:30:05.403",
"Id": "14881",
"Score": "1",
"Tags": [
"python",
"classes"
],
"Title": "Python: keeping track of info across classes by storing a variable to self"
} | 14881 |
<p>I have been trying to optimize the filtering process of a <code>Collection<Alert></code> based on the <code>DateTime GeneratedOn</code> property of <code>Alert</code> class.</p>
<p>Below is the code block which filters the <code>List</code> by taking in <code>From Date</code> and <code>To Date</code>.</p>
<p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T10:28:55.797",
"Id": "24145",
"Score": "0",
"body": "You mean you're trying to make this code faster? Did profiling tell you this code is really a bottleneck in your application?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<p><strong>Why are you storing <code>FromDate</code> and <code>FromTime</code> seperately to begin with?</strong></p>\n\n<p>Instead of storing using four properties, use only two, storing both Date and TimeOfDay inside them:</p>\n\n<pre><code>public DateTime FromAlert { get; private set; }\npublic Da... | {
"AcceptedAnswerId": "14935",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T07:54:49.397",
"Id": "14886",
"Score": "2",
"Tags": [
"c#",
"optimization",
"linq",
"datetime"
],
"Title": "DateTime filter"
} | 14886 |
<p>I have written a parser function that returns a JQuery Promise. You can see from the code that this is the top level parser and it delegates out to two other more specific parsers.</p>
<p>At the minute it feels a little scattered about with the promise being rejected and resolved all over the place. perhaps it wo... | [] | [
{
"body": "<p>Chop up functions longer than 12 lines of code into smaller functions.\nSince you're using <code>this</code>, then you can attach the additional functions to the prototype on <code>Parser</code>.</p>\n\n<p>Here's what I came up with.</p>\n\n<pre><code>function Parser(json) {\n var dfd = $.Defer... | {
"AcceptedAnswerId": "15326",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T10:24:44.650",
"Id": "14890",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"parsing",
"json"
],
"Title": "JQuery Promise Interface for a (very) simple JSON Parser"
} | 14890 |
<p>I have two code examples that I wrote for best practices encrypting a string that I'm looking for feedback both in terms of best practices and security. They are both using <a href="http://en.wikipedia.org/wiki/Authenticated_encryption">authenticated encryption</a>. One is using the <a href="http://www.bouncycastle... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T14:15:33.153",
"Id": "24169",
"Score": "14",
"body": "As far as best practices go, I see a few offhand: 1. `static public XXX` is idiomatically written as `public static XXX`. 2. Since all your methods are `static`, the class should... | [
{
"body": "<p>As far as best practices go, I see a few offhand:</p>\n\n<ol>\n<li><code>static public XXX</code> is idiomatically written as <code>public static XXX</code>. </li>\n<li>Since all your methods are <code>static</code>, the class should be made <code>static</code> as well to prevent (useless) instanc... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T12:54:57.017",
"Id": "14892",
"Score": "53",
"Tags": [
"c#",
"security",
"cryptography",
"aes"
],
"Title": "Simplified secure encryption of a String"
} | 14892 |
<p>I want to search a DB table and display the records in a gridview below is my stored proc</p>
<pre><code> create procedure search
@Firstname varchar (50),
@Lastname varchar (50),
@Gender varchar (10),
@Maritalstatus varchar (20),
@Height varchar (30),
@Complexion varc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T12:49:02.557",
"Id": "24156",
"Score": "0",
"body": "Well, one thing is that Connection, Command and DataTable aren't being disposed. You might find that codereview.stackexchange is better suited toward style and best practice type ... | [
{
"body": "<p>if you want assign your textbox</p>\n\n<pre><code>void Btn_Click(Object sender, EventArgs e)\n{\n\n string fname = YourTextBoxName.Text.Trim();\n string emailid =YourTextBoxEmail.Text.Trim(); \n\n //Call bll.Search\n //Bind your grid\n\n}\n</code></pre>\n\n<p>You can use optinal param... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T12:45:03.693",
"Id": "14896",
"Score": "3",
"Tags": [
"c#",
"asp.net",
"sql-server"
],
"Title": "Search using stored procedure"
} | 14896 |
<p>Let's say I want to parse audio track information into two variables like this:</p>
<ul>
<li><code>'2/15'</code> -> <code>track = 2, num_tracks = 15</code></li>
<li><code>'7'</code> -> <code>track = 7, num_tracks = None</code></li>
</ul>
<p>What's an elegant way to do this in Python? For example:</p>
<pre><code>t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T07:34:41.070",
"Id": "24173",
"Score": "3",
"body": "Don't use a bare `except` though; catch specific exceptions only. You'd be amazed how many bugs could be masked by blanket `except` statements."
}
] | [
{
"body": "<p>This may be overly generic, but could be reused. It \"pads\" a sequence by making it long enough to fit the requested length, adding as many repetitions as necessary of a given padding item.</p>\n\n<pre><code>def right_pad(length, seq, padding_item=None):\n missing_items = length - len(seq)\n ... | {
"AcceptedAnswerId": "14907",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T03:26:11.547",
"Id": "14901",
"Score": "32",
"Tags": [
"python",
"parsing",
"error-handling",
"null"
],
"Title": "Using default None values in Python when assigning split()... | 14901 |
<p>I cannot quite see all the advantages of OOP PHP. I have already started translating some procedural functions into object oriented. How is the second code better than the first one? Is there anything I am missing? Could it be improved? It is surely a newbie question but I'm starting now with the Object Oriented asp... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-23T14:13:42.827",
"Id": "24336",
"Score": "0",
"body": "See the update in my answer for some of the answers to your questions from the comments. In the future only use one name per comment, or if the comment is on the answer of someone... | [
{
"body": "<p>When you have just 1 class, it doesn't really come into perspective...the fact that you're modularizing your code is one of the many bonuses of OOP. Here's your code, cleaned up, with an added Database class:</p>\n\n<pre><code>class DB{\n private $query; \n\n public function __construct(){}\... | {
"AcceptedAnswerId": "14921",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T16:12:15.460",
"Id": "14905",
"Score": "2",
"Tags": [
"php",
"object-oriented"
],
"Title": "OOP PHP with language detection"
} | 14905 |
<p>I'm working on a battery indicator feature in my app, and I was wondering if there is a better way than what I am doing to check what image should be displayed when. I am currently using <code>if</code> statements, but I was wondering if case statements would be a better option.</p>
<pre><code>- (void)observeValue... | [] | [
{
"body": "<p>I think this code is easier to read and should result in significantly less comparisons, as it just compares in every step the lower bound, where as your define macro checks twice each. And note that you are checking also equality. this should result into </p>\n\n<ol>\n<li>at least 2 checks at cpu... | {
"AcceptedAnswerId": "15897",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T19:35:17.450",
"Id": "14911",
"Score": "3",
"Tags": [
"objective-c"
],
"Title": "Showing an image based on the battery level"
} | 14911 |
<p>What would be the best (performance, memory wise) to achieve a clean way to create a class or some way to properly structure the code, that shares 2 variables (req, res) which have a decent object size.</p>
<p>And yes, for those who use <code>Node.js</code> it are the <code>req</code> and <code>res</code> variables... | [] | [
{
"body": "<p>Note: I assumed the Client function would be used a constructor, e.g.</p>\n\n<pre><code>var clientInstance = new Client();\nclientInstance.req;//access req\n</code></pre>\n\n<p>I think I may have been wrong about that.</p>\n\n<p>Objects are passed via reference, so they shouldn't be taking up more... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-21T20:27:48.883",
"Id": "14912",
"Score": "2",
"Tags": [
"javascript",
"object-oriented",
"url-routing"
],
"Title": "Structuring code to do URL routing for Node.js"
} | 14912 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.