body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I'm using the repository pattern with a context and ninject as the IOC. I have a service which handles getting and setting page properties in the database.</p> <pre><code>public class MyContext : DbContext { public MyContext() : base ("DefaultConnection") { } public DbSet&lt;PageProperty&gt; PagePr...
[]
[ { "body": "<p>I don't think I completely know what is going on in your code.</p>\n\n<p>but there is one thing that I think you are doing wrong.</p>\n\n<p>you are creating a connection over the web and trying to force it to stay open.</p>\n\n<p>your web application should </p>\n\n<ol>\n<li>Connect</li>\n<li>Send...
{ "AcceptedAnswerId": "33615", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T14:59:36.677", "Id": "30082", "Score": "3", "Tags": [ "c#", "asp.net", "asp.net-mvc-4", "dependency-injection" ], "Title": "Multiple Ajax Requests per MVC 4 View" }
30082
<p>I have written a working code that generates a simple linked list of dates and associated holidays. I realize that I have a problem with memory leaking as I copy lists repeatedly, so I wrote a freeList function. I am just having issues determining where to place this function. </p> <pre><code>//Creates a linked lis...
[]
[ { "body": "<p>In your current code, I can't see the copying of lists repeatedly as you stated. You are using pointers here so you're not actually duplicating the list.</p>\n\n<p>The freeList function should be called once you're done using your list (the one returned by <code>holidayList()</code>).</p>\n\n<p><e...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T15:40:44.767", "Id": "30087", "Score": "1", "Tags": [ "c", "memory-management", "linked-list" ], "Title": "Working C code dealing with lists: problem with memory leak" }
30087
<p>I made this function to teach myself about hash tables. Any ideas? I commented out <code>free(addition)</code> because it was giving me a compiler error, but I need to figure out how to deallocate the memory. </p> <pre><code>#define hashSize 1000 typedef struct hashElem{ char* date; char* holiday; }hashEle...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T06:49:25.083", "Id": "47826", "Score": "1", "body": "Is the question how to deallocate memory?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T11:41:48.520", "Id": "47834", "Score": "0", "...
[ { "body": "<p>For one thing, this:</p>\n\n<pre><code> // Add holiday to Hash Table\n if (hashTable[murmurHash(key, strlen(key))] == NULL)\n { \n addition-&gt;next = NULL;\n hashTable[murmurHash(key, strlen(key))] = addition; \n }\n else //If there is already an element at the index, ad...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T18:41:53.407", "Id": "30096", "Score": "5", "Tags": [ "c", "memory-management", "hash-map" ], "Title": "Hash Table: adding and finding functions" }
30096
<p>I made a small Vim distribution that uses vundle. I decided to make a small function that checks if the repository must be updated.</p> <pre><code>"""""""""""""""""""""""""""""""""""""""""""""""""" "Update the repository """""""""""""""""""""""""""""""""""""""""""""""""" "A function to update if necessary function!...
[]
[ { "body": "<p>Your function has the side-effect of switching the directory to the file's path. To be side-effect-free, you should <code>let l:current_path = getcwd()</code> instead. Better yet, use the <code>--git-dir</code> and <code>--work-tree</code> options to <a href=\"https://www.kernel.org/pub/software...
{ "AcceptedAnswerId": "30114", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T19:24:05.997", "Id": "30097", "Score": "2", "Tags": [ "shell", "git", "vimscript" ], "Title": "Checking if a git repository needs to be updated" }
30097
<p>The below code uses Promises/A+ (specifically <a href="https://github.com/tildeio/rsvp.js" rel="nofollow">rsvp.js</a>) to generate a token. It does so by either taking an existing token or downloading and parsing a token from a web page. Is it possible to chain this to LoadURIPromise more cleanly? Usually one can ...
[]
[ { "body": "<p>I'm not familiar with the RSVP.js library. <a href=\"http://jsfiddle.net/zkfur/\" rel=\"nofollow\">I use jQuery here</a>, but the overall concept should still be (or exactly) the same:</p>\n\n<pre><code>// You can pull out your config to an array and use apply to use them\nvar config = [\n '/root...
{ "AcceptedAnswerId": "30267", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T20:45:44.167", "Id": "30102", "Score": "1", "Tags": [ "javascript", "promise" ], "Title": "Can this promise be chained more cleanly?" }
30102
<p>It has been mentioned in the <a href="https://github.com/bbatsov/clojure-style-guide" rel="nofollow">Clojure Style guide</a> to avoid functions longer than 10 SLOC but mine has more than 10 (47 to be exact).</p> <p>The code is an <a href="https://github.com/psibi/clj-uclassify/blob/master/src/clj_uclassify/uclassif...
[]
[ { "body": "<p>There's value in factoring the logic out into one or more new functions, even if those functions are only used in a single place, because it can make the code easier to understand and modify.</p>\n\n<p>In a situation like that (when the logic won't be used elsewhere) I often use <code>letfn</code>...
{ "AcceptedAnswerId": "30108", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-22T22:34:31.360", "Id": "30106", "Score": "3", "Tags": [ "clojure" ], "Title": "Clojure function greater than 10 SLOC" }
30106
<p>The purpose of this script is to calculate the nonlinear reflection coefficient of a crystalline silicon slab.</p> <p>It takes some input files (columns of data separated by whitespace), converts that data to NumPy matrices, then operates on that data via some formulas that are coded into different functions. Final...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T07:12:31.710", "Id": "47827", "Score": "3", "body": "It would be good to (1) [profile](http://docs.python.org/2/library/profile.html) the code, (2) time a Python script that is only `import numpy, scipy` (maybe that already takes 1....
[ { "body": "<p>Avoid computing the same thing more than once. For example:</p>\n\n<ul>\n<li>Define global constants such as <code>SIN_THETA_RAD_SQUARED = sin(THETA_RAD) ** 2</code></li>\n<li>Load the data files just once into global constants, or into local variables in <code>nonlinear_reflection</code> and pass...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T01:50:04.690", "Id": "30109", "Score": "5", "Tags": [ "python", "numpy", "mathematics" ], "Title": "Calculating the nonlinear reflection coefficient of a crystalline silicon slab"...
30109
<p>I am building my first real php web app. as many you know this requires building LOTS of pages.</p> <p>in attempting to streamline the repetitive stuff i placed most of my stuff within a content.php page which looks like this</p> <pre><code>?php include_once ('config3.inc');?&gt; &lt;?php if(isset($_GET['p'])){ ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T12:58:03.017", "Id": "47841", "Score": "0", "body": "Why is this off-topic? this is working code..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T16:28:21.643", "Id": "47870", "Score": "1", ...
[ { "body": "<p>Well a more elegant approach would be to use an MVC pattern as a starter framework I would suggest you to use <a href=\"http://laravel.com/\" rel=\"nofollow\">Laravel</a> it's very clear written and also an easy catch for people who are general new to MVC. The way your currently writing the code, ...
{ "AcceptedAnswerId": "30151", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T06:07:05.907", "Id": "30112", "Score": "2", "Tags": [ "php", "template" ], "Title": "Attempting to build template but Having Issue with gets and posts" }
30112
<p>After getting much improvement, it´s still one issue that concerns me. And that is the sync between my 2 threads.</p> <p>I use AutoResetEvent, but sadly, it has some delay with it, and would love to use something else if possible. Would be great if something could be connected to a Bool or the Queue i am using. Her...
[]
[ { "body": "<ol>\n<li><p>When I tried to measure the delay of <code>AutoResetEvent</code>, I usually got less than 0.1 ms. That doesn't sounds like something you should worry about. If you're seeing larger delay, maybe it's caused by something else. It could be processing the message queue, which is what <code>R...
{ "AcceptedAnswerId": "30124", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T06:48:57.783", "Id": "30115", "Score": "1", "Tags": [ "c#", "multithreading" ], "Title": "Is this a good way to syncronize my Threads?" }
30115
<p>In C# I have the following two extension methods.</p> <pre><code> public static void WaitForMilliseconds(this IWebDriver driver, int milliseconds) { var timeout = new TimeSpan(0, 0, 0, 0, milliseconds); WaitForTimeout(driver, timeout); } public static void WaitForSeconds(this IWebDri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-08-20T23:03:05.167", "Id": "185638", "Score": "0", "body": "The desire to improve code is implied for all questions on this site. Question titles should reflect the purpose of the code, not how you wish to have it reworked. See [ask]." ...
[ { "body": "<p>If it helps make your code more readable and easier to maintain, I see no problem with that at all. Personally, I start with private extension methods and usually wind up promoting them into my company's public libraries when they appear to have enough utility.</p>\n\n<p>So... go for it. Just make...
{ "AcceptedAnswerId": "30131", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T08:07:53.633", "Id": "30118", "Score": "6", "Tags": [ "c#", "extension-methods" ], "Title": "Are private extension methods a bad thing to use?" }
30118
<p>Suppose I have following elementary DTOs, each DTO corresponding to a database table:</p> <pre><code>class Event { String name } class Player { String name } </code></pre> <p>DAOs for elementary DTOs:</p> <pre><code>class PlayerDao { def insert(Player p) { //sql to insert local members } }...
[]
[ { "body": "<p>I would go for the first one, because it exposes a much simpler API to the caller.</p>\n\n<p>The day you need to add anything to your design, if it's encapsulated this way, the caller doesn't need to change a thing and it's still going to work, because the <code>Game</code> <em>knows</em> how to b...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T12:19:21.327", "Id": "30123", "Score": "3", "Tags": [ "comparative-review", "groovy", "jdbc" ], "Title": "Designing DAOs that handle composite objects" }
30123
<p>This works fine but I feel it can be better optimized.</p> <pre><code>#!/usr/bin/env py s = "1:5.9,1.5:7,2:10,4:18,8:40" load_value = raw_input("Enter a load value\n") li = s.split(',') driver = None for index,item in enumerate(li): if load_value == li[index].split(':')[1]: driver = li[index].split(':...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T13:19:44.577", "Id": "47845", "Score": "0", "body": "do not call `li[index].split(':')` twice. Call it once, store the result and than use [0] and [1] on it." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-...
[ { "body": "<p>Maybe you can use <code>dict</code> instead of <code>str</code> to store the driver-load values. If the driver is the key, you can search easily.</p>\n\n<pre><code>#!/usr/bin/env py\n\ns = {'5.9':'1', '7':'1.5', '10':'2', '18':'4', '40':'8'}\nload_value = raw_input(\"Enter a load value\\n\")\ndriv...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T12:50:24.903", "Id": "30126", "Score": "2", "Tags": [ "python" ], "Title": "Searching a list of pairs of numbers" }
30126
<p>I have an application which polls a bunch of servers every few minutes. To do this, it spawns one thread per server to poll (15 servers) and writes back the data to an object:</p> <pre><code>import requests import threading import time servers = ['1.1.1.1', '1.1.1.2'] class CallThreads(threading.Thread): ""...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T14:57:23.543", "Id": "47926", "Score": "0", "body": "Is the while statement supposed to be in the `process_results` function?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T06:57:18.980", "Id": "...
[ { "body": "<p><strike>The two classes seem useless to me.</p>\n\n<p><code>ServerResults</code> only contains a list, so just use a list.</strike> <em>Edit: see comment below.</em></p>\n\n<p>The <code>CallThreads</code> class is unnecessary, this:</p>\n\n<pre><code>t = CallThreads(poll_server, s, results)\n</cod...
{ "AcceptedAnswerId": "30665", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T13:23:59.837", "Id": "30129", "Score": "3", "Tags": [ "python", "multithreading" ], "Title": "Polling multiple servers" }
30129
<p>I've made the following program that takes a list of email addresses from a table in MS Access and sends each a test email.</p> <pre><code>'Send email to mailing list Function SendNotificationEmail() 'Handle any errrors On Error GoTo ErrHandler: 'Create Outlook object Dim olApp As Outlook.Application ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-03-29T19:23:27.160", "Id": "510382", "Score": "0", "body": "You ask if this is the right approach. Why not just use MS Words mail merge to email (assuming you have word and outlook)." } ]
[ { "body": "<pre><code>Set olMailItem = Nothing\nSet olFolder = Nothing\nSet olNS = Nothing\nSet olApp = Nothing\n</code></pre>\n<p>is unnecessary. VBA is garbage collected, there's no need for this, or any of the other <code>= Nothing</code>'s you have. <a href=\"https://docs.microsoft.com/en-us/archive/blogs/e...
{ "AcceptedAnswerId": "30146", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T13:45:32.440", "Id": "30130", "Score": "7", "Tags": [ "vba", "email", "ms-access" ], "Title": "Sending test emails to a list of email addresses" }
30130
<p>I move back and forth between Python and C++ and I often need a nice/quick way to output STL objects to the screen for debugging purposes. I'd like the output to match the output of a comparable Python object, thus I have different templates for vectors, sets, etc...</p> <p>Is this the best way to go about this?</p...
[]
[ { "body": "<p>This looks fine, but perhaps a more idiomatic option would be to use <code>ostream_iterator</code>, or similar constructs with <code>std::copy</code>, to avoid the actual loop. See <a href=\"https://stackoverflow.com/questions/6692880/how-to-deal-with-last-comma-when-making-comma-separated-string\...
{ "AcceptedAnswerId": "30159", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T14:04:00.807", "Id": "30132", "Score": "3", "Tags": [ "c++", "c++11", "vectors" ], "Title": "Comma-formatted STL vectors" }
30132
<p>The following code is part of an application I maintain that has a VT100/Xterm style graphical user interface that is implemented using text (Think Midnight Commander. Retro, I know.)</p> <p>Part of the code involves producing collections of rectangles that represent regions of the screen that may require redrawin...
[]
[ { "body": "<p>So I cleaned up and simplified the inner loop in the code quite a lot:</p>\n\n<pre><code>static vector&lt;rectangle&gt; merge_overlapping_slices(vector&lt;rectangle&gt; rectangles)\n{\n sort(rectangles.begin(), rectangles.end(), compare_slices);\n\n BOOST_AUTO(first_slice, rectangles.begin()...
{ "AcceptedAnswerId": "31723", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T14:40:36.860", "Id": "30137", "Score": "3", "Tags": [ "c++", "performance", "algorithm", "computational-geometry" ], "Title": "Algorithm for merging overlapping rectangles"...
30137
<p>I wrote a script for getting the stats of codereview.SE from the front page into a file. <a href="https://github.com/anshbansal/general/blob/b444984901f01b90d88c81e6e561924970548594/Python33/Projects/codereview_stats/get_stats.py" rel="nofollow">Github link</a> if someone prefers reading there. Here is <code>data_f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T09:05:12.657", "Id": "48041", "Score": "0", "body": "If a line needs some explanation, that explanation should be right before/beside it in a comment. :)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-2...
[ { "body": "<p>Firstly, you don't need to store the last date at the beginning of the file since it's already at the end.</p>\n\n<p>Secondly, you shouldn't compute today's date twice.</p>\n\n<p>Thirdly, you should use <a href=\"http://api.stackexchange.com/docs/info#filter=default&amp;site=codereview&amp;run=tru...
{ "AcceptedAnswerId": "30589", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T15:16:56.133", "Id": "30139", "Score": "5", "Tags": [ "python", "python-3.x" ], "Title": "Review Python script for getting the stats of codereview.SE into a file for analysis" }
30139
<p>This is my first Python script, and I was hoping to get some feedback. I do have one specific question: is the use of <code>global</code> variables considered a bad practice? When I used them below, my programmer's instincts immediately went off as though I was creating a code-smell, mostly because it seems much l...
[]
[ { "body": "<p>You can solve anything without globals. If not, you are doing wrong. If you are using globals, the debugging will be a nightmare. In the <code>checkGuess()</code> you can use single ifs instead of elif. The return will terminate the function and after the first 3 check, the last one can't be anyth...
{ "AcceptedAnswerId": "30156", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T18:44:22.477", "Id": "30150", "Score": "5", "Tags": [ "python", "beginner", "number-guessing-game" ], "Title": "First Python script: number-guessing game with a global variable...
30150
<p>This method allows me to filter by date a data structure list of hash that contains articles. I would like to have your opinion on the code:</p> <pre><code>=method article_by_date $articles-&gt;articles_by_date( month =&gt; 12 ); </code></pre> <p>Return a list of articles filter by date specified:</p> <pre><...
[]
[ { "body": "<p>Most of this depends on what exactly do you want to achieve. For example, <code>@articles</code> will be a list of references to the same articles that are also referenced in <code>$self-&gt;_get_or_create_cache('articles')</code>. Depending on what you want, you might want to clone these values, ...
{ "AcceptedAnswerId": "30173", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T19:13:35.163", "Id": "30153", "Score": "2", "Tags": [ "datetime", "perl" ], "Title": "Filter by date method" }
30153
<p>I have been trying to parse results and make sure when I am doing so that I don't repeat the same data. I tried to use a few different options built into php with no luck. I did find an example of a recursive array search that seems to work but it's very intensive and adds a lot of time to the script.</p> <p><stron...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-01-22T09:38:07.303", "Id": "141789", "Score": "1", "body": "Also for PHP 5.5+ there is a simpler option, array_search($value, array_column($array, $key)); see http://stackoverflow.com/a/24527099/207603 (there is also a link to a backport ...
[ { "body": "<p>I have two comments.</p>\n\n<p>First, what is the purpose of <code>$current_key</code>? Since you're not changing it, just use <code>$key</code>.</p>\n\n<p>Second, by your usage, I'd say that</p>\n\n<pre><code>foreach ($haystack as $key =&gt; $item)\n if ($item[\"md5\"] === $needle) return $key...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-23T21:23:49.780", "Id": "30155", "Score": "1", "Tags": [ "php", "array" ], "Title": "Searching multidimensional arrays" }
30155
<p>Is there a better way to write it? I need the best way to write it. It is this principle? Please show me a better way</p> <p>it breaks SRP?</p> <pre><code> public class PlacementLocation { public int Row { get; set; } public int Column { get; set; } public int Location { get; set; } } public class Pla...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T14:16:09.893", "Id": "47917", "Score": "0", "body": "why have you edited the initial question code? Now it is not clear what question is about and answers below don't make any sense..." }, { "ContentLicense": "CC BY-SA 3.0",...
[ { "body": "<p>Yes. Your class is not reusable, as it uses a specific initialization.</p>\n\n<p>Write a basic 'PlacementLocations' and a specialized and separate class with your initialization. Or do the initialization in the class using your PlacementLocations.</p>\n\n<p>The latter is the usual case. </p>\n\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T04:53:53.650", "Id": "30162", "Score": "1", "Tags": [ "c#", "beginner", "collections", "constructor" ], "Title": "Write a class with some properties and indexed" }
30162
<p>I have two threads, where one listens on TCP and the other renders in a loop:</p> <pre><code> private void checkBox1_CheckedChanged(object sender, EventArgs e) { try { if (ReceiveCheck.Checked) { tcplisten.Start(); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T11:44:14.123", "Id": "47904", "Score": "0", "body": "Can you clarify this \"To just start then, and kill them when i want to?\". Are you asking how to do this or is this a good way to do this?" }, { "ContentLicense": "CC BY-...
[ { "body": "<p>No, this is absolutely not a good way. <code>Thread.Abort()</code> should never be used, because it is very hard to write correct code when an exception can happen at almost any point in your code.</p>\n\n<p>Instead, you should implement cooperative cancellation either by using a <code>volatile bo...
{ "AcceptedAnswerId": "30171", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T08:48:33.870", "Id": "30166", "Score": "0", "Tags": [ "c#", "multithreading", "tcp" ], "Title": "Threads listening on TCP and rendering in a loop" }
30166
<p>I've written an Entity Component System using C++ for my game engine. I'm still inexperienced so I've probably made a lot of mistakes. Thus I've decided to ask here for an honest review.</p> <p>The complete code is fairly large (although not too large IMHO) so it wouldn't quite fit here. Still if anyone here wishes...
[]
[ { "body": "<p>With regards to returning <code>ComponentProvider</code> by value from <code>getRelevantComponents</code> if you have a move constructor defined (or the default move constructor is generated) the return is likely to be moved instead of copied and you won't have to worry about it at all.</p>\n\n<p>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T12:14:43.117", "Id": "30170", "Score": "8", "Tags": [ "c++", "c++11", "entity-component-system" ], "Title": "Entity Component System in C++" }
30170
<p>I made this simple chat in php. You have suggestions on how I can improve it?</p> <p>This file configures the connection to the server</p> <p>This file is a simple form "login" ( only username required )</p> <pre><code> &lt;form action="chat.php" method = "post"&gt; Username: &lt;input type="text" name="ni...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T17:23:36.750", "Id": "47948", "Score": "0", "body": "If you aren't sure if this is working 100%, then come back when you have fixed it." } ]
[ { "body": "<p>If I'm reading this right, your AJAX grabs the whole chat every 3 seconds and (re)displays it. IMO, it'd be much better to send some info on the last message you have (timestamp or something), and then fetch only newer messages if there are any (via JSON; format them on the client side). That woul...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T09:27:59.760", "Id": "30176", "Score": "2", "Tags": [ "php", "javascript", "html", "mysql", "ajax" ], "Title": "Chat with PHP, MySql, Ajax: How to improve it?" }
30176
<p>Is there anyway to make this piece of code more elegant? It's not a nice view, but I can't really see a way to improve the looks of it or shorten it.</p> <pre><code>private void Send(CancellationToken CTSSend) { try { NativeMethods.Rect rc; NativeMethods.GetWindowRect(hwnd, out rc); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T18:54:49.580", "Id": "47953", "Score": "0", "body": "First of all, you should apply separation of concerns. Encoding images and network communication shouldn't be in the same method, probably not even in the same class." }, { ...
[ { "body": "<p>A couple of comments:</p>\n\n<ul>\n<li>Shortening code is not a goal - readability and maintainability is (which may, but not neccessarily, shorten it).</li>\n<li>The code mixes net code, graphics code, encoder code and UI code. Separating these into separate functions/classes will be <em>very</em...
{ "AcceptedAnswerId": "30209", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T16:48:46.883", "Id": "30177", "Score": "2", "Tags": [ "c#", "tcp" ], "Title": "TCP connection and reconnection" }
30177
<p>I'd like this improved.</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;Add New Games&lt;/title&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt; &lt;meta name="description" content=...
[]
[ { "body": "<p>First of all, I'm not a fan of having one single page with everything -- I typically prefer to separate my HTML from my PHP.</p>\n\n<p>Putting that aside:</p>\n\n<pre><code>$dbc = mysql_connect(,,);\n</code></pre>\n\n<p>The documentation for <a href=\"http://php.net/manual/en/function.mysql-connec...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T17:02:38.317", "Id": "30178", "Score": "2", "Tags": [ "php" ], "Title": "Adding new games to a database" }
30178
<p>I would like to get some feedback on my AS3 code below. It's for an Adobe Air mobile app to preload a website in a StageWebView container. That container will be moved on screen later in the app process. My goal is to show the website content to the user as fast as possible.</p> <pre><code>// OFF SCREEN - PRELOAD v...
[]
[ { "body": "<p>I don't think there's anything that can be improved to your approach.</p>\n\n<p>Minor improvements do apply;</p>\n\n<pre><code>function showWeb(e:Event=null){\nwebView.viewPort = new Rectangle( 0, 0, stage.stageWidth, stage.stageHeight);\n}\n</code></pre>\n\n<p>could use some indentation,</p>\n\n<...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T17:10:10.177", "Id": "30179", "Score": "3", "Tags": [ "actionscript-3" ], "Title": "Preload content in StageWebView" }
30179
This tag is for questions that came up in an interview.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T17:52:13.467", "Id": "30184", "Score": "0", "Tags": null, "Title": null }
30184
<p>The following code would strip 0 (all numbers ending with 0, it can contain 0, eg: 105 can be is valid but 150 should be eliminated) and return a number in decimal series if all numbers ending with 0 were stripped.<br> Example : <code>0 -&gt; 1, 10 -&gt; 11, 19 -&gt; 22</code>.<br> I would just appreciate any code ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T20:28:12.933", "Id": "47957", "Score": "6", "body": "Your question is unclear. Why `19 -> 21`? What is the expected output for `100` and `998` and why?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T...
[ { "body": "<p>Well... Sorry to say this, but it's crappy!</p>\n\n<ul>\n<li>The function name doesn't explain what the function does (and using your explanation above for Javadoc would only make things worse, judging from the confusion in the comments)</li>\n<li>Even knowing the implementation doesn't help, it's...
{ "AcceptedAnswerId": "30206", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T20:10:53.220", "Id": "30186", "Score": "1", "Tags": [ "java" ], "Title": "Code review of code to strip 0 from decimal series" }
30186
<p>Is there any way to make this work faster?</p> <p>Here is my sample code in vb.net. This adds a point on a chart at mouse position but it is quite slow.</p> <pre><code>Private Sub Chart2_MouseMove(sender As Object, e As MouseEventArgs) Handles Chart2.MouseMove Dim coord() As Double = GetAxisValuesFromMouse(e.X, e...
[]
[ { "body": "<pre><code>Try\n Chart2.Series.RemoveAt(1)\nCatch ex As Exception\nEnd Try\n</code></pre>\n\n<p>Your Try/Catch block is probably the cause of your problem. Catching exceptions is very slow. Instead you should check to see if the item exists at index 1 before you try to remove it. You should notice...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T20:29:10.017", "Id": "30188", "Score": "5", "Tags": [ "performance", ".net", "vb.net" ], "Title": "Drawing a point on a chart" }
30188
<p>I'm looking for general feedback on how to make this useful to other people. This is a subset of underscore.js with some additions, and what I feel are improvements.</p> <p>The code passes jslint and minifies well with clousre.</p> <p>Please let me know what questions I can answer to receive a better review.</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T21:57:44.603", "Id": "47963", "Score": "0", "body": "Welcome! We cannot look for errors for you here, but we can certainly do a general review. If you do come across errors, feel free to post them on Stack Overflow." }, { ...
[ { "body": "<ul>\n<li><p>When declaring variables, I suggest going with the <code>var</code> for each approach. Helps you in avoiding missing commas. Also, it's easier to read and tell they are variables especially when there are comments in between the set.</p></li>\n<li><p>Name your variables verbosely. It can...
{ "AcceptedAnswerId": "30196", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T20:56:47.643", "Id": "30189", "Score": "4", "Tags": [ "javascript" ], "Title": "General feedback on utility module" }
30189
<p>This code finds the intersections of all overlapping intervals.</p> <p>Example: if <code>[0-20]</code>, <code>[15-40]</code>, and <code>[25-50]</code> are the 3 intervals then the output should be <code>[15-20]</code> and <code>[25-40]</code>.</p> <p>I could not find an answer with complexity less than \$O(n^2)\$....
[]
[ { "body": "<p>Sort the intervals by starting value, and length incremental : O(n sqrt(n))<br></p>\n\n<p>Loop the intervals and check overlaps between current and previous one. : O(n)</p>\n\n<p>Resulting complexity : O(n sqrt(n))</p>\n\n<p>You said to assume they're already sorted, but I'm not sure whether they...
{ "AcceptedAnswerId": "30201", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T21:04:17.880", "Id": "30190", "Score": "10", "Tags": [ "java", "optimization", "interval" ], "Title": "Find intersections of overlapping intervals" }
30190
<pre><code>private void rect_ManipulationStarting(object sender, ManipulationDeltaRoutedEventArgs e) { startingColumn = Grid.GetColumn(e.OriginalSource as Windows.UI.Xaml.Shapes.Rectangle); gLValue = headerGrid.ColumnDefinitions[startingColumn].Width.Value + e.Delta.Translation.X; if (gLVal...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T13:21:32.400", "Id": "47996", "Score": "2", "body": "A lot more information is need - Winforms or WPF? Is column virtualization enabled? Are columns Auto width or fixed width? TemplateColumn or builtin column (WPF)? Would it perhaps...
[ { "body": "<p>Here is the final code without any lag!</p>\n\n<pre><code> //event handler for when the rectangles are dragged left or right (resizing the columns)\n private void rect_ManipulationStarting(object sender, ManipulationDeltaRoutedEventArgs e)\n {\n startingColumn = Grid.GetColumn(e.Or...
{ "AcceptedAnswerId": "30333", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T22:16:53.177", "Id": "30191", "Score": "1", "Tags": [ "c#", "xaml" ], "Title": "Need help optimizing code so that resizing of 884+ columns in grid does not lag" }
30191
<p>The code I'm trying to improve modifies a URL according to the options passed in a hash:</p> <pre><code>{ :image_aspect_ratio =&gt; "square", :image_size =&gt; 50 } </code></pre> <p>or</p> <pre><code>{ :image_size =&gt; { :width =&gt; 50, :height =&gt; 60 } } </code></pre> <p>The code looks like ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T00:38:16.403", "Id": "48018", "Score": "0", "body": "What is `raw_info['picture']`? An object or just a plain array?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-04T15:53:41.487", "Id": "48947", ...
[ { "body": "<p>Overall, it's reasonably tight code. You've taken steps to reduce method size, which is good.</p>\n\n<p>To answer your questions specifically:</p>\n\n<ol>\n<li><p>I think an instance variable would be better, because then you can avoid the else clauses you mention in 2. Those methods can then be r...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T00:25:26.997", "Id": "30194", "Score": "1", "Tags": [ "optimization", "ruby", "image" ], "Title": "Modifying an image URL based on hash options" }
30194
<p>I've implemented a rate limiter for redis in Lua, and I'm wondering if anyone has any suggestions that might improve the performance.</p> <p>An example use: </p> <pre><code>eval '[sha] mykey 1234567 60000 1000 1 10' 0 </code></pre> <p>Which translates to:</p> <ul> <li>Create a hash under key <code>mykey</code></...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-04-13T06:49:25.993", "Id": "234239", "Score": "0", "body": "A little bit off-topic but maybe relevant for anyone using redis. Windows now has bash, meaning that [you no longer need sloppy virtual machines](http://www.hanselman.com/blog/De...
[ { "body": "<p>I run the code in my laptop. I got 16594.76 requests per second.</p>\n\n<p>Environment:</p>\n\n<ul>\n<li>Ubuntu 15.10</li>\n<li>Run Redis natively (no VM)</li>\n<li>CPU: Intel(R) Core(TM) i7-2620M CPU @ 2.70GHz</li>\n<li>Mem: 16GB</li>\n</ul>\n\n<p>After some changes I got 17825.31 requests per se...
{ "AcceptedAnswerId": "139472", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T00:25:58.690", "Id": "30195", "Score": "11", "Tags": [ "performance", ".net", "lua", "redis" ], "Title": "Redis rate limiting in Lua" }
30195
<p>I have created a polymorphic system, but I don't know whether this is the correct way of doing it. Am I abusing Polymorphism here? Here is the code:</p> <pre><code>class WriteObj { public string Obj1 { get; set; } public string Obj2 { get; set; } public string Obj3 { get; set; } } </code></pre> <p>The ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T09:48:35.737", "Id": "47989", "Score": "1", "body": "Seems ok. I might consider making the Writer method take a more generic parameter, perhaps ICollection or even a ReadOnlyCollection to enforce an abstraction that the method is t...
[ { "body": "<p>Yes, I don't see a problem with that.</p>\n\n<p>If you don't have any implementation at all in the base class, consider making it an interface instead:</p>\n\n<pre><code>interface IWriter {\n void Write(List&lt;WriteObj&gt; writeObjList);\n}\n\nclass ConsoleWriter : IWriter {\n public void Wri...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T07:29:53.423", "Id": "30202", "Score": "2", "Tags": [ "c#", "object-oriented", "polymorphism" ], "Title": "designing application using polymorphism" }
30202
<p>Can you please take a look at my code and improve it (if necessary)?</p> <p><a href="http://jsfiddle.net/U6R6E/" rel="nofollow">http://jsfiddle.net/U6R6E/</a></p> <p><strong>Javascript (with jQuery)</strong></p> <pre><code>function random(min, max) { return min + parseInt(Math.random() * (max - min + 1), 10);...
[]
[ { "body": "<p><code>Math.random()</code> <a href=\"http://ifsec.blogspot.com/2012/05/cross-domain-mathrandom-prediction.html\">doesn't return cryptographically secure numbers on all browsers</a>. If this is intended for production use, you'll want to use <a href=\"http://crypto.stanford.edu/sjcl/\">a library th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T14:33:02.820", "Id": "30211", "Score": "8", "Tags": [ "javascript", "jquery", "performance", "random" ], "Title": "Improve random password generator" }
30211
<p>This is a quick and dirty implementation of coroutines that implements yield by saving and restoring the stack to and from the heap. Here's an earlier version, which does <a href="https://github.com/danluu/setjmp-longjmp-ucontext-snippets/blob/master/coroutines.c">the most naive possible thing</a>, and just allocate...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T21:10:24.493", "Id": "48008", "Score": "0", "body": "Apart from BSD linux." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T23:08:29.027", "Id": "48012", "Score": "0", "body": "Are you tryi...
[ { "body": "<h1>Things you did well on:</h1>\n\n<ul>\n<li>Overall, this looks like a pretty decent little bit of code. It looks like some research went into this</li>\n<li>I like the comments. Everywhere I was confused on something, there was a comment to clarify. You also didn't go overboard with them!</li>\...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T18:13:53.777", "Id": "30214", "Score": "11", "Tags": [ "c", "stack", "concurrency" ], "Title": "How can this simple coroutine implementation be improved?" }
30214
<p>I need to bind a <code>dropdown</code> to an <code>enum</code>. For this I've made a <code>key_value_pair</code> class and I manually go through each <code>enum</code> option to add it. Is there a more elegant way to achieve this?</p> <p>HTML:</p> <pre><code>&lt;select data-bind="options: regions, value: region, o...
[]
[ { "body": "<p>Your solution works fine and I didn't find a better solution. I've just upgraded it little bit, by automatic fill the options, so it is usable to any <code>Enum</code> class.</p>\n\n<p><a href=\"https://stackoverflow.com/a/21294925/984081\">Here I found how to enumerate <code>Enum</code> type</a><...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T18:37:29.703", "Id": "30216", "Score": "2", "Tags": [ "enum", "typescript" ], "Title": "\"options\" binding with an enum as data source" }
30216
<p>I want to access some of the methods from outside of the plugins scope, namely <code>showPopup()</code>, <code>hidePopup()</code> and <code>updateColor(newcolor)</code>.</p> <h3>Initialization</h3> <pre><code>&lt;span class="cp"&gt;&lt;/span&gt; &lt;script&gt; var cp = $(".cp").ColorPickerSliders({ fl...
[]
[ { "body": "<p>Firstly, underneath everything Javascript is an event driven language so I do not think that there is anything wrong with using an event driven design pattern if you are comfortable with it. Events are a great way to be able to interlink different components of your system without exposing the inn...
{ "AcceptedAnswerId": "30726", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T20:07:21.440", "Id": "30218", "Score": "1", "Tags": [ "javascript", "jquery", "plugin" ], "Title": "jQuery Color Picker Sliders plugin" }
30218
<p>Please review my code.</p> <pre><code>public class CircularLinkedlistinsert { private Node first; private static class Node { int element; Node next; public Node(int element, Node next) { this.element = element; this.next = next; } } public ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T03:36:08.457", "Id": "48023", "Score": "2", "body": "You've fallen into the indentation trap. Add a return statement to the true case of the if statement and get ride of the else syntax." } ]
[ { "body": "<pre><code>public class CircularLinkedlistinsert {\n</code></pre>\n\n<p>Class names should have the first letter of each word capitalized. I'd also change the name to remove the activity and just describe the object. i.e., <code>CircularLinkedList</code>. The method names will describe whatever ac...
{ "AcceptedAnswerId": "30220", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T20:42:31.680", "Id": "30219", "Score": "3", "Tags": [ "java", "linked-list", "circular-list" ], "Title": "Insert in circular linked list" }
30219
<p>This is only my second Python script, so let me have it! If anything seems off in style or implementation, please nit pick away. I want to learn. I know it could've been done in less lines of code without making separate functions and whatnot, but I wanted to approach it like I would an actual project.</p> <pre>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T06:27:54.137", "Id": "48029", "Score": "2", "body": "@tintinmj This is Python2 not Python3. `raw_input` is in Python2 not Python3" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T07:11:12.580", "Id...
[ { "body": "<p>Not essential but I would find it neater to make a function that translates a single word, then join those together. You should also deal with the case of a word containing no vowels or 'y', which currently gets your programme stuck in an infinite loop.</p>\n\n<pre><code>def get_pig_latin(string):...
{ "AcceptedAnswerId": "30222", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T21:07:29.323", "Id": "30221", "Score": "2", "Tags": [ "python", "pig-latin" ], "Title": "Python Pig Latin Translator" }
30221
<p>I am writing a small application that would interactively allow user for xml file manipulation with d3 interactive charts. </p> <p>My xml file has the following hierarchy : </p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;testcase&gt; &lt;measurement&gt; &lt;type&gt;M8015&lt;/type&gt; &...
[]
[ { "body": "<p>I suggest you use JSON when manipulating the data because it's easier and less code compared to the same XML counterpart code - and much easier.</p>\n\n<p>I can think of two ways you can do this:</p>\n\n<ul>\n<li><p>Convert your files to JSON, <em>if you can</em>.</p></li>\n<li><p>If you can't con...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T23:34:01.950", "Id": "30227", "Score": "2", "Tags": [ "javascript", "jquery", "xml", "d3.js" ], "Title": "What is the more effective way to get array of data out of xml for d3...
30227
<p>I know my naming is not good. Please exclude variable / function renaming reviews from your comments.</p> <pre><code>import java.util.NoSuchElementException; /** * http://stackoverflow.com/questions/2216666/finding-the-intersecting-node-from-two-intersecting-linked-lists */ public class Interserction { pri...
[]
[ { "body": "<p>I suggest defining <code>getIntersectionNode()</code> right after <code>findIntersectionItem()</code>. Also, put a comment there saying that <code>getIntersectionNode()</code> only works when the two arms of the \"Y\" are the same length (which is OK because only <code>findIntersectionItem()</cod...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-25T23:54:53.167", "Id": "30228", "Score": "1", "Tags": [ "java", "linked-list" ], "Title": "Finding intersection of linked list" }
30228
<p>The following code gets the recipient's email address, email subject line and email body from a table. It then creates the emails and sends them to a pickup directory. There is a db connection class that I did not include here, but I invoke it in the code below.</p> <p>The code below runs fine. I am wondering if...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-15T19:58:13.217", "Id": "101939", "Score": "0", "body": "What version of C#/.NET Framework are you using? Your code contains Framework 1.1 constructs (i.e. `ArrayList`). If you have something newer in use, use idiomatic constructs (i.e...
[ { "body": "<p>Have you done any benchmarking? </p>\n\n<p>What part is slower, the database query or the sending of the emails to exchange?</p>\n\n<p>Sending emails is generally the slowest part, but given you are using a pickup directory, that may not be the case here. If it is really slow then you could run se...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T02:13:26.353", "Id": "30233", "Score": "4", "Tags": [ "c#", "performance", "email" ], "Title": "Sending emails using SMTP client" }
30233
<p>The following working code basically swaps the content of two divs. The divs are created dynamically, then the user checks which records they want to swap, and then clicks on a swap button that triggers a function to swap an inner div element.</p> <p>The part that swaps the div's seems really messy to me. I'm only...
[]
[ { "body": "<p>You could improve it a little like this, at least you are not selecting the same elements over and over.</p>\n\n<p>I do think it could improve more, if you swapped the actual div's rather then the html content and umrn value.</p>\n\n<pre><code>var $bed0 = $('#bed-div-' + selected[0].substring(4));...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T02:18:10.090", "Id": "30235", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Swapping dynamic page div's around on button click" }
30235
<p>So I'm working on a register form and I have four fields: name, username, email and password. I pick up the values of these fields in jQuery and depending on if all the fields are filled, I pass them onto a PHP script via ajax. Is that safe for form validations? I was worried about data getting manipulated by the us...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T07:19:09.687", "Id": "48031", "Score": "0", "body": "What are you doing with the data? Putting it into a DB? into a file? ..." } ]
[ { "body": "<p>I take it you're trying to protect yourself from XSS attacks, injection and general mallicious input. You're well on your way (but <a href=\"https://codereview.stackexchange.com/questions/29294/how-can-i-make-this-code-safer-against-xss-attacks/29295#29295\">do have a look here</a>, there are some...
{ "AcceptedAnswerId": "30248", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T04:04:52.910", "Id": "30237", "Score": "1", "Tags": [ "javascript", "php", "jquery", "validation" ], "Title": "Form validation - security and input specification" }
30237
<p>Previous question (without AI): <a href="https://codereview.stackexchange.com/questions/30060/tic-tac-toe-optimization">Tic-Tac-Toe optimization</a></p> <p>This new code has a main file, a base <code>game</code> class, and two derived <code>human</code> and <code>computer</code> classes.</p> <p>I welcome any sugge...
[]
[ { "body": "<ul>\n<li><p><em>In general</em>: it's nice to organize your STL <code>#include</code>s alphabetically. In addition, the header <code>#include</code>s should be above the library ones so that there are no dependencies among them.</p></li>\n<li><p>Not a very effective <code>choice</code> as you're al...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T04:52:50.027", "Id": "30238", "Score": "4", "Tags": [ "c++", "performance", "beginner", "game", "ai" ], "Title": "Tic-Tac-Toe optimization 2.0 with AI" }
30238
<p>How can I make it faster, more efficient, and simpler? Are there any obvious mistakes I've made, or things which will make my code "fancier"?</p> <p>It's my first time working with any form of pathfinding, so I'm sure I've made plenty of mistakes. It still works, though.</p> <p>I've ended up adding a lot of comme...
[]
[ { "body": "<p>Some points to consider...</p>\n\n<h3>Sorting is slow. <em>Really</em> slow.</h3>\n\n<p>At the end of your loop you call <code>OpenList.Sort()</code> to order your nodes by relative cost so that you can work on the lowest-cost nodes first. Depending on how far your search extends, this can lead ...
{ "AcceptedAnswerId": "30247", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T06:11:41.973", "Id": "30243", "Score": "8", "Tags": [ "c#", "pathfinding" ], "Title": "How can I improve upon my A* Pathfinding code?" }
30243
<p>I have written the following program for next word prediction using n-grams. The data structure is like a trie with frequency of each word.</p> <p>Any suggestions are welcome, but I am more concerned about the <code>compareTo</code> and <code>equals</code> method, where the contract of <code>if(obj1.compareTo(other...
[]
[ { "body": "<p>First let answer about your concern</p>\n\n<blockquote>\n <p>I am more concerned about the compareTo and equals method where the contract of <code>if(obj1.compareTo(other)==0)</code> then <code>(obj1.equals(obj2)</code> is not honored</p>\n</blockquote>\n\n<h2><code>equals</code> Method</h2>\n\n<...
{ "AcceptedAnswerId": "30263", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T08:47:00.397", "Id": "30249", "Score": "2", "Tags": [ "java", "trie" ], "Title": "Next word prediction using n-grams" }
30249
<p>I've looked for a good method to generate an integer inside a range of values. I think using modulo is not a good method because the values are not perfectly mapped in the range. So I mapped the pseudo random generated number in the range by using double variables types.</p> <p>What do you think about this method...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T14:54:11.637", "Id": "48069", "Score": "1", "body": "I think the initialization with `std::ceil()` could be this: `int i = std::ceil(static_cast<double>(32 / numberOfBits));`" }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<p><strong>DONT DO THIS</strong></p>\n\n<pre><code>while (i--)\n{\n myRand += rand();\n if (i)\n {\n myRand &lt;&lt;= numberOfBits;\n }\n}\n</code></pre>\n\n<p>It seems like you are trying to increase the range of random numbers.<br>\nWhat you are doing is screwing up the distribut...
{ "AcceptedAnswerId": "30260", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T08:53:11.150", "Id": "30250", "Score": "4", "Tags": [ "c++", "random", "integer" ], "Title": "What do you think about this uint64 random generator?" }
30250
<p>I'd like to create a cookie wrapper in my application to help support a DRY approach to coding common cookie methods, provide IntelliSense for cookie-type properties (keys), and protect against typo-errors when working with cookies from multiple classes and namespaces. </p> <p>The best structure for this (that I c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T12:00:55.820", "Id": "48051", "Score": "0", "body": "Why do you have `Cookie` and `Get()` that seem to do the same thing?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T15:32:34.803", "Id": "4807...
[ { "body": "<p>I am thinking that you are looking for an <code>Interface</code> rather than an <code>Abstract</code></p>\n\n<p>I am not sure what all you want to use this for, but I am thinking it might be worth looking into, especially if everything inside this class is something that you must have.\nthe only t...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T09:41:58.213", "Id": "30251", "Score": "3", "Tags": [ "c#", "asp.net-mvc-4", "http" ], "Title": "Cookie wrapper in MVC4" }
30251
<p>I recently started working on my code's cleanliness/logistics and would appreciate it if you could give me some tips on how to improve certain things.</p> <p>Here's a simple console Hangman game I've made:</p> <pre><code>#include &lt;fstream&gt; #include &lt;iostream&gt; #include &lt;stdio.h&gt; #include &lt;stdli...
[]
[ { "body": "<ul>\n<li><p>You may group your STL <code>#include</code>s either alphabetically, or by groups (credit to @Loki Astari in a different answer):</p>\n\n<blockquote>\n<pre><code>// This is Class.cpp\n#include \"Class.h\"\n#include \"OtherMyClassIdependon1.h\"\n#include \"OtherMyClassIdependon1.h\"\n\n//...
{ "AcceptedAnswerId": "30264", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T14:48:22.607", "Id": "30261", "Score": "15", "Tags": [ "c++", "game", "console", "hangman" ], "Title": "Hangman game logicistics and cleanliness" }
30261
<p>In order to make cert creation with easy-rsa as practical for others, this script was created and it works so far. The questions are:</p> <ol> <li>where can it be improved?</li> <li>are there flaws that are not obvious to the author?</li> </ol> <p>The commentary is a bit extensive, but whomever will come across t...
[]
[ { "body": "<p>This</p>\n\n<pre><code>myself=auto_rsa_gen.sh # tells the script who it is\n</code></pre>\n\n<p>is better done like this:</p>\n\n<pre><code>myself=\"$0\"\n</code></pre>\n\n<p>or, if you want just filename, then</p>\n\n<pre><code>myself=\"$(basename \"$0\")\"\n</code></pre>\n\n<p>because it will gi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T14:53:35.097", "Id": "30262", "Score": "3", "Tags": [ "bash" ], "Title": "Automating easy-rsa cert creation with Bash script" }
30262
<p>Is there a better way to write this, as I am using the condition of the Cancellation Token to tell if it should use a byte[] from another thread or not.</p> <pre><code> SharpDX.Windows.RenderLoop.Run(form, () =&gt; { if (CTS.IsCancellationRequested) form.Dispose(); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T17:33:09.517", "Id": "48079", "Score": "0", "body": "I think you shouldn't use `CancellationToken` here at all, since it looks like you're not actually using it for cancellation." }, { "ContentLicense": "CC BY-SA 3.0", "...
[ { "body": "<p><strong>EDIT</strong></p>\n\n<p>I think this is what you are looking for, it will only check once inside the using block, if you want to dispose the form if that first <code>Queue.TryTake(out TextureData, 300))</code> is false then add to the else of that statement.</p>\n\n<p>if you really want to...
{ "AcceptedAnswerId": "30272", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T16:17:42.297", "Id": "30266", "Score": "2", "Tags": [ "c#", "multithreading" ], "Title": "Better way to use a Condition (CancellationToken)" }
30266
<p>I wondered if there was any better way of doing so.</p> <p>I had a hard time figuring it out (it seemed nobody else already tried to do so).</p> <pre><code>import re import string class BetterFormat(string.Formatter): """ Introduce better formatting """ def parse(self, format_string): """ Receive...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T20:26:35.183", "Id": "48093", "Score": "0", "body": "`parse()` is doing too much to be one-lined. List comprehension can be very useful, but not when it causes the line to be over 200 characters. This would be more legible if the li...
[ { "body": "<p>Could <a href=\"http://docs.python.org/3.3/library/textwrap.html\" rel=\"nofollow\">textwrap</a> do some of the job?</p>\n\n<p>Particularly the dedent and indent function? You will still need to count the number of tabs you want, but the rest will be done. </p>\n", "comments": [], "meta_d...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T19:43:48.033", "Id": "30273", "Score": "2", "Tags": [ "python", "strings", "python-3.x" ], "Title": "Automatically indent a whole block of text into str.format" }
30273
<p>I currently have a solution to increment numbers within a range:</p> <pre><code>i % x + 1 </code></pre> <p><em>Where <code>x</code> is the maximum number in the range and <code>i</code> is the previous number.</em></p> <p>It is nice and simple, and gives this array: <code>1,2,3,4,1,2...</code></p> <p>I also need...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T23:06:48.977", "Id": "48102", "Score": "0", "body": "could you give some more of the code that you use? I want to recreate and see if I can do it, I have an idea but I want to test it first" }, { "ContentLicense": "CC BY-SA...
[ { "body": "<p>Some thoughts:</p>\n\n<pre><code>(i + x) % x == i //For i &gt;= 0 &amp;&amp; i &lt; x\n</code></pre>\n\n<p>Then</p>\n\n<pre><code>(i + x - 1) % x\n</code></pre>\n\n<p>Gives us the range from 0 to x-1.\nWe want the range from 1 to x so we change this to:</p>\n\n<pre><code>(i + x - 2) % x + 1;\n</co...
{ "AcceptedAnswerId": "30280", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-26T22:33:07.867", "Id": "30278", "Score": "1", "Tags": [ "c#", "mathematics" ], "Title": "Simple way to decrement number within a repeating range" }
30278
<p>So I have this code that i use for addition of funds to a certain item. </p> <pre><code>def addFund fund=params[:fund] if(fund.to_i&gt;0) @fund=fund if(@item.fund+fund.to_f&gt;@item.price) #the fund added should be less than price-current fudn respond_to do |format| format.htm...
[]
[ { "body": "<p>A lot of these logic could be moved to model. Rails provides lot of helpers for validation in your model. </p>\n\n<pre><code>class Item\n validate :fund_vs_price, :fund_greater_than_zero\n\n\n def fund_vs_price\n errors.add(:fund, \"Fund amount should not exceed price difference\") if fund &g...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T05:21:55.513", "Id": "30287", "Score": "0", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Ruby on rails action code could be shorter" }
30287
<p>I am developing an Android app. Due to my low experience and the requirement for network operation, my class uses a lot of <code>AsyncTask</code> instances and it grew quite large. I'd like to know how I can split this in to different classes, and generally make it better (not required).</p> <p>I am really confused...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T10:04:20.750", "Id": "48138", "Score": "4", "body": "Show us the important parts you want reviewed, do not simply copy-paste the entire class. You think someone would want to read 900 lines of your code? :) I seriously doubt it." ...
[ { "body": "<p>A few tips, but there may be more. These are just the things that immediately jumped out at me:</p>\n\n<hr>\n\n<blockquote>\n <p>Break out AsyncTasks into their own class</p>\n</blockquote>\n\n<p>With multiple tasks, it might be better to make them each their own class/file. You can call back to ...
{ "AcceptedAnswerId": "31708", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T08:00:09.487", "Id": "30289", "Score": "4", "Tags": [ "java", "android" ], "Title": "Refactoring long class to make it more maintainable" }
30289
<p>I want to insert and edit values on the same button click. The code is working fine and I am using the same code for both insertion and deletion.</p> <pre><code>function saveToDB(){ var value= pageValidation(); if($('#jobid').val()==" "){ if(value!=false){ var data = { "names": $('#names')....
[]
[ { "body": "<p>The only difference between the two code blocks is the service endpoint and the inclusion of the ID, so you could shorten it to:</p>\n\n<pre><code>function saveToDB(){\n var jobId = $('#jobid').val(); \n var valid = pageValidation();\n var url = jobId === \" \" ? \"/insertJobs\" : \"...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T09:02:54.680", "Id": "30291", "Score": "0", "Tags": [ "javascript", "jquery", "beginner" ], "Title": "Saving to database" }
30291
<p>I have a function which gets called very often, for this test 30,720,000 times. It has to run in real-time, so performance is very important. Are there possible improvements?</p> <pre><code>// This function looks up in the vertice table wheter a vertice at that position already exists // - If yes, return the vertic...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T10:42:04.367", "Id": "48145", "Score": "1", "body": "Why did you document parameters that don't exist?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T10:47:58.767", "Id": "48146", "Score": "0...
[ { "body": "<p>It looks to me like your function is actually doing 2 things:</p>\n\n<ol>\n<li>It's checking to see if an entry exists in the dictionary, and if so return it</li>\n<li>If it doesn't exist, then it creates a new one</li>\n</ol>\n\n<p>So I would break it into 2 functions:</p>\n\n<pre><code>VERTICE_I...
{ "AcceptedAnswerId": null, "CommentCount": "17", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T10:14:13.493", "Id": "30295", "Score": "3", "Tags": [ "c++", "performance", "coordinate-system" ], "Title": "Conditionally creating a new vertex" }
30295
<pre><code>class Youtube { private $url = null; private $id; public function __construct($url) { $this-&gt;url = $url; $this-&gt;parseUrl($url); } protected function parseUrl($url) { if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?...
[]
[ { "body": "<p>I would probably put the $width and $height into the properties and not hard-coded into the method. That way you can change them as needed, instead of editing the class itself.</p>\n\n<pre><code>class Youtube {\n private $width = 123; // default value, if needed \n private $height = 456; // ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T01:16:36.220", "Id": "30297", "Score": "3", "Tags": [ "php", "object-oriented" ], "Title": "Is this a qualified OOP script in PHP?" }
30297
<p>Based on the answer to <a href="https://stackoverflow.com/questions/18387417/">my previous question on Stack Overflow</a>, I put together the following Queue class. I realize there are already libraries out there to do this. However, I wanted to actually understand the concept and implementing it yourself really dri...
[]
[ { "body": "<p>From a once over,</p>\n\n<ul>\n<li>I would check for <code>if (self.paused) {</code> at the very beginning, otherwise you might keep pushing <code>returnValue</code> into the <code>args</code></li>\n<li>I would not assign an anonymous function herre: <code>this.next = function(returnValue) {</code...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T01:31:56.720", "Id": "30298", "Score": "3", "Tags": [ "javascript", "asynchronous", "callback", "queue" ], "Title": "Javascript Queue for async functions" }
30298
<p>I have a situation where I have multiple objects that each needs to connect to a different MongoDB URI.</p> <p>I am currently testing this using Mongolia but the concept should be the same if I were to use the <code>collection()</code> method of MongoDB's native driver.</p> <p>Mongolia requires a <code>db</code> o...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T11:17:58.550", "Id": "30299", "Score": "1", "Tags": [ "node.js", "coffeescript", "mongodb" ], "Title": "Handling multiple Mongodb connections in Node.js (using Mongolia)" }
30299
<p>Server:</p> <pre><code>require 'socket' require 'time' require 'ap' server = TCPServer.open(1026) def process_the_request req, client # not important, disk-related process sleep 2 req.to_s + ' ' + client.peeraddr[3].to_s + ' ' + Time.now.to_s end loop do Thread.start(server.accept) do |client| reques...
[]
[ { "body": "<p>You shouldn't read from the client one byte at a time. Call <a href=\"http://www.ruby-doc.org/stdlib-1.9.3/libdoc/socket/rdoc/TCPSocket.html\" rel=\"nofollow\"><code>client.gets</code></a> to take a line at a time.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T11:43:10.783", "Id": "30300", "Score": "1", "Tags": [ "performance", "ruby", "socket" ], "Title": "Improving performance of Ruby socket programming" }
30300
<p>The following is a new question based on answers from here: <a href="https://codereview.stackexchange.com/q/19592/3163">Small MVC for PHP</a></p> <hr> <p>I have written a small template library that I would like some critiques on, <a href="https://github.com/maniator/SmallFry/tree/cf08f80712084a220037d083330b14ba3...
[]
[ { "body": "<p>Small nitpick,</p>\n\n<pre><code>class_alias('SmallFry\\lib\\MySQL_Interface', 'SmallFry\\lib\\MySQL'); // MySQL class to be deprecated\n</code></pre>\n\n<p>You can use the <code>use</code> statement:</p>\n\n<pre><code>use SmallFry\\lib\\MySQL_Interface as MySQL\n</code></pre>\n", "comments": ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T14:02:23.970", "Id": "30304", "Score": "5", "Tags": [ "php", "object-oriented", "template", "library", "framework" ], "Title": "Small PHP framework template library" }
30304
<p>We're trying to design validation classes with a common interface. This would apply to all validators. We would define a validator interface with a <code>validate($input):bool</code> method. Each validator would represent a specific data type (email address, login, etc.); the validate method would implement the appr...
[]
[ { "body": "<p>I am not that familiar with static methods in PHP specifically, so my answer is a bit limited in the aspect of what can be done in PHP.</p>\n\n<p>If possible in PHP, I'd say make both ways available.</p>\n\n<p>Obviously, the appeal of the static method is in its ease of use. However, such approach...
{ "AcceptedAnswerId": "30329", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-08-27T14:02:42.370", "Id": "30305", "Score": "3", "Tags": [ "php", "comparative-review", "validation" ], "Title": "Validator classes" }
30305
<p>I have a factory that loads configuration from an xml file, and uses the configuration to be able to create objects of an appropriate type with appropriate settings. My application does a number of different tasks, and I don't want a broken or missing xml file to interfere with the other tasks the application does.<...
[]
[ { "body": "<p>Your approach will work, but I would suggest an alternative. \nRemove the <code>makeUnchecked</code> and <code>ready</code> methods. \nDo not have constructor load settings. \nHave a static <code>boolean</code> variable, say, <code>areSettingsLoaded</code> to indicate whether settings have been lo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T14:33:17.810", "Id": "30307", "Score": "5", "Tags": [ "java", "exception-handling", "dependency-injection" ], "Title": "Object can throw exception on construction, but I don't wan...
30307
<p>I have some doubt about how NSString is released in ARC Mode.</p> <p>I would like to know if have something i can do to release a nsstring when i want in arc mode.</p> <p>Take a look at this code:</p> <pre><code>__block NSString *strImage = nil; dispatch_sync(backGround, ^{ // Convert NSData To NSStri...
[]
[ { "body": "<p>Also <code>@autoreleasepool</code> does not look are the objects create outside of it scope, just the object used within. Also if using are there is not need for the <code>@autoreleasepool</code> at all, since the scope variables will be released and nilled at the end of the scope.</p>\n", "co...
{ "AcceptedAnswerId": "30513", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T14:59:10.780", "Id": "30310", "Score": "1", "Tags": [ "objective-c", "ios" ], "Title": "AutoreleasePool NSString Automatic Reference Counting" }
30310
<p>I'm using an open source program called MElt which lemmatize (give the lemma example:giving-->give) of words. MElt works on Linux and it's programmed in Perl and Python. So far it's working good but it take way too much time to give the results. I looked into the code and located the loop responsible for this:</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-30T09:14:50.630", "Id": "48494", "Score": "0", "body": "WRT the update: The code you have given us is a very small snippet from the actual code. The two answers just tell how a constant factor can be reduced. This doesn't matter much, ...
[ { "body": "<p>I would try to get rid of the regular-expressions, because they are quite heavy to compute.</p>\n\n<p>But if you need them, have a look at the answer in this post: <a href=\"https://stackoverflow.com/questions/550258/does-the-o-modifier-for-perl-regular-expressions-still-provide-any-benefit\">prec...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T15:18:14.220", "Id": "30312", "Score": "1", "Tags": [ "performance", "regex", "hash-map", "perl" ], "Title": "Searching for words in a dictionary" }
30312
<p>This program writes out all the files in the current directory level to a text file, outputs an array of sub-directories at the current level, then repeats this process until there are no more sub-directories to search. The code below take 50 seconds to run.</p> <p>I was hoping I could get any pointers on the code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T15:27:51.857", "Id": "48177", "Score": "0", "body": "what happens to the application when you hit an Exception in your try/catch? does the application stop, or does it skip that one and keep going?" }, { "ContentLicense": "...
[ { "body": "<p>First of all, you shouldn't hardcode values like your <code>C:\\</code> or <code>C:\\ComputerFiles.txt</code>. If you want to change this, you don't want to edit it at multiple places.</p>\n\n<pre><code>static void filesArray(string path)\n</code></pre>\n\n<p>The usual .Net naming convention for m...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T15:21:52.133", "Id": "30313", "Score": "3", "Tags": [ "c#", "search" ], "Title": "Writing out names of files on local C drive to a text document" }
30313
<p>This is an Android app and there is a <code>EditText</code> box, and I need to accept multiple types of inputs one after another in order. This order is predefined. On <code>USER_INP_NAME</code> object <code>newUser</code> is created. After this multiple properties are set with this object. Finally on <code>USER_INP...
[]
[ { "body": "<p>I think I would consider using three controls to achieve this and resetting their visibility on submission.</p>\n\n<p>Reusing whatever you have used to create the userInputs control, rename that to nameInput and create two others weightInput and shelfLifeInput. Importantly when creating the other ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T17:06:01.063", "Id": "30321", "Score": "1", "Tags": [ "java", "object-oriented", "android" ], "Title": "Getting multiple inputs from single EditText" }
30321
<p>I am calling a C library via P/Invoke. That library needs to be called in sucession with an increasing <code>unsigned int</code>, and returns a pointer. That pointer is then mapped to a managed type, until it returns a <code>NULL</code> pointer. </p> <p>In C, the idiomatic way to write it, is probably <code>for(i=0...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T21:52:53.373", "Id": "48207", "Score": "1", "body": "BTW, this method might be a good candidate for `yield return`." } ]
[ { "body": "<p>I think the for loop can show the \"breaking condition\" like this:</p>\n\n<pre><code>for (uint i = 0; (newPort = GetPortData(i)) != null; i++) {\n ports.Add (newPort);\n}\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T...
{ "AcceptedAnswerId": "30324", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T19:00:45.360", "Id": "30322", "Score": "3", "Tags": [ "c#" ], "Title": "Idiomatic loop and break condition" }
30322
<p>This module is dependent upon a utility module I previously posted:</p> <p><a href="https://codereview.stackexchange.com/questions/30189/general-feedback-on-utility-module">General feedback on utility module</a></p> <p>I'm looking for general feedback on how to make this useful to other people. This is a subset of...
[]
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li>Unfortunate naming\n\n<ul>\n<li><code>win[$R.g].molist.dom</code> &lt;- <code>$R</code> and <code>g</code> and <code>molist</code> are unfortunate</li>\n<li><code>function (ref_el, func, con)</code> &lt;- <code>con</code> ?</li>\n<li><code>$P.HTMLToElement</code...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T20:42:52.320", "Id": "30327", "Score": "3", "Tags": [ "javascript" ], "Title": "General feedback on DOM module" }
30327
<p>This is my table model code style:</p> <pre><code>public class MyModel extends DefaultTableModel { static Vector data = new Vector(); static Vector column = new Vector(); Connection conn; Statement statement; ResultSet result; public MyModel() { super(data, column); try { conn = DriverManager.getConnection(.....
[]
[ { "body": "<p>This way your software is highly coupled. I can see three big responsibilities in it:</p>\n\n<ul>\n<li>Get data from db</li>\n<li>Format data in \"TableModel way\"</li>\n<li>Create TableModel</li>\n</ul>\n\n<p>Let's create a class to get data. I don't like the idea of let other classes deal with o...
{ "AcceptedAnswerId": "30335", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T21:06:11.357", "Id": "30330", "Score": "5", "Tags": [ "java", "swing", "jdbc" ], "Title": "Table model code style" }
30330
<p>I am implementing an <a href="http://msdn.microsoft.com/en-us/library/System.Collections.IEqualityComparer.aspx" rel="nofollow">IEqualityComparer</a> for Dictionary objects and am looking for input on a couple of different approaches. I define equality in this case to be that both dictionaries contain the same set o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T21:35:35.837", "Id": "48205", "Score": "3", "body": "I think [Programmers](http://programmers.stackexchange.com/) would be a better fit for this question." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-...
[ { "body": "<p>A 32-bit hash returned by <code>GetHashCode</code> has 2^32 possible values, with a probability distribution dependent on the hashing function. If there are more than 2^32 possible input values then you will get collisions (see <a href=\"http://preshing.com/20110504/hash-collision-probabilities\"...
{ "AcceptedAnswerId": "30339", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T21:13:44.653", "Id": "30332", "Score": "-1", "Tags": [ "c#", ".net", "hash-map" ], "Title": "Proper way to compare two Dictionaries" }
30332
<p>I'm rewriting an old Swing project that I did a few months ago, a fairly simple copy-cat of MS paint. I've been doing a pretty good job of keeping the code maintainable and organized, but I've hit a wall on one class. All I need is some general tips on organization on this one class.</p> <p>The way I have my progra...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T14:10:16.043", "Id": "48274", "Score": "2", "body": "You should consider using Swing components, rather than extending Swing components. The only time you should extend a Swing component is when you want to override a method. Your...
[ { "body": "<p>+1 to <em>@Gilbert Le Blanc</em>'s comment. Creating </p>\n\n<p>I'd consider extracting out methods like <code>createOpenMenuItem()</code>, <code>createSaveMenuItem()</code>, <code>createPrintMenuItem()</code> for better readability and higher abstraction:</p>\n\n<pre><code>private JMenuItem creat...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T21:28:48.220", "Id": "30334", "Score": "3", "Tags": [ "java", "swing" ], "Title": "Custom component organization system" }
30334
<p>I got about 4 days of assembly knowledge, so I need a review on this <code>strcpy</code> function and if it can be done better (at least I have the feeling).</p> <p>Full code (with the test included):</p> <pre><code>.data s: .asciz "Hello world!" .bss .lcomm destination, 4 .text .globl main main:...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-27T16:41:20.433", "Id": "63524", "Score": "0", "body": "Why not use `loopne` instead of the jump?" } ]
[ { "body": "<p>You can use Bit Twidding Hack to determine if <code>int32</code> or <code>int64</code> has no zero bytes: <a href=\"http://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord\" rel=\"noreferrer\">http://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord</a></p>\n\n<p>If it has not you can...
{ "AcceptedAnswerId": "30348", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T00:41:49.743", "Id": "30337", "Score": "9", "Tags": [ "strings", "linux", "assembly" ], "Title": "x86 strcpy implementation" }
30337
<p>I would like to share my design of mvc via js.</p> <p>What do you think about it? I tried to not use any mvc framework but i want to get clear structure and a decoupled organisation.</p> <p>Next step for me is evaluating something like require.js to get rid of the ordering within the index file</p> <p>The code:</...
[]
[ { "body": "<p>Did you post the right code?</p>\n\n<p>What is TC.messenger?</p>\n\n<p>You pass two arguments in</p>\n\n<pre><code>XX.namespace.ContactListController = (function(contactListModel, view) \n</code></pre>\n\n<p>and you save them as members, but never use them.</p>\n", "comments": [ { ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T12:02:42.580", "Id": "30358", "Score": "1", "Tags": [ "javascript", "mvc" ], "Title": "Javascript MVC Design Feedback" }
30358
<p>This is my first JavaScript/jQuery project after having been reading and learning for a good few weeks. I am proud I have made something that at least works. However, I'm sure that my code is inefficient, and possibly more complex that it needs to be. I would appreciate any feedback on my JavaScript. What other ways...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T13:46:04.363", "Id": "48273", "Score": "0", "body": "Bug report: I notice if I start typing very fast that it will not enter my letters correctly. :)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T14...
[ { "body": "<p>While browsing the code with a first glance. 2 things come to mind:</p>\n\n<ul>\n<li>This code seems to have no Portability / re-usability</li>\n<li>why jQuery?</li>\n</ul>\n\n<p>There is no encapsulation of the code, this isn't bad since it simply works. But changing the classnames in your html i...
{ "AcceptedAnswerId": "30362", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T12:05:15.200", "Id": "30360", "Score": "6", "Tags": [ "javascript", "jquery", "html", "css", "quiz" ], "Title": "\"Guess the Brand\" game" }
30360
<p>I have an SQL Server table from which I want to extract data from one column (<code>DD</code>) and return as multiple columns.</p> <p>The data is in <code>NVARCHAR</code> and looks like:</p> <blockquote> <p><code>;&lt;b&gt;HF&lt;/b&gt;:GN;&lt;b&gt;HM&lt;/b&gt;:GTN;&lt;b&gt;HN&lt;/b&gt;:GN;&lt;b&gt;PN&lt;/b&gt;:A...
[]
[ { "body": "<p>Basically, sql is not meant to parse text. The database design is the issue here and it probably needs to be modified. Another option is to return the string to the server and do the parsing there and then make another call to sql.</p>\n\n<p>My answer is basically a copy of Andrew White's answer...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T12:06:28.813", "Id": "30361", "Score": "2", "Tags": [ "c#", "asp.net", "sql-server", "etl" ], "Title": "Extract data from one column of SQL Server table" }
30361
<p>I have the following model:</p> <pre><code>namespace Site.Models.Country { public class Country { public string CountryCode { get; set; } public string CountryName { get; set; } public string CountryUrl { get; set; } } } </code></pre> <p>In a separate model folder for a differen...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T12:25:15.277", "Id": "48257", "Score": "1", "body": "I think this is a valid question, but perhaps best suited for migration to the codereview stack exchange site." } ]
[ { "body": "<p>Unless you have several country related classes don't see the point of having a <code>Country</code> namespace.</p>\n\n<p>In case you do have several country related classes, call your namespace different so is not the same as the name of the class. </p>\n\n<p>Without knowing the rest of the class...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T12:20:25.257", "Id": "30364", "Score": "3", "Tags": [ "c#" ], "Title": "How to access and share MVC Model?" }
30364
<p>There are my shapes (for example):</p> <pre><code>public abstract class Shape { protected int _id; protected string _description; public abstract string ToXml(); } public sealed class Triangle : Shape { public int TriangleId { get { return _id; } set { _id = value; } } public string TriangleDescription ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T15:38:24.773", "Id": "48292", "Score": "2", "body": "I don't know C# much, but do you really have to redefine the getters and setters for id and description?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-...
[ { "body": "<p>Just expose the class types to the user (which they already appear to be) rather than forcing them to use a gawd-awful enum.</p>\n\n<pre><code>public class Module\n{\n public string GetXml&lt;TShape&gt;( int id ) where TShape : Shape\n { \n return DB.GetEntity( id ).ToTypedEntity&lt;TShape...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T14:47:04.817", "Id": "30370", "Score": "1", "Tags": [ "c#" ], "Title": "How to remove duplicate matching?" }
30370
<p>The code inputs an <code>int</code>, <code>n</code>, which is the number of lines to follow. Then, on each line, the first number goes to array <code>A</code>, the second to <code>B</code>, and the third to <code>C</code>. I then pass these 4 arguments to <code>sub</code> which I have no control over (in an object f...
[]
[ { "body": "<ul>\n<li><p>It's a good idea to order your STL <code>#include</code>s either alphabetically or by groups (see <a href=\"https://codereview.stackexchange.com/questions/30261/code-logicistic-and-cleanliness/30264#30264\">this</a> answer for more details). Header files should also precede STL <code>#i...
{ "AcceptedAnswerId": "30375", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T15:01:24.450", "Id": "30371", "Score": "6", "Tags": [ "c++" ], "Title": "Writing input into separate arrays and an output file" }
30371
<p>I'm being forced to use the common anti-pattern of a <code>public interface Constants</code> which many classes in this project implement. Long story short, I need to have a <code>List</code> constant which is pre-populated with values. Normally I would do this like so:</p> <pre><code>public static final List&lt;...
[]
[ { "body": "<p>Not sure I understand your specific case entirely, but couldn't you just use enums for that purpose?</p>\n\n<p>As in...</p>\n\n<p>Simple version... </p>\n\n<pre><code>public enum MyConstants {\n FOO, BAR\n}\n// use method name() to get \"FOO\" or \"BAR\"...\n</code></pre>\n\n<p>Version with act...
{ "AcceptedAnswerId": "30385", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T16:44:11.107", "Id": "30380", "Score": "7", "Tags": [ "java" ], "Title": "Initializing complex constant in Constants interface" }
30380
<p>I've implemented a Ruby version of Conway's Game of Life that functions correctly and passes all my tests. I was hoping to get some advice on how I could clean up the code for readability and efficiency.</p> <p>For anyone who doesn't know the rule to the Game of life, they are as follows:</p> <blockquote> <ul> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T09:38:33.913", "Id": "48365", "Score": "0", "body": "Ruby is the worst language for this problem." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T10:05:02.363", "Id": "48368", "Score": "0", ...
[ { "body": "<ul>\n<li>Ruby convention is to use CamelCase for Classnames (GameOfLife)</li>\n<li>Since \"size\" and \"str\" are mutably exclusive parameters, using a hash parameter here makes the API confusing</li>\n<li>Using flags like \"@test\" to define object behavior is bad style (antipattern)</li>\n<li>Ruby...
{ "AcceptedAnswerId": "30418", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T16:48:07.793", "Id": "30381", "Score": "3", "Tags": [ "ruby", "game-of-life" ], "Title": "Cleaning up code for Conway's Game of Life" }
30381
<p>I wrote up a simple averages calculator for student grades, based on <a href="http://www.reddit.com/r/dailyprogrammer/comments/1kphtf/081313_challenge_136_easy_student_management/" rel="nofollow">this</a> daily programming challenge.</p> <p>First, the script asks for the file name for the text file containing the s...
[]
[ { "body": "<p>For conciseness in Python, the key is to think in terms of applying functions using <code>map</code> and list comprehensions, rather than thinking procedurally. In this problem, it is very important to define a <a href=\"https://stackoverflow.com/questions/7716331\"><code>mean()</code></a> functi...
{ "AcceptedAnswerId": "30404", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T18:43:26.813", "Id": "30388", "Score": "2", "Tags": [ "python", "csv", "statistics" ], "Title": "Computing average grades for students in a class" }
30388
<p>I haven't understood how I can perform (and so prevent ) a Directory traversal attack thorugh php.</p> <p>Probably isn't necessary, but I ask: my script contains a multiple file upload and download, this is the script to upload:</p> <pre><code>if (isset($setting[5]) &amp;&amp; $setting[5] == 1) { $msid = $DBH-...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T18:48:02.200", "Id": "48318", "Score": "0", "body": "Do you have a page that lists all the files that can be downloaded? That's how a directory traversal attack is done, by following all the links on a page like that." }, { ...
[ { "body": "<p>It doesn't appear to be vulnerable to <a href=\"https://www.owasp.org/index.php/Path_Traversal\" rel=\"nofollow\">Path Traversal</a> as you appear to be creating your own <code>$encname</code> variable to store the file rather than directly using the filename from an untrusted source (i.e. the POS...
{ "AcceptedAnswerId": "30427", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T18:44:23.280", "Id": "30390", "Score": "1", "Tags": [ "php", "security" ], "Title": "How to perform and prevent a Directory traversal attack" }
30390
<p>I have the following controller function. What I want to do is make this function do less. Most of this code is just random checks on various things that is also done on most of my other controllers. So to prevent from consistently copying and pasting this code THAT IS NOT where the access_level_id is checked in the...
[]
[ { "body": "<p>Here it's a bit more DRY, perhaps someone else can take a crack at trying to get it DRYer:</p>\n\n<pre><code>&lt;?php\n/**\n * Content_pages::read()\n * \n * @return\n */\npublic function read(){\n # Initializes the user id with the value from the session user id if it exists. If there isn't a ...
{ "AcceptedAnswerId": "30520", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T19:11:08.263", "Id": "30391", "Score": "3", "Tags": [ "php", "codeigniter" ], "Title": "Helping to Make My Controller Function DRY" }
30391
<p>I'm working with knockout and am trying to stay true the MVVM structure and trying to make the objects have that dependency on each other.</p> <p>Model, ViewModel, Service definitions:</p> <pre><code>var App = window.App || {}; (function(ns, $, ko) { ns.Models = {}; ns.ViewModels = {}; ns.Services = n...
[]
[ { "body": "<p>This looks good me, just as it looked good for the SO reviewers.</p>\n\n<p>Some thoughts;</p>\n\n<ul>\n<li>Consider <code>'use strict';</code></li>\n<li>Consider naming your anonymous functions</li>\n<li>It is not clear how <code>SearchResultModel</code> deals with failed calls</li>\n<li><code>var...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T19:12:03.040", "Id": "30392", "Score": "2", "Tags": [ "javascript", "mvvm", "knockout.js" ], "Title": "Structuring objects for proper MVVM in Knockout" }
30392
<p>I come today with a state machine I'm currently working on.</p> <p>Problem:</p> <blockquote> <p>Given any State that the Character is in, a button press or combination of button presses can modify that state in a different way than how the initial state was entered.</p> </blockquote> <p>I've looked at several d...
[]
[ { "body": "<p>I think that you have an issue with general approach you have chosen. <code>StateManager</code> can still be improved tho.</p>\n\n<ol>\n<li><p>Use better and consistent naming. Why <code>_onCompletion</code> but <code>_nextOnComplete</code>? Why <code>_nextState</code>, but <code>_lastState</code>...
{ "AcceptedAnswerId": "30428", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T20:16:20.623", "Id": "30395", "Score": "4", "Tags": [ "c#", "delegates", "state-machine" ], "Title": "State Machine for Character" }
30395
<p>I'm designing a security camera program. Right now, I am just trying to set up the GUI before receiving. I am using Kivy since, in the future, I plan on designing some programs for Android. I really like Python, and I figured I'd start learning Kivy.</p> <p>My question is: am I building the GUI structure correctl...
[]
[ { "body": "<p><strong>tl;dr</strong>: If you are planning on adding more methods to each of these classes, then use them. If not, then don't.</p>\n\n<p>One of the first things you should check when deciding whether to use a class or not, is if the class has two or less methods, <code>__init__</code>, and anothe...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T20:53:46.687", "Id": "30396", "Score": "4", "Tags": [ "python", "gui", "user-interface", "layout", "kivy" ], "Title": "GUI layout for a security camera app" }
30396
<p>I've just launched my first project on GitHub. It's a jQuery plugin that helps create a responsive menu. It deals with interactivity (essentially using toggle and some classes), and leaves all the presentation stuff for CSS.</p> <p>Here is the basics for using the plugin:</p> <p><strong>First, create the structur...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-06T18:52:54.517", "Id": "49158", "Score": "0", "body": "Nice little plugin you got there! Representando o Brasil na net - show de bola! What happens if I were to have sub-sub-menus? IE: `<ul>\n <li>\n <ul>\n <li>\n <ul>\n <li...
[ { "body": "<p>Don't be intimidated be the size of the book, I just like to write out and explain in as much detail as possible. Well anyways, I've pretty much re-wrote the whole plugin. I've applied a more object-oriented approach and re-factored the plugin into the <a href=\"http://www.adequatelygood.com/JavaS...
{ "AcceptedAnswerId": "31022", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T21:02:15.093", "Id": "30397", "Score": "6", "Tags": [ "javascript", "jquery", "plugin" ], "Title": "jQuery plugin that helps create a responsive Menu" }
30397
<p>What might be wrong with this shared pointer? One good point of it might be, that it should handle array types correctly by default (e.g. <code>light_ptr&lt;int[]&gt;(new int[10])</code>.</p> <p><code>std::shared_ptr</code> has the advantage of being more portable. For example, <code>emscripten</code> provides an i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T22:33:21.840", "Id": "48435", "Score": "2", "body": "Writing your own shared pointer is a bad idea. It is a lot harder than you think to just get it working correctly. Optimizing is a step on top of that. But making it work should b...
[ { "body": "<p>The move assignment operator is broken:</p>\n\n<pre><code>light_ptr&amp; operator=(light_ptr&amp;&amp; rhs) noexcept\n</code></pre>\n\n<p>You over write the current members with the values from the rhs, but do not decrement the reference counter before overwriting. It might be easier to swap <code...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T21:16:57.163", "Id": "30398", "Score": "4", "Tags": [ "c++", "c++11", "reinventing-the-wheel", "pointers" ], "Title": "Yet another shared pointer" }
30398
<p>I'm new to programming, and I would like to know if this is the right way to layout code. If anyone has any tips, please share them.</p> <pre><code>import random import time def displayIntro(): print("You are in a land full of dragons. In front of") print("you are two caves. In one cave the dragon is") ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T21:47:50.627", "Id": "48335", "Score": "0", "body": "General rules for code layout in Python are stated in [PEP 8 -- Style Guide for Python Code](http://www.python.org/dev/peps/pep-0008/)." }, { "ContentLicense": "CC BY-SA 3...
[ { "body": "<p>(1) For variable and function names, <code>check_cave</code> (underscore) rather than <code>checkCave</code> (camelcase) are standard in python.</p>\n\n<p>(2) The line <code>def chooseCave</code> needs to be unindented</p>\n\n<p>(3) Your main game loop could probably be neatened up:</p>\n\n<pre><c...
{ "AcceptedAnswerId": "30932", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-28T21:34:32.180", "Id": "30400", "Score": "9", "Tags": [ "python", "beginner", "game" ], "Title": "Text-based adventure game" }
30400
<p>This first stores a string as input, loops through it to extract all of the numbers into an <code>ArrayList</code>, then prints all of these numbers along with their sum and product.</p> <p>How would I decompose this Java program into multiple methods? </p> <pre><code>public class Assignment1 { public static v...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T17:29:10.180", "Id": "48404", "Score": "2", "body": "This seems on-topic to me, as the OP is asking for help refactoring. That seems right up our alley." } ]
[ { "body": "<p>Start by separating your code into input handling, computation, and output. Each of those could have its own method(s).</p>\n\n<p>For the input, you're working too hard. The <code>java.util.Scanner</code> has methods to give you <code>int</code>s.</p>\n\n<p>Think about what the inputs and output...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T03:14:47.130", "Id": "30407", "Score": "2", "Tags": [ "java", "homework" ], "Title": "Extracting numbers from a string into an ArrayList" }
30407
<p>I am trying to write a count sort in Python to beat the built-in <code>timsort</code> in certain situations. Right now it beats the built-in sorted function, but only for very large arrays (1 million integers in length and longer, I haven't tried over 10 million) and only for a range no larger than 10,000. Additiona...
[]
[ { "body": "<p><code>min()</code> and <code>max()</code> each has to make a pass through your entire <code>unsorted_list</code>. You might do better by keeping track of your extrema while you build your <code>counts</code>, from a cache locality standpoint.</p>\n\n<p>On the other hand, it's possible that Python...
{ "AcceptedAnswerId": "30419", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T03:41:10.763", "Id": "30408", "Score": "9", "Tags": [ "python", "performance", "sorting" ], "Title": "Beating built-in timsort with own count sort function" }
30408
<p>I put together a Custom Linked List class in hopes of using it for a Talent/Skill Tree for a game. It allows for inserting nodes with <code>NSMutableDictionary</code> for Skills and Requirements along with a <code>nodeID</code> and a Boolean to see if said node is activated or not.</p> <p>I would like some feedbac...
[]
[ { "body": "<p>First, it should be noted that an <code>NSDictionary</code> can use any object as it's key (as long as it conforms to NSCopying protocol), as such, your <code>setValue:forKey:</code> methods should probably be rewritten to take <code>id</code> as the <code>key</code> argument type, rather than <co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T04:33:30.977", "Id": "30410", "Score": "2", "Tags": [ "objective-c", "linked-list", "binary-search" ], "Title": "Custom linked list class" }
30410
<p>This changes the application's volume through the Trackbar (1-100, 1% to 100%):</p> <pre><code>public static class NativeMethods { //Winm WindowsSound [DllImport("winmm.dll")] internal static extern int waveOutGetVolume(IntPtr hwo, out uint dwVolume); [DllImport("winmm.dll")] internal static ext...
[]
[ { "body": "<p>There isn't much to review in 6 lines of code. But oh well.</p>\n\n<ol>\n<li>Native methods return error codes, so it is good practice to handle those codes somehow, not just ignore them. For example, if method reports, that there is no sound driver or no sound card or w/e, it makes sense to notif...
{ "AcceptedAnswerId": "30430", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T05:28:29.297", "Id": "30413", "Score": "4", "Tags": [ "c#", "audio" ], "Title": "TrackBar volume control" }
30413
<p>This is a very simple anagram game that plays only with names of colors.</p> <p>I tried to focus on code design. I also wanted it to support further updates. But, my <code>init</code> seems smelly and you will notice it, especially in the main loop.</p> <p>I was wondering about my naming and commenting/docstring...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T07:31:17.227", "Id": "48359", "Score": "4", "body": "Instead of shortened variable names (\"rword\"), you would be wise to use full names to improve clarity and do away with unneeded comments. So, use variable names such as \"random...
[ { "body": "<p>In your <code>__init__()</code> function, you have defined <code>words</code> as a parameter but you are assigning <code>None</code> to <code>_words</code></p>\n\n<p>class AnagramGame:</p>\n\n<pre><code>def __init__(self, words=None, rword=None, inp=None,\n anagram=None, is_corr_word=F...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-29T07:06:51.210", "Id": "30417", "Score": "6", "Tags": [ "python", "game", "python-3.x" ], "Title": "Simple anagram game with names of colors" }
30417