body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I just wrote a little bash script for rsync push backups of my laptop to my Synology-Diskstation at home.</p> <p>Since I am a bash beginner and don't have any experience with <code>ssh</code>, <code>rsync</code> and backups I am asking for suggestions how to improve the <em>performance</em>, <em>reliablility</em>, ...
[]
[ { "body": "<h2>DRY - Don't Repeat Yourself.</h2>\n\n<p>You repeat certain things a lot. I recommend extracting a function for your ssh commands:</p>\n\n<pre><code>function remotessh {\n echo \"Running ssh : \" + \"$@\"\n ssh -i /home/myuser/.ssh/id_rsa root@192.168.0.70 \"$@\"\n}\n</code></pre>\n\n<p>This...
{ "AcceptedAnswerId": "44530", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T08:46:17.207", "Id": "29429", "Score": "7", "Tags": [ "beginner", "bash", "linux" ], "Title": "Push backup script" }
29429
<p>I am trying to solve the <a href="http://leetcode.com/onlinejudge#question_5" rel="nofollow">Longest Palindromic Substring problem</a> on LeetCode, and I have come up with a DP solution pasted below:</p> <pre><code>public class Solution { String string; boolean[][] visited; String[][] results; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-02T13:12:39.493", "Id": "46529", "Score": "0", "body": "Also, it's probably slow because of the recursion." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-02T13:13:22.700", "Id": "46530", "Score": "...
[ { "body": "<h2>Why is it slow?</h2>\n\n<p>The input string <code>S</code> can be up to 1000 characters.</p>\n\n<p>Your DP solution considers all \\$\\mathcal{O}(|S|^2)\\$ substrings of <code>S</code> and you're checking for each of these substrings, if it is a palindrome, in linear time in terms of the length o...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-02T13:09:51.357", "Id": "29434", "Score": "3", "Tags": [ "java", "algorithm", "strings", "programming-challenge", "palindrome" ], "Title": "\"Longest Palindromic Substring\" ...
29434
<p>I've noticed that there are several ways of sending data through a TCP stream. I want to do it the fastest way in terms of latency.</p> <p>One method I became aware of is with a binary writer:</p> <pre><code>using (MemoryStream ms = PrintWindow(process)) { writer.Write((int)ms.Length); writer.Write(ms.GetB...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T17:30:28.627", "Id": "46577", "Score": "0", "body": "there are various ways of checking the incoming data. And of reading and writing.. eg readline, readexisting, read.. which all have their advantages etc.. You have not indicated h...
[ { "body": "<p>If you are looking for ways to optimize your application - you are clearly looking at the wrong place, at least in my opinion. <code>BinaryWriter</code> is a simple wrapper around actual stream. All it does is it converts simple types to byte arrays and writes those to stream. Ofc it is slower, as...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T12:16:49.390", "Id": "29440", "Score": "5", "Tags": [ "c#", "comparative-review", "stream", "tcp" ], "Title": "Sending data through a TCP stream" }
29440
<hr> <h2>here is the puzzle description</h2> <p>Your task is to decode messages that were encoded with substitution ciphers. In a substitution cipher, all occurrences of a character are replaced by a different character. For example, in a cipher that replaces "a" with "d" and "b" with "e", the message "abb" is encode...
[]
[ { "body": "<p>A tad tighter, but the same solution overall:</p>\n\n<pre><code>static class Program\n{\n static void Main()\n {\n var dict = new List&lt;string&gt; { \"hello\", \"there\", \"yello\", \"thorns\" };\n var listEncryptedSentences = new List&lt;string&gt; { \"12334 51272\", \"12334...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T12:46:11.037", "Id": "29443", "Score": "2", "Tags": [ "c#", "design-patterns", "cryptography" ], "Title": "Better ways of solving the substitution cipher puzzle" }
29443
<p>In the book <code>Clean Code</code> from Robert C. Martin are given many recommendations. Two of them are </p> <ul> <li>to keep functions small and </li> <li>within a function to only have one level of abstraction. </li> </ul> <p>I already cleaned the following method up a bit by extracting a few methods (<code>Re...
[]
[ { "body": "<p>First of all, each condition and formatting will be moved to your own class. Let's create a common interface:</p>\n\n<pre><code>interface FormattingRemover\n{\n bool Match(string value);\n string RemoveFormat(string value);\n}\n</code></pre>\n\n<p>Now we can use it to abstract the formatting...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T12:46:22.490", "Id": "29444", "Score": "7", "Tags": [ "c#" ], "Title": "Small function and level of abstraction - clean code - refactor further" }
29444
<p>It simply searches for an empty row in a given destination. If it is empty, it performs certain actions (copying, pasting, etc.). If it is not empty, it goes to another row. I managed to do it with dozens of <code>If</code> formulas, but doing it in such a way seems really ineffective. Moreover, doing it in such ...
[]
[ { "body": "<pre><code> If Worksheets(Cells(x, \"P\").Value).Cells(Cells(x, \"Q\").Value + 4, \"C\") = \"\" Then\n Worksheets(Cells(x, \"P\").Value).Cells(Cells(x, \"Q\").Value + 4, \"A\").Resize(, 10).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove\n Range(\"F\" &amp; x, \"H\" &amp; x).C...
{ "AcceptedAnswerId": "29488", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T14:10:02.143", "Id": "29450", "Score": "7", "Tags": [ "performance", "vba", "excel" ], "Title": "Searching for an empty row in a given destination" }
29450
<p>The following code works but is slow and I know can be better, just don't understand how to make it work. The end result is displaying the actual driving distance from the users current location to multiple locations (I'm only including two end locations here to try and save space). This way they can see which locat...
[]
[ { "body": "<p>Finally figured it out! By doing this, in my application code, I was able to reduce the number of AsyncTask class lines from nearly 400 to 100.</p>\n\n<p>Here's the adjusted code for anyone interested. I'm only including the relevant parts for the sake of saving space.</p>\n\n<p><strong>No changes...
{ "AcceptedAnswerId": "29559", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T14:32:27.703", "Id": "29453", "Score": "1", "Tags": [ "java", "android", "asynchronous" ], "Title": "Can these async tasks be merged together?" }
29453
<p>I am working on a C#.Net application that will generate an Excel report from a template. Although the code's not in the app yet, it will pull data from a SQL Server database to populate the report.</p> <p>I am asking for help in reviewing my class design. My code is below, with some details of the functions remov...
[]
[ { "body": "<p>Although arguably a Pandora's box of other complications, have you considered ditching the Interop libraries and driving this through Ace/Jet drivers via OleDB? Too often do I see well-intentioned applications fall over because Excel gets upgraded. Best-case scenario you'll have to manage multip...
{ "AcceptedAnswerId": "29774", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T15:03:01.383", "Id": "29454", "Score": "2", "Tags": [ "c#", "object-oriented", "excel" ], "Title": "Class design - Excel report" }
29454
<p>I am looking for feedback on a solution to the following problem posed from a book that I'm working through (<em>Java: How To Program</em> 9th Edition):</p> <blockquote> <p>Continuing the discussion in Exercise 16.20, we reiterate the importance of designing check-writing systems to prevent alteration of chec...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T15:58:10.613", "Id": "46569", "Score": "0", "body": "Check out this Stack Overflow answer: http://stackoverflow.com/a/3911982/300257" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-29T08:13:45.333", ...
[ { "body": "<p>Yes! Your code is more complicated than it needs to be.</p>\n\n<ul>\n<li>You treat the String as a String instead of first parsing it as a number and treating it as a number. It is more complicated to treat chars than numbers when you want to use them as numbers.</li>\n<li>You have some code dupli...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T15:24:17.587", "Id": "29457", "Score": "6", "Tags": [ "java", "beginner", "recursion", "converting", "numbers-to-words" ], "Title": "Writing the word equivalent of a check...
29457
<p>Please criticize the <code>MatrixNotThreadSafe</code> class and other classes. How can I improve the design of the Matrix interface? How can I make the classes and tests clearer?</p> <p><a href="https://github.com/Leonideveloper/Matrix/tree/master/Matrix/src/com/gmail/leonidandand/matrix" rel="nofollow">Code on Git...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T17:57:04.527", "Id": "46585", "Score": "1", "body": "My biggest issue is that it does not do anything useful yet. The proof is in the pudding. You cannot add or multiply two of them. You cannot invert one. I know some people advocat...
[ { "body": "<p><strong>Position</strong></p>\n\n<ul>\n<li>While it implements <code>equals()</code> it doesn't implement <code>hashCode()</code>. It should.</li>\n<li>The <code>equals()</code> method could start with a test : <code>if (this == obj) { return true; }</code> While this isn't strictly necessary it c...
{ "AcceptedAnswerId": "29466", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T15:28:22.473", "Id": "29458", "Score": "2", "Tags": [ "java", "thread-safety", "matrix" ], "Title": "Thread-safety of Matrix class" }
29458
<p><a href="https://en.wikipedia.org/wiki/Grading_%28education%29" rel="nofollow">For anyone who's unfamiliar with this grading system</a>.</p> <p>I'd like a general review of my code, and I have a few questions:</p> <ol> <li>Are plain types okay for the letter grades and credit hours, or could they be <code>public</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T17:48:29.800", "Id": "46583", "Score": "0", "body": "with deciding to make letter grades and credit hours public, I would ask, what advantage is there to making them public? But what are the disadvantages, weighed against the limit...
[ { "body": "<p>Note that I am completely unfamiliar with the american(?) grade system and GPAs -- I am reviewing the coding style and approach, not whether or not the solution is correct.</p>\n\n<h3>General notes:</h3>\n\n<ul>\n<li><p><strong>Your</strong> <code>GPA</code> <strong>class is not really a class.</s...
{ "AcceptedAnswerId": "29465", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T16:59:24.750", "Id": "29462", "Score": "3", "Tags": [ "c++" ], "Title": "Grade point average (GPA) calculator" }
29462
<p>I am trying to learn some basic Python and am trying to find tricks to write speedy code:</p> <pre><code>import sys if len(sys.argv) &lt; 3: print("You left out the arguments") sys.exit() gcf = 0 numbers = [] collections = [] unique = False for i in range(1,len(sys.argv)): numbers.append(int(sys.argv[...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T17:59:28.127", "Id": "46587", "Score": "0", "body": "does this code work? I don't understand what yr trying to acheive here for i in collections[0]:\n for x in collections:\n if i in x:" }, { "ContentLicens...
[ { "body": "<p>You have written that you want to know tricks for writing speedy code. So I'll leave the algorithm as it is.</p>\n\n<p>You should know that <a href=\"https://stackoverflow.com/questions/11241523/why-does-python-code-run-faster-in-a-function\">Python code runs faster in local scope than global scop...
{ "AcceptedAnswerId": "29498", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T17:42:27.883", "Id": "29464", "Score": "3", "Tags": [ "python", "performance" ], "Title": "Simple GCF calculator app" }
29464
<p>I'm working on a general <code>Requestmethod</code> class which sanitizes and recasts the input of users in an automatic fashion. I've also tried to do array-access in cookies.</p> <p>My biggest question are:</p> <ol> <li>Is this too much for one class alone?</li> <li>Is the readability/thinking right on this?</li...
[]
[ { "body": "<p>Right, let me be clear, I mean this in the nicest of ways, but I don't like this code one bit. Let me start off a couple of simple things:</p>\n\n<p>Please, follow the coding standards as described by <a href=\"http://www.php-fig.org/psr/1/\">PHP-FIG</a></p>\n\n<p>I've noticed you're (ab)using the...
{ "AcceptedAnswerId": "29485", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T20:10:10.167", "Id": "29469", "Score": "9", "Tags": [ "php", "object-oriented", "classes" ], "Title": "Critique Request: PHP Request-Method Class" }
29469
<p>I've written a small code snippet that generates checkboard texture using cl-opengl.</p> <pre><code>(defun init-texture (tex) (gl:bind-texture :texture-2d tex) (gl:tex-parameter :texture-2d :texture-min-filter :nearest) (gl:tex-parameter :texture-2d :texture-mag-filter :nearest) (print *test-texture...
[]
[ { "body": "<p>Not much better:</p>\n\n<pre><code>(defun init-texture (tex &amp;aux (tex-w 16) (tex-h 16) (pixel-size 4))\n (gl:bind-texture :texture-2d tex)\n (gl:tex-parameter :texture-2d :texture-min-filter :nearest)\n (gl:tex-parameter :texture-2d :texture-mag-filter :nearest)\n (print *test-texture*)\n ...
{ "AcceptedAnswerId": "29472", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T20:11:12.513", "Id": "29470", "Score": "1", "Tags": [ "common-lisp", "opengl" ], "Title": "common lisp: nested loop beautification (checkboard texture generator)" }
29470
<p>The following code takes a string and converts it to it's number equivalent. A=1 ... Z=26, while keeping all other characters intact. It formats the string using two delimiters. One for between characters and one for between words. I want to optimize it, and have fixed a lot of redundancy, and slow parts. However, I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T05:19:45.690", "Id": "46639", "Score": "0", "body": "\"Sub is called the same amount of times either way\". Um, no. Try removing the call outside the loop. BTW, the table length call in the for loop is evaluated only once." }, ...
[ { "body": "<p>Your code is a bit is overcomplicated. There are a million ways to skin this cat, but I'll show a few. They're all about twice as fast as your code on my machine:</p>\n\n<p>The most concise would be to let Lua do most of the parsing for us. We'll first chop the string into words, then chop each wo...
{ "AcceptedAnswerId": "29473", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-06T20:57:20.057", "Id": "29471", "Score": "6", "Tags": [ "parsing", "lua" ], "Title": "Lua string parsing" }
29471
<p>I have implemented the following code which will be used to read in what are essentially key-value pairs from a file.</p> <p>an example input file may look like</p> <pre><code>max_search_depth 10 enable_recursion false job_name Khalessi </code></pre> <p><strong>my main issue with this code</strong> is that I wish...
[]
[ { "body": "<p>There's quite a bit to comment on here, however, it's late, so I'm going to post a solution to your problem, and then try and quickly explain it. Hopefully I can edit this post with more details soon.</p>\n\n<p>Crux of the solution: there are two major problems here. Firstly, the keys are not stor...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T01:09:41.627", "Id": "29474", "Score": "5", "Tags": [ "c++" ], "Title": "Trying to find a good design for reading in values of different types from a file" }
29474
<p>I have written the script, which unzips a zip file (passed as argument to the bash), loops through directory and files, then perform different actions based on directory or file. It is working fine.</p> <p>However I would like to know some things:</p> <ol> <li>Is it possible to do this without the unzip command? I...
[]
[ { "body": "<ol>\n<li><p>There's no documentation. Even a comment at the top of the script summarizing what it does would be better than nothing.</p></li>\n<li><p>There's no error handling. What if the user forgets the argument?</p></li>\n<li><p>This script will break if the argument <code>$1</code> contains a s...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T03:20:31.417", "Id": "29477", "Score": "1", "Tags": [ "bash" ], "Title": "script- loop through files and directories" }
29477
<p>All this code does is transfer the files. In order to make changes to the file, one has to re-transfer the file. During this time, I stand by to automate the update operation, where the server listens to the files and updates them automatically whenever any changes are made.</p> <pre><code>fileserver.java import ...
[]
[ { "body": "<p>Your socket communication protocol is asymmetrical..... the client-side cannot correctly send files larger than 2GB (though the server side looks like it can handle it).</p>\n<p>Additionally, your client-side code reads the entire file in to memory.... which is wasteful and unnecessary.</p>\n<p>Us...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T04:09:31.117", "Id": "29478", "Score": "4", "Tags": [ "java", "socket" ], "Title": "Transfer log file between client and server while updating files automatically" }
29478
<p>I have a <code>Customer</code> class that has the code below. I can refactor the two if condition clauses into the <code>Memebership</code> class. Apart from that, I am wondering how I should refactor the if clause within the <code>Benefits</code> set property, without over-complicating thing.</p> <p>Does any one o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-01T20:04:38.113", "Id": "46618", "Score": "1", "body": "I'd be wary of this initial design from the get-go. That's all fine because you're asking about re-factoring, but the general consensus is that properties shouldn't really have a...
[ { "body": "<p>Personally here's what I would do :</p>\n\n<p>Use the Membership type to create derived class; this will remove the if chain completely.\nAvoid side effects in setters; bad practice in my opinion.\nAvoid using properties with private sets; bad practice in my opinion.</p>\n\n<p>This results in the ...
{ "AcceptedAnswerId": null, "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-01T20:02:06.237", "Id": "29479", "Score": "1", "Tags": [ "c#", "design-patterns" ], "Title": "Refactoring If clause" }
29479
<p>I want to create an like button like on Twitter. I used Twitter bootstrap and this code:</p> <pre><code>$(document).ready(function(){ $('.btn-follow').on('mouseover', function(e){ if ($(this).hasClass('following')){ $(this).removeClass('btn-primary').addClass('btn-danger').text('UnFollow'); } }) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T17:04:17.357", "Id": "46674", "Score": "0", "body": "Care to add what *bugs* you are experiencing? That would speed up answering..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T00:16:13.700", "...
[ { "body": "<p>I reworked the code a bit. Check out the comments for explanation. </p>\n\n<pre><code>$(document).ready(function() {\n //Don't copy and paste the same string.\n //It is also helpful when the CSS or text changes. There is just one part\n //of the code to look at.\n var followBtn = $('.btn-foll...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T08:30:45.317", "Id": "29486", "Score": "3", "Tags": [ "javascript", "jquery", "html", "twitter-bootstrap" ], "Title": "Follow button like on Twitter" }
29486
<pre><code>if ((key == null &amp;&amp; group.Key == null) || (key is DBNull &amp;&amp; group.Key is DBNull) || (!(key is IComparable) &amp;&amp; !(group.Key is IComparable))) </code></pre> <p>Can the above code simplified like below,</p> <pre><code>if(key == group.key || (!(key is IComparable) &am...
[]
[ { "body": "<p>No, not unless you restrict what values the variables can have, or what type they are declared as.</p>\n\n<p>If for example <code>key</code> is an <code>int</code> with the value <code>4</code> and <code>group.Key</code> is an <code>int</code> with the value <code>4</code>, the first code gives <c...
{ "AcceptedAnswerId": "29490", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T09:48:55.937", "Id": "29489", "Score": "-2", "Tags": [ "c#" ], "Title": "IComparable comparision" }
29489
<p>The following is a code written in Javascript. It let's me change the appearance of a canvas depending on user input. The question is, how can I make this code more CPU efficient? I ask that because this code is just barely snappy enough on the iPad 2 and any improvement in speed would be really great to have.</p> ...
[]
[ { "body": "<p>The short answer is that you can't, not really anyways. You have no real control over how this code will be compiled. Since you mention iPad, the code is likely to be JIT-compiled to bytecode, prior to execution. How this is done depends (in part) on how the code is written, and <em>how JS is impl...
{ "AcceptedAnswerId": "29496", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T14:08:52.620", "Id": "29494", "Score": "2", "Tags": [ "javascript", "performance", "ios", "canvas" ], "Title": "Drawing to a canvas based on user input" }
29494
<p>The function <code>hash_blog</code> is inspired by <a href="http://git-scm.com/book/en/Git-Internals-Git-Objects" rel="nofollow">"how git stores its objects"</a>. It is supposed to take a <code>String</code>, append a header to it, compute the SHA1 of it, then compress it and write it to a file. The first two charac...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T17:57:11.133", "Id": "46678", "Score": "0", "body": "Beginning to learn the language or beginning to learn Object Oriented programming as well?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T18:02:44...
[ { "body": "<p><strong>Problems</strong> :</p>\n\n<ul>\n<li>methods mkdirs() and createNewFile() return booleans to indicate whether they are successful. You should check and handle if they return false.</li>\n<li>IOException gets ignored, you print the stacktrace but clients have no way of knowing the method fa...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T17:29:01.300", "Id": "29501", "Score": "3", "Tags": [ "java", "io", "cryptography" ], "Title": "File I/O, SHA1 sum and compression" }
29501
<p>I recently set out to create an open-source ASP.net MVC web development framework. Specifically, I wanted to automate some of the tasks associated with the creation of data-driven applications. I've had to create a number of CRUD screens over the years and wanted to automate as many aspects of these screens as pos...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T19:49:13.707", "Id": "46687", "Score": "0", "body": "It would help us if you gave a class that actually inherits from this." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T22:39:45.343", "Id": "46...
[ { "body": "<p>This switch should be an if statement instead.</p>\n\n<blockquote>\n<pre><code> if (input == null) // we didn't get an input from GetCustomEditorInput\n {\n switch (property.PropertyType.Name)\n {\n case \"Boolean\":\n input = n...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T18:11:13.060", "Id": "29502", "Score": "11", "Tags": [ "c#", ".net", "asp.net", "asp.net-mvc-4", "controller" ], "Title": "Generic ASP.NET MVC controller that generates ma...
29502
<p>I have a form that I'm turning into a string value for an email, but the string value that I turn it into seems very complicated, plus I believe this way takes up a lot of memory and is somewhat slow as well. Is there any other way to make a NSString with many arguments besides using <code>[NSString stringWithFormat...
[]
[ { "body": "<p>You could use <code>NSMutableString</code>. It has <code>appendString</code> method which you could use to create string by appending other strings.\nFor example: </p>\n\n<pre><code>NSMutableString *mutableString = [NSMutableString stringWithFormat:@\"%@\", someString];\n[mutableString appendStrin...
{ "AcceptedAnswerId": "29622", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T18:52:21.987", "Id": "29503", "Score": "2", "Tags": [ "strings", "objective-c" ], "Title": "Is there a better way of making an NSString with many argument values?" }
29503
<p>I wrote this <code>with-input-from-pipe</code> function for Guile. I’m not that comfortable with <code>dynamic-wind</code> or <code>set-current-input-port</code>, so I’d appreciate any critiques.</p> <pre><code>(use-modules (ice-9 popen) (srfi srfi-26)) (define (with-input-from-pipe command thunk) (...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T19:50:36.157", "Id": "29505", "Score": "2", "Tags": [ "scheme" ], "Title": "A with-input-from-pipe for Guile" }
29505
<p>The goal is to have a <code>DataGrid</code> of comboboxes, 10 rows, 3 columns.</p> <p>Here's the XAML to create said grid:</p> <pre class="lang-xaml prettyprint-override"><code>&lt;DataGrid Name="grid1" AutoGenerateColumns="False"&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTemplateColumn Head...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T05:46:49.380", "Id": "46701", "Score": "1", "body": "What is your problem exactly? Please add more context. Is there a reason, you use strings? Is there a reason you use observable collections? Are those collections supposed to be u...
[ { "body": "<p>If your items in the ComboBox are static, you don't need binding at all.</p>\n\n<pre><code>&lt;DataGridTemplateColumn Header=\"Product\"&gt;\n &lt;DataGridTemplateColumn.CellTemplate&gt;\n &lt;DataTemplate&gt;\n &lt;ComboBox&gt;\n &lt;ComboBoxIte...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T21:09:14.687", "Id": "29507", "Score": "4", "Tags": [ "c#", "wpf" ], "Title": "Populating a datagrid of comboboxes" }
29507
<p>I'm working on an old PHP website, and NetBeans is complaining about an uninitialized variable. I'm seeing some code like this:</p> <pre><code>$app-&gt;soapAPIVersion($apiVersion); $_SESSION['apiVersion'] = $apiVersion; </code></pre> <p>The function looks something like this:</p> <pre><code>function soapAPIVersio...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-14T06:54:17.147", "Id": "82548", "Score": "0", "body": "While I agree with the advice to refactor and avoid the reference, *sometimes* you have no choice (e.g. the built-in function `preg_match`). Yes, this is a [bug in NetBeans](https...
[ { "body": "<ol>\n<li><p><em>Clean Code, Chapter 3. Functions</em> has some guidance:</p>\n\n<blockquote>\n <p><strong>Have No Side Effects</strong></p>\n \n <p>Side effects are lies. Your function promises to do one thing, but it also does other hidden\n things.</p>\n \n <p>[...]</p>\n \n <p>Anything th...
{ "AcceptedAnswerId": "29517", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T23:25:06.957", "Id": "29511", "Score": "5", "Tags": [ "php", "php5" ], "Title": "Initializing a variable with a function reference (PHP)" }
29511
<p>I am hoping someone can help me attain better performance and better ways of writing this script. Any help would be awesome!</p> <p><strong>Overall Goal:</strong> I have a dropdown that allows someone to select an option from it. It will add that record to the table below, and then the option will be removed. If...
[]
[ { "body": "<ul>\n<li><p>Your indentation is a little funky. I can understand not indenting after <code>$(function () {</code> (though I would do so myself), but the <code>change</code> handler's body really should be indented</p></li>\n<li><p>You've got everything in one function, though it'd probably be more r...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T00:01:48.993", "Id": "29512", "Score": "2", "Tags": [ "javascript", "optimization", "jquery" ], "Title": "Recording options selected from dropdown menu" }
29512
<p>How could this scala code be made more concise and/or idiomatic? Do I need to define each functions as a <code>val</code> in order to pass them as values, or is there a shorthand for this? Also looking for feedback on the <code>disenvowel</code> function.</p> <pre><code>// See: http://nurkiewicz.blogspot.com/2012...
[]
[ { "body": "<p>Depending on the function definition, you can do this inline using a function literal (which is basically a lambda):</p>\n\n<pre><code>transformString(\"blah\", List(s =&gt; s.toUpperCase, s =&gt; s.reverse))\n</code></pre>\n\n<p>In fact, you can make this even more concise using <code>_</code>:</...
{ "AcceptedAnswerId": "29547", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T06:09:27.677", "Id": "29516", "Score": "4", "Tags": [ "scala" ], "Title": "Improve scala functional string transformation" }
29516
<p>I have a Java/Swing/Guice application that uses multiple frames. When the application runs normally, I just want some of these frames to hide (and the "master" frame can unhide them).</p> <p>When testing the view, I have various other <code>main</code> methods that can open just one frame, and perhaps populate them...
[]
[ { "body": "<p>The <code>Closer</code> class and its <code>setCloser</code> method does not close anything so I'd rather call it <code>CloseOperationProvider</code>. I guess you could get rid of it and annotate the <code>setCloser()</code> parameter instead:</p>\n\n<pre><code>@Inject(optional = true)\nprivate vo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T14:44:43.757", "Id": "29520", "Score": "3", "Tags": [ "java", "unit-testing", "swing", "dependency-injection", "guice" ], "Title": "Guice custom behavior for testing" }
29520
<p>I am quite new to Java, and I am trying to read a file into a string (or should I use byte arrays for this?). File can be anything, such as a text file or executable file etc. I will compress what I read and write it to another file.</p> <p>I am thinking of using this code:</p> <pre><code>public static String read...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T17:42:59.440", "Id": "46720", "Score": "0", "body": "I would suggest that you read this : http://stackoverflow.com/questions/3402735/what-is-simplest-way-to-read-a-file-into-string-in-java" }, { "ContentLicense": "CC BY-SA 3...
[ { "body": "<p>Why reinvent the wheel? </p>\n\n<p>Use <a href=\"https://commons.apache.org/proper/commons-io/download_io.cgi\" rel=\"nofollow\">commons-io</a>'s <code>FileUtils.readFileToByteArray(File)</code><a href=\"https://commons.apache.org/proper/commons-io/javadocs/api-2.4/org/apache/commons/io/FileUtils....
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T17:02:21.517", "Id": "29521", "Score": "4", "Tags": [ "java", "beginner", "io" ], "Title": "Reading a file into string in Java" }
29521
<p>I'm not so good with recursion, so I've decided to tackle an exercise consisting of drawing this pattern using characters:</p> <pre><code> * *** ***** ******* ********* *********** ************* *********** ********* ******* ***** *** * </code></pre> <p>Here is my code so f...
[]
[ { "body": "<p>My few cents,</p>\n\n<ol>\n<li>Probably this is not the best exercise for recursive coding.</li>\n<li>the caller should not have to know about the middle parameter, ideally it would just be <code>Main.drawDiamond(\"*\", 5 );</code></li>\n<li><code>seed += \"**\";</code> this should use the seed, w...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T17:40:40.790", "Id": "29523", "Score": "7", "Tags": [ "java", "algorithm", "recursion" ], "Title": "Attempt at method to draw diamond (recursive or not ?)" }
29523
<p>Would the following be considered idiomatic Go code?</p> <p>My main concerns are:</p> <ol> <li><p>The use of maps for this purpose. I basically want the data structure to be completely dynamic in size and have easy access to elements by id. This is because I will want to retrieve specific items on demand lots of...
[]
[ { "body": "<p>Instead of </p>\n\n<pre><code>i, ok := this.BoxItems[id]\nif ok {\n i.Qty += qty\n} \n</code></pre>\n\n<p>a more idiomatic usage is </p>\n\n<pre><code>if i, ok := this.BoxItems[id]; ok {\n i.Qty += qty\n} \n</code></pre>\n\n<p>Calling the receiver <code>this</code> doesn't seem like a good p...
{ "AcceptedAnswerId": "29525", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T18:09:11.500", "Id": "29524", "Score": "4", "Tags": [ "go" ], "Title": "Box data structure in Go" }
29524
<pre><code>public static bool IsAnagramOf(this string word1, string word2) { return word1.OrderBy(x =&gt; x).SequenceEqual(word2.OrderBy(x =&gt; x)); } public static void Main() { Console.SetIn(new StreamReader(Console.OpenStandardInput(8192))); string test = Console.ReadLine(); string[] split = test...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T22:42:28.873", "Id": "46733", "Score": "0", "body": "I really don't see how could this have too high memory footprint. I think you need to include some more details." } ]
[ { "body": "<p>Not sure what memory issue you're having with this, but there is a simpler way to write this, since you're already employing LINQ:</p>\n\n<pre><code>private static bool IsAnagramOf(this string word1, string word2)\n{\n return word1\n .OrderBy(x =&gt; x)\n .SequenceEqual(word2.Orde...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T18:20:16.050", "Id": "29527", "Score": "2", "Tags": [ "c#", "linq", "memory-management" ], "Title": "Reducing memory footprint in anagram-finding program for text" }
29527
<p>I have this code snippet below that I am looking for a way to make smaller if possible. Any help or suggestions would be appreciated, thanks!</p> <pre><code>Private Sub ShowAlternateRows(Show As Boolean) If Show = True Then splitter.Visible = True lblAlternateActualPercent.Visible = True ...
[]
[ { "body": "<p>Assuming <code>OPTION STRICT OFF</code> (since I don't know the type of <code>Grid.Cols.Item</code>):</p>\n\n<pre><code>Private Sub ShowAlternateRows(show As Boolean)\n Dim grpShow = \n {\n splitter, lblAlternateActualPercent, \n lblAltEstimated, lblStaticAltEstimated, \n ...
{ "AcceptedAnswerId": "29646", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T22:03:40.497", "Id": "29535", "Score": "2", "Tags": [ "vb.net" ], "Title": "Better Way to Show and Hide Items in Project" }
29535
<p>Here's a Python script to optimize JSON documents:</p> <pre><code>#!/usr/bin/python3 """jopo - Optimize JSON documents.""" from collections import defaultdict def optimize(data): """Optimize a JSON-like data structure.""" if isinstance(data, list): if len(data) == 1: return optimize(...
[]
[ { "body": "<pre><code> digest = defaultdict(lambda: defaultdict(set))\n</code></pre>\n\n<p>It's pretty rare that we have a good reason for such a nested data structure in python.</p>\n\n<pre><code> for element in data:\n if not isinstance(element, dict) or len(element) != 2:\n break\n ...
{ "AcceptedAnswerId": "29542", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-08T22:28:10.160", "Id": "29536", "Score": "2", "Tags": [ "python", "json" ], "Title": "Critique my JSON-optimizing Python script" }
29536
<p>I want to display a town name in my navigation, depending on the town I am requesting from the model. The following code works, but I am mixing logic in my view which I know is wrong and I haven't been successful in accessing the <code>@town</code> instance variable from my <code>TownsController</code>.</p> <p>Can ...
[]
[ { "body": "<p>Is _header.html.erb part of the layout? If so, i would advice you to move this logic to helper, if not all the controllers would need to set the @towns instance variable.</p>\n\n<pre><code>module ApplicationHelper\n def town_names\n Town.all.collect(&amp;:name)\n end\nend\n</code></pre>\n\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T00:15:37.877", "Id": "29538", "Score": "1", "Tags": [ "ruby", "ruby-on-rails", "erb" ], "Title": "Moving instance variable from partial to helper" }
29538
<p>I have done some tests of my code, which I got help to improve here before. The code simply takes a screenshot of a selected process window, encodes it to JPEG (if I want), saves it to a <code>memorystream</code> and returns it (necessary for sending it).</p> <p>My test simply runs the code 1000 times, and posts t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T17:18:32.410", "Id": "46761", "Score": "0", "body": "What are you building? Why is it not enough for you for a screenshot to take on the order of tens of ms? Perhaps use a highly optimized system tool written in C that can grab the ...
[ { "body": "<p>Well, first of all, what you call \"the little jump\" is not that little. You can easily devide <code>1152x864</code> by <code>800x600</code> for yourself and see, that it, surprisingly enough, equals <code>2</code>. Which means, that your algorithm most likely has a complexity of <code>O(n)</code...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T08:36:19.093", "Id": "29548", "Score": "3", "Tags": [ "c#", "performance", "image" ], "Title": "Encoding a screenshot to JPEG and saving it to a memorystream" }
29548
<p>I'm doing an exercise where I need to convert <code>int</code> to <code>bignum</code> in OCaml, for example:</p> <blockquote> <pre><code>123456789 -&gt; {neg:false; coeffs:[123;456;789]} </code></pre> </blockquote> <p>There were a lot of things going inside my head when writing the function, and it was a load of f...
[]
[ { "body": "<p><code>num==0</code> is misleading, use <code>num=0</code> (although it has the same meaning for integers). Also, <code>fromInt</code> is spread over too many lines for my taste, I'd prefer the following choice of line breaks:</p>\n\n<pre><code>let fromInt (n: int) : bignum =\n let rec aux num : i...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T09:16:12.867", "Id": "29549", "Score": "2", "Tags": [ "functional-programming", "ocaml" ], "Title": "Functional Programming: int to bignum conversions" }
29549
<p>First off, I know there are other solutions and practices but I'm referring to MS proposed code from .NET documentation.</p> <p>It goes like this:</p> <pre><code>client.Connect(anEndPoint); bool blockingState = client.Blocking; try { byte [] tmp = new byte[1]; client.Blocking = false; client.Send(tmp...
[]
[ { "body": "<p>First off, I'm not an expert about TCP and Sockets, though I have had some experiences in the past.</p>\n\n<blockquote>\n <p>My problems is that on some occasions it detects disconnect where server does not, so on server I have connection left hanging while client reconnects.</p>\n</blockquote>\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T10:19:20.077", "Id": "29550", "Score": "2", "Tags": [ "c#", ".net", "socket", "tcp" ], "Title": "Detecting socket disconnect in .NET" }
29550
<p>I have an Eclipse plugin which creates a <code>JavaSourceViewer</code> to visualize specific source code in a separate view. I would like to configure the font of the viewer to match the settings of the <em>Java Editor Text Font</em> preference:</p> <pre><code>JavaSourceViewer textViewer = new JavaSourceViewer(...)...
[]
[ { "body": "<p>I'm not familiar with Eclipse plugin development, so just two minor notes after going through javadoc of the relevant APIs:</p>\n\n<ol>\n<li><p><a href=\"http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/jface/resource/FontRegistry.html\" rel=\"nofollow\">...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T13:24:47.657", "Id": "29554", "Score": "3", "Tags": [ "java", "eclipse" ], "Title": "Retrieving font preference setting in Eclipse JDT plugin" }
29554
<p>I am building a PHP framework and would like to get some feedback on a few different sections of the project so far. I consider myself still a neophyte in PHP so I would like to ask if I'm going about completing these different tasks in an efficient and or correct way. </p> <p>This section is of the MySQL database ...
[]
[ { "body": "<p>Always think this: everything you code must solve some kind of problem.\nIf it doesn't solve a problem. Remove it.</p>\n\n<p>Now by looking at your code I think you are trying to solve two problems being:</p>\n\n<ol>\n<li>Handling of multiple connections</li>\n<li>Caching query results for later u...
{ "AcceptedAnswerId": "29560", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T13:38:56.123", "Id": "29555", "Score": "3", "Tags": [ "php", "design-patterns", "mysql" ], "Title": "PHP framework building: Database Control Classes" }
29555
<p>I'm looking to let people define arbitrarily nested lists of lists and return a random json document for them. Right now the assumption is that if you have a structure like this:</p> <pre><code>[item1, item2, [item3, item4]] </code></pre> <p>The desired document is:</p> <pre><code>{item1: value, item2: { item...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T14:37:49.763", "Id": "46753", "Score": "0", "body": "Your understanding of elegant code is so different, that I can't improve your solution. However, variable named 'type' is not a good idea, because it shadows built-in function typ...
[ { "body": "<p>The only idea, which comes to my mind, is to replace</p>\n\n<pre><code>for i in range(len(document)-1)\n</code></pre>\n\n<p>with </p>\n\n<pre><code>for (l, l1) in zip(document, document[1:])\n# or izip from itertools\n</code></pre>\n\n<p>to get pairs of consecutive items.</p>\n", "comments": [...
{ "AcceptedAnswerId": "29601", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T14:25:21.943", "Id": "29557", "Score": "3", "Tags": [ "python", "recursion", "comparative-review", "hash-map" ], "Title": "Nested array-to-dict transformation" }
29557
<p>I am quite new to <a href="http://en.wikipedia.org/wiki/Java_%28programming_language%29" rel="nofollow">Java</a>. I have data structured like this:</p> <pre><code>tree 503(there is a null character here)040000 tree 0bfec80bc7b7aa0a50e0b373044929cb0aae278b build/ 100755 blob e30876c61eb7712ad09b50593a30513d9b173805 ...
[]
[ { "body": "<p>I'll first suggest you that the raw format that you use to store your data, use a different separator than a white-space. This will simplify the code since we are sure that we have unique separator.</p>\n\n<p>Your <code>TreeEntry</code> should encapsulate his fields in getter and setter. Public fi...
{ "AcceptedAnswerId": "29570", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T18:38:53.937", "Id": "29564", "Score": "3", "Tags": [ "java", "beginner", "parsing", "tree" ], "Title": "Parsing structured text in Java" }
29564
<p>I've been working on a jQuery plugin for pulling tweets since the v1 endpoints were all closed off and you need oAuth now. This is just the jQuery part but if you want to see the php behind it I'll be happy to post. But basically, I'd love suggestions, as this is one of the first real plugins i've made, i'm really l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-16T14:56:27.087", "Id": "71914", "Score": "0", "body": "The big `if else` could be an `switch case`: http://stackoverflow.com/questions/2922948/javascript-switch-vs-if-else-if-else" }, { "ContentLicense": "CC BY-SA 3.0", "C...
[ { "body": "<p>A few minor notes:</p>\n\n<ol>\n<li><p>Comments like this:</p>\n\n<blockquote>\n<pre><code>// Creates an empty template with all present data, in order.\n$.each(tplArray, function(i, elm){\n</code></pre>\n</blockquote>\n\n<p>and this:</p>\n\n<blockquote>\n<pre><code>//Populates the template with d...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T18:43:39.477", "Id": "29565", "Score": "5", "Tags": [ "javascript", "jquery", "plugin", "twitter" ], "Title": "Plugin for pulling Tweets" }
29565
<p>I wrote the code for an iterative pre-order traversal using stack for binary search tree. Below is the code for same. Please help me verify the correctness of the algorithm. Here <code>t.t</code> is the value of node <code>t</code>.</p> <pre><code>static void preorder(TreeNode t) { MyConcurrentStack&lt;TreeNode...
[]
[ { "body": "<p>There are a few points that can be critizised.</p>\n\n<ol>\n<li><p>The method signature suggests that the architecture of the system isn't well-designed. Traversal of a Tree should likely be encapsulated in an Iterator class. In that case, the stack would be a private field of the iterator, and th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T20:25:48.943", "Id": "29568", "Score": "2", "Tags": [ "java", "algorithm", "tree" ], "Title": "Preorder traversal using stack" }
29568
<p>This code works by taking my user input and correctly pulling the information I'm giving it.</p> <p>I'm having difficulty understanding the implementation of methods in classes. I'm pretty sure I'm not doing this the correct way. Can anyone show me the way it <em>should</em> be done?</p> <pre><code>class prog_setu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-10T00:03:21.333", "Id": "46785", "Score": "0", "body": "Your indentation really should be more than 1 space each. Having it at 1 makes it unreadable. It should be at a minimum of 3 in any structured language really. Though for Python, ...
[ { "body": "<p>If you decide to implement this without using a class you can simply write:</p>\n\n<pre><code>def get_starlist():\n ...\ndef get_inputkey():\n ...\n\nif __name__ == \"__main__\":\n get_starlist()\n get_input_key()\n define_lists_and_arrays() \n determine_normalization_point()\n ...
{ "AcceptedAnswerId": "29574", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T22:34:52.747", "Id": "29571", "Score": "4", "Tags": [ "python" ], "Title": "Pulling information from user input" }
29571
<p>I am doing sentiment analysis on tweets. I have code that I developed from following an online tutorial (found <a href="http://www.laurentluce.com/posts/twitter-sentiment-analysis-using-python-and-nltk/" rel="nofollow noreferrer">here</a>) and adding in some parts myself, which looks like this:</p> <pre><code>#!/us...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-17T00:57:56.253", "Id": "57553", "Score": "0", "body": "What did you end up doing here?" } ]
[ { "body": "<p>take a look at the answers in </p>\n\n<p><a href=\"https://stackoverflow.com/questions/13610074/is-there-a-rule-of-thumb-for-how-to-divide-a-dataset-into-training-and-validatio/13623707#13623707\">Is there a rule-of-thumb for how to divide a dataset into training and validation sets?</a></p>\n\n<b...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-09T23:28:17.073", "Id": "29573", "Score": "5", "Tags": [ "python", "performance", "beginner", "machine-learning", "data-mining" ], "Title": "Alternative to Python's Naive Bay...
29573
<p>I have an HTML menu with sub-menus and also sub-sub-menus. This code verifies each menu's trigger. If clicked, sub-menu opens. Sub-menus also have triggers that open sub-sub-menus and so on. A working example can be found <a href="http://bios-diagnostic.ro/meniu213/" rel="nofollow noreferrer">here</a>. This menu is...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-10T07:47:36.673", "Id": "46797", "Score": "2", "body": "Well, you could **start with proper intendation**! After that, factor out common stuff. Functions are not special, so you could do `var gnSubMenu = gnMenu, gnSubMenu2 = gnMenu;` i...
[ { "body": "<p>One thing that I saw right away, while I was editing your question to make it more noticeable, is that you have 3 functions that are the same, they just have different names.</p>\n\n<blockquote>\n<pre><code>function gnMenu( el, options ) {\n this.el = el;\n this._init();\n}\n\nfunction gnSub...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-10T07:05:04.423", "Id": "29579", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "HTML menu with sub-menus" }
29579
<p>I wrote a class to import a large XML file. It works great, but I feel like its ugly, and horribly inefficient although I do like how easy it is to follow what it does. </p> <p>How can I improve this to make it better and to foster some better ruby writing ability?</p> <pre><code>require "rexml/document" class Xml...
[]
[ { "body": "<p>Some notes:</p>\n\n<ul>\n<li><code>rexml/document</code>. I'd use <a href=\"http://nokogiri.org/\" rel=\"nofollow\">Nokogiri</a> without a second thought, but if you prefer <code>rexml</code> because it's comes in the standard library, that's ok.</li>\n<li><code>Rails.logger.info \"all done\"</cod...
{ "AcceptedAnswerId": "29588", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-10T09:52:03.840", "Id": "29585", "Score": "2", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "XML Import class - Style improvements & Efficiency" }
29585
<p>My first question relates to the first Python module that I published on Python. This is a very small and simple module, the package contains only one class. This is a port of a Perl module <a href="https://metacpan.org/module/Locale%3a%3aWolowitz" rel="nofollow">Locale::Wolowitz</a> this is a module for managing tr...
[]
[ { "body": "<pre><code>import glob\nimport re\nimport os.path\nfrom collections import defaultdict\n\n\nclass Pylocwolowitz(object):\n '''Pylocwolitz is a very simple text localization system, meant to be used\nby web applications (but can pretty much be used anywhere). Yes, another\nlocalization system.'''\n...
{ "AcceptedAnswerId": "29590", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-10T12:58:37.690", "Id": "29586", "Score": "7", "Tags": [ "python", "json", "perl", "i18n" ], "Title": "Simple text localization system" }
29586
<p>I am making a WordPress "framework" for myself. Looking at the <a href="http://d.pr/f/kqw8" rel="nofollow">functions.php file</a> file, is there redundant or bad code that could be changed or some code that could be good to add?</p> <p>The functions.php should be a file that I could use in every web project with li...
[]
[ { "body": "<p>The code seems pretty solid. I'll make some small observations:</p>\n\n<ol>\n<li><p>I'd remove <code>add_action( 'after_setup_theme', 'remove_core_updates' );</code> and add a call to the function <code>remove_core_updates()</code> at the end of <code>beeFramework_setup()</code>.</p></li>\n<li><p>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-10T12:59:00.207", "Id": "29587", "Score": "3", "Tags": [ "php", "wordpress" ], "Title": "WordPress Functions.php file" }
29587
<p>I am new to C++ and to threading, so I'm sorry if my code is bad. I'm here to get it better and to learn. </p> <p>Any kind of advice (both on C++ style, on Qt usage, or on threading handling) is welcome. Please feel free to comment anything, also if the question has to be reformulated.</p> <p>I have this problem:<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-05T12:09:10.463", "Id": "64430", "Score": "1", "body": "I'm afraid I don't have the familiarity with QT needed to give you good feedback, but I did want to say that this is very good beginner code. The names make sense, the code is no...
[ { "body": "<p>First of all: your code is not bad; I agree with <a href=\"https://codereview.stackexchange.com/users/10084/wayne-conrad\">Wayne Conrad</a>.</p>\n\n<p>I have a minor remark about the connect statement. You are currently using Qt 4.8, so this is fine as it is. However with Qt 5 a <a href=\"https://...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-10T14:41:14.887", "Id": "29589", "Score": "6", "Tags": [ "c++", "beginner", "multithreading", "qt", "producer-consumer" ], "Title": "1 producer, n consumer with QThread" }
29589
<p>I've put together the code below, which creates a new sheet in my workbook and applies dynamically-named ranges and page-formatting. </p> <pre><code>Sub UniqueOverheads() Set rOverheadsList = Range([B4], [B4].End(xlDown)) Set rOverheadsActuals = Range([C4], [C4].End(xlDown)) Set rOApr = Range([D4], [D4].End(xlDo...
[]
[ { "body": "<p>Try to avoid using <code>Select</code>. I have fixed that for you. </p>\n\n<p>This line: <code>Range(Cells(4, i + 2), Cells(Cells(Rows.Count, i + 2).End(xlUp).Row, i + 2)).Address(ReferenceStyle:=xlR1C1)</code></p>\n\n<p>may require you to add <code>Sheets(\"SheetName\")</code> separated by dot <c...
{ "AcceptedAnswerId": "30309", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-10T17:17:52.547", "Id": "29593", "Score": "3", "Tags": [ "vba" ], "Title": "Dynamic ranges and page-formatting" }
29593
<p>This is a whole class I wrote. I am on my third day learning Java, so I think I would benefit a lot from a general review. At first I thought whole class would be too large, but <a href="https://codereview.meta.stackexchange.com/questions/729/how-long-is-long-code">this</a> says it is ok.</p> <pre><code>/** * Wiki...
[]
[ { "body": "<p><code>this.params</code> is superfluous; just use <code>params</code>.</p>\n\n<p>Use <code>modern</code> for loops, not with <code>iterator</code>.</p>\n\n<p>Use <code>entrySet</code> iterators to avoid map lookups in loops.</p>\n\n<p>Close the <code>printwriter</code> in a <code>finally</code> bl...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-10T19:41:45.167", "Id": "29595", "Score": "7", "Tags": [ "java", "beginner" ], "Title": "WikiCategory class" }
29595
<p>I am writing a board game program in Java. Slightly similar to chess or civilization in that each player has a set of units, and each unit has certain actions that it can take.</p> <p>The base <code>GameAction</code> class has two methods: One which checks to make sure the action is allowed, and one to actually do ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T00:08:47.220", "Id": "46827", "Score": "1", "body": "It doesn't look excessively redundant to me." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T17:11:45.720", "Id": "46907", "Score": "0", ...
[ { "body": "<p>I think that this type of setup should work fine. If you find yourself repeating multiple steps in various places in code, you could move that functionality to a utility class with static methods. As long as a unit of code can be considered stateless, you should be able to move it to a static me...
{ "AcceptedAnswerId": "29701", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-10T21:23:36.823", "Id": "29597", "Score": "1", "Tags": [ "java", "design-patterns", "game", "immutability" ], "Title": "Removing redundancy from an immutable \"rules class\"" ...
29597
<p>Many years ago, I wrote a script in Perl that was meant to create a cached metadata of MP3 files (in Apple's plist/XML format) which iTunes uses when you insert a CD/DVD full of MP3 files (the same would be true for AAC files, but I limited the scope of my project, due to lack of usable libraries back then).</p> <p...
[]
[ { "body": "<p>I'd replace</p>\n\n<pre><code>foreach (sort readdir($dh)) { # for each entry\nmy $name = \"$_[0]/$_\";\nif (-d $name and $_ ne \".\" and $_ ne \"..\") {\n ...\n} elsif ($_ ne \".\" and $_ ne \"..\") {\n ...\n</code></pre>\n\n<p>with</p>\n\n<pre><code>foreach my $fn (sort readdir($dh)) { # fo...
{ "AcceptedAnswerId": "29605", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T01:18:45.570", "Id": "29602", "Score": "3", "Tags": [ "xml", "perl", "cache" ], "Title": "Perl script for generating iTunes xml Metadata for MP3 CDs/DVDs" }
29602
<p>Given a graph in <code>[[sourcevertex,targetvertex],...]</code> format with all the directed edges of the graph I am trying to optimize the code here because it still hasn't stopped running I don't know if it will take days or hours, although it is somewhat working for small input sets. I think the masking/vertex r...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T13:12:11.813", "Id": "46963", "Score": "0", "body": "For intentionally infinite `while` loops, I recommend just using `while True:` as this is more common practice and seems more readable." } ]
[ { "body": "<p>First, main procedures of an executable Python script should <strong>always</strong> use this at the very bottom of the script to define the main entry point of the program:</p>\n\n<pre><code>if __name__ == '__main__':\n main() # or whatever your main execution code is\n</code></pre>\n\n<p>See ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T04:27:13.977", "Id": "29603", "Score": "1", "Tags": [ "python", "algorithm", "recursion", "graph" ], "Title": "Finding strongly connected components of directed graph, kosaraj...
29603
<p>If many threads Borrow() and Return() an instance of Packet from/to PacketPool could the Exception in Packet.Init() ever be thrown? Assuming only PacketPool ever called the Init() and UnInit() methods on a Packet.</p> <pre><code>class PacketPool { private Stack&lt;Packet&gt; pool; public PacketPool(int ini...
[]
[ { "body": "<p>No, the exception in Packet.Init() will never be thrown. This is because although there may be multiple threads in Borrow(), the lock statement will ensure that each thread sees its own version of p.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": ...
{ "AcceptedAnswerId": "29614", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T08:57:42.820", "Id": "29606", "Score": "1", "Tags": [ "c#", "thread-safety" ], "Title": "Thread safe object pool, is this object pool thread safe?" }
29606
<p>Here you can find my implementation of <a href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes" rel="nofollow">sieve of Eratosthenes</a> in Java.</p> <pre><code>/** * Return an array of prime numbers up to upperLimit * using sieve of Erastosthenes. * @param upperLimit * @return array of prime numbers up to ...
[]
[ { "body": "<p>A few notes:</p>\n\n<p>Right now you are using <code>int[]</code>s to represent the sieve. However, the <code>int</code> data type is internally stored as 32-bits, which is a waste of space.</p>\n\n<p>Use <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/BitSet.html\"><code>java.util.B...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T10:11:34.443", "Id": "29609", "Score": "9", "Tags": [ "java", "primes", "sieve-of-eratosthenes" ], "Title": "Sieve of Eratosthenes in Java" }
29609
<p>With the Zend coding convention in the back of my mind, <a href="https://github.com/Michal-sk/TargetSMS" rel="nofollow">I have set this up</a>.</p> <p>It lets you communicate with the API of the vendor <code>TargetSMS</code>. They allow you to bill customers trough SMS. For now I've only spent time on the <code>Non...
[]
[ { "body": "<p>If you wanted to make <code>isAllowdIp</code> static (and there's nothing wrong with that, per se), you -indeed- don't need an instance of your class to call that method. But owing to there being no instance, you won't have access to any non-static properties of your class, either.<br/>\nTo get ar...
{ "AcceptedAnswerId": "30868", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T10:26:19.000", "Id": "29610", "Score": "1", "Tags": [ "php", "object-oriented", "static" ], "Title": "Could my object use static methods? Anything I need to do to make the code...
29610
<p>I have written a program, in which I have to find the number of occurrences (overlapping + non-overlapping) of a string in another string.</p> <pre><code>// variable to keep track of word int i=0; for(vector&lt;string&gt;::iterator it = p.begin(); it!=p.end(); it++){ frequency[i]=0; int start=0; while(t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T12:35:38.157", "Id": "46833", "Score": "0", "body": "What exactly are you looking to improve? Or are you looking for a general review?" } ]
[ { "body": "<p>I don't like nested loops. They are generally unnecessry\nand are often confusing. So instead of your two loops, I would extrac the\ninner loop to a function, for example:</p>\n\n<pre><code>int key_search(const std::string&amp; s, const std::string&amp; key)\n{\n int count = 0;\n size_t pos...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T10:47:51.407", "Id": "29611", "Score": "2", "Tags": [ "c++", "optimization", "strings" ], "Title": "Finding the number of occurrences of a string in another string" }
29611
<p>Instead of using multiple setter functions within a class like </p> <pre><code>public function setAction() public function setMethod() </code></pre> <p>etc</p> <p>I've been using a method from a base class that all other classes have access to.</p> <pre><code>public function set_properties($properties) { fo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T17:07:10.690", "Id": "46837", "Score": "2", "body": "You should still keep the possibility that a property will need a special setter (that does more than just setting the property). In your loop, you should check whether `$this` ha...
[ { "body": "<p>Having individual setters has a couple of advantages:</p>\n\n<p>A dedicated setter allows you to put dedicated validations for these properties. You could obviously put them in the bulk setter as well, but that will make the bulk setter large and unwieldy very quickly. You want methods to do one d...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T17:00:44.300", "Id": "29617", "Score": "4", "Tags": [ "php", "object-oriented" ], "Title": "Setting properties inside of a class" }
29617
<p>This is the algorithm I am using to flip an image in-place. Though it works perfectly, I would like if any one can spot any potential problems or offer any points on improvement and optimizations.</p> <pre><code>/** * pixels_buffer - Pixels buffer to be operated * width - Image width * height - Image height * b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T22:17:57.377", "Id": "46852", "Score": "3", "body": "You shouldn't cast the result from `malloc` in C." } ]
[ { "body": "<p>Just some quick things:</p>\n\n<ul>\n<li><p><code>unsigned int width</code> doesn't need to be <code>const</code> since it's passed-by-value. But that's not really significant as the compiler will optimize away the <code>const</code> if needed.</p></li>\n<li><p>Prefer <a href=\"https://stackoverf...
{ "AcceptedAnswerId": "29626", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T17:20:04.687", "Id": "29618", "Score": "7", "Tags": [ "optimization", "c", "image" ], "Title": "Image Flip algorithm in C" }
29618
<p>I would like a review and recommendations for improvement of the code below. I want to allow an exception to be handled by the caller, so I am rethrowing it. But I have resources to close. So I have the resource closing code duplicated in both the try and the catch blocks. Is there a better way to do this?</p> ...
[]
[ { "body": "<p>It seems that your code would benefit dramatically from use of <a href=\"http://en.wikipedia.org/wiki/RAII\" rel=\"nofollow\">RAII</a>. To illustrate, let's assume the existence of an <code>HTTPConnection</code> class that opens an appropriate connection in its constructor and closes it at destruc...
{ "AcceptedAnswerId": "29627", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T18:17:22.717", "Id": "29621", "Score": "0", "Tags": [ "c++", "exception-handling" ], "Title": "Dealing with resource closure when rethrowing an exception" }
29621
<p>The interface and some of the implementation is take from Boost. However, it is intended to be transferable between projects by only copying one file. I have removed most of the policy classes in favor of more condensed code that requires less files to move around. Please tell me where my strengths are as well as wh...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T16:00:11.490", "Id": "46902", "Score": "3", "body": "This is good for an excercise. But please do **NOT** do this for production code. There are just too many gotchs involved in writing a correct smart pointer. Check out Scott Myers...
[ { "body": "<p>Firstly, let's fix up some errors that exist in the code. </p>\n\n<ol>\n<li>You're missing an <code>#endif</code> at the end of your <code>unique_ptr.h</code> file. </li>\n<li>Both <code>template &lt;class U, class D&gt; unique_ptr(unique_ptr&lt;U, D&gt; &amp;);</code> and <code>template &lt;class...
{ "AcceptedAnswerId": "29658", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-11T23:42:15.603", "Id": "29629", "Score": "5", "Tags": [ "c++", "pointers" ], "Title": "Unique pointer implementation" }
29629
<p>I am learning to use Java Swing and have made a simple animation that makes a small shape bounce around the predetermined borders of a panel. The program works well, but I am looking for feedback in terms of quality and any improvements or alternative methods that could be used in such an application.</p> <pre><cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-10-09T04:19:04.480", "Id": "119463", "Score": "0", "body": "import.java.awt.BorderLayout should be more efficient" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-03-21T10:13:42.353", "Id": "230106", "Scor...
[ { "body": "<h2>Things I would fix:</h2>\n\n<p>Don't do this:</p>\n\n<pre><code>import javax.swing.*;\nimport java.awt.*;\n</code></pre>\n\n<p>It could be problematic for the compiler to import a bunch of packages at once. If two packages provide the same type, both are imported, and the type is used in the clas...
{ "AcceptedAnswerId": "29634", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T00:27:02.480", "Id": "29630", "Score": "25", "Tags": [ "java", "swing", "animation" ], "Title": "Simple Java animation with Swing" }
29630
<p>This is a quick question. I am reading a mass amount of JSON from a variety of text files. The JSONs are tweets, in this format:</p> <pre><code>{"filter_level":"medium","retweeted_status":{"contributors":null,"text":"Daily Mail: Vincent Kompany says Manchester United are favourites http://t.co/NB2p1cqlRs #mufc","ge...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T13:21:56.160", "Id": "46887", "Score": "0", "body": "Some suggestions not related to your question : you can use for-each instead of a normal for loop. And if I'm not mistaken, you don't need to create a new Gson object all the time...
[ { "body": "<p>You're skipping a line that contains spaces. That's what the trim() does, removes spaces from the beginning and the end of a line.</p>\n\n<p>There is this alternative:</p>\n\n<pre><code> if (!rawTweet.equals(\"\")) {\n Tweet parsedTweet = new Gson().fromJson(rawTweet, Tweet.class);\n ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T00:32:34.380", "Id": "29631", "Score": "3", "Tags": [ "java", "json" ], "Title": "Parsing JSON from file in Java" }
29631
<p>I have an application with HTML, external JavaScript and a bit of jQuery on the page which is initializing specific stuff to that page. I try to keep most of the JavaScript in other files. However I'm unsure if stuff in the DOM Ready function should be split into a separate file as well which is specific to that pag...
[]
[ { "body": "<p>I don't know if it is <em>good practice</em>, but in my eyes it would be cleaner, since you have several JS-files at this point, to separate markup, layout and JS completely. So <code>$()</code> would reside in a .js-File.</p>\n\n<p>In some cases, when you only have a few lines of JS or -on the ot...
{ "AcceptedAnswerId": "29671", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T05:33:53.017", "Id": "29637", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Should jQuery DOM Ready code be in the page with the HTML or separate JavaScript file?" }
29637
<p>In a <a href="https://stackoverflow.com/questions/14495757/invalidoperationexception-in-release-since-net-4-0">former question on SO</a> I described a problem with a construct called 'EnumBase'.</p> <p>As I sad there, I am not involved when basic implementation happened. So I'm not sure why the thinks are a they ar...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T09:22:23.987", "Id": "46868", "Score": "0", "body": "What is your intent? Why do you need such class in the first place?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T10:18:42.777", "Id": "46872...
[ { "body": "<p>So, extending my comment... </p>\n\n<p>Enums are designed to represent a fixed number of states. This is their purpose. If that is what you need then nothing prevents you from using standart <code>enum</code>. If you want to specify items source as a collection of enum values - use <code>IEnumerab...
{ "AcceptedAnswerId": "30246", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T08:16:53.227", "Id": "29640", "Score": "0", "Tags": [ "c#", "object-oriented", "design-patterns", "asp.net", "winforms" ], "Title": "Searching for a better implementati...
29640
<p>I'd like a general opinion on my piece of code (which does exactly what I want it to do). I feel like I'm using bad practices, like a DB query within a <code>foreach</code> loop, or grabbing the lowest value in a non-elegant way (sorting, then using the object with an index of 0). I'm also not sure on my usage of th...
[]
[ { "body": "<p>Right, one general opinion coming up:</p>\n\n<ul>\n<li><code>Static</code>'s, at least the way you're using them, are just globals in drag. Don't do that. If you need both the <code>View</code> and <code>DB</code> class(or at least some tables from it) in the object, of which you posted a method: ...
{ "AcceptedAnswerId": "29677", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T13:08:54.233", "Id": "29649", "Score": "0", "Tags": [ "php", "performance", "sql", "laravel" ], "Title": "DB Query within foreach" }
29649
<p>In a Rails application, I want to have a complex form with some dynamic behaviour. For example, I want to show a part of the form want I check a box or I want to have different values in a select box when I choose a radio button.</p> <p>I do this with JQuery. My problem concern the archirecture. I created a form ob...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T14:28:51.637", "Id": "46894", "Score": "0", "body": "You might want to edit to ask about CoffeeScript since you aren't writing JavaScript at all. Client side techniques can be similar, but your title should match what you are askin...
[ { "body": "<p>For a single form, this is the exact reason Knockout.js was created - tutorials here: <a href=\"http://learn.knockoutjs.com/#/?tutorial=intro\" rel=\"nofollow\">http://learn.knockoutjs.com/#/?tutorial=intro</a></p>\n\n<p>Angular is more of a full blown \"SPA\" framework, Knockout is data-binding f...
{ "AcceptedAnswerId": "29984", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-07T14:20:46.237", "Id": "29651", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "Best practices to do complex forms with javascript?" }
29651
<p>I have a simple encryption module that is used to "encrypt" a text file because it contains some passwords. I only need to encrypt it because I need those passwords in my program (they are used to send an automated bug-report email), but I don't want the end-user to be able to see them. </p> <p>My "encryption" func...
[]
[ { "body": "<p><strong>Manual attack</strong></p>\n\n<p>First of all, your encryption scheme is very weak and easily exploitable. Given a few hundred characters of ciphertext, even a novice cryptanalyst can crack this cipher in less than 30 minutes with only pen and paper. I recommend you stick to industrial-str...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T16:04:19.453", "Id": "29652", "Score": "1", "Tags": [ "python", "security", "cryptography", "cython" ], "Title": "Is my Encryption Module Secure?" }
29652
<p>Coming from a Java kind of OOP, I miss a lot of things in JavaScript. I am working on a Node.Js project, and I would like to use an OO approach.</p> <p>Looking around and asking in <a href="https://stackoverflow.com/questions/18188083/javascript-oop-in-nodejs-how">StackOverflow</a> I came up with this example scena...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T17:02:45.257", "Id": "46906", "Score": "0", "body": "Like I showed in my answer, you can prefix a method or field with an underscore to communicate that this is an internal method or field, and it should not be accessed directly." ...
[ { "body": "<h2>Pretty good code.</h2>\n\n<p>From an OOP perspective, this is exactly right. From a formatting perspective, this is almost flawless. I hardly have anything to say about this code, but I see very little that I would change.</p>\n\n<p>The only issue that I see is an irregular formatting choice. The...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T16:32:46.877", "Id": "29653", "Score": "2", "Tags": [ "javascript", "object-oriented", "inheritance", "prototypal-class-design" ], "Title": "Understanding OO JavaScript with a...
29653
<p>I wrote <a href="https://github.com/yasar11732/HttpStatusCodes" rel="nofollow noreferrer">this small project</a> to practice threading in Java. At first, I planned to do it like <a href="https://stackoverflow.com/questions/18186336/what-type-of-queue-to-use-to-distribute-jobs-between-worker-threads">this</a>. But la...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T18:25:11.343", "Id": "46915", "Score": "3", "body": "I'll suggest you to use the interface `Map`instead of the implementation `HashMap`. More information here http://stackoverflow.com/questions/147468/why-should-the-interface-for-a-...
[ { "body": "<p>I'll talk about the code in general, not about the functionality.</p>\n\n<hr>\n\n<pre><code>package com.github.HttpStatusCodes;\n</code></pre>\n\n<p>Package names are used to identify the associated developer with the package. The problem here is that, unless you work for GitHub and write this und...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T17:54:21.360", "Id": "29656", "Score": "2", "Tags": [ "java", "multithreading" ], "Title": "Threading in Java" }
29656
<p>I'm creating an unordered list element in Backbone via Underscore templating:</p> <pre><code>&lt;ul id="FrontRack" style=" background-image: url({%= data.get('racks').at(0).get('imageUrls')[0] %}); height:{%= data.get('racks').at(0).get('pixelHeight') %}px; width:{%= data.get('racks').at(0)....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T12:08:41.957", "Id": "46957", "Score": "1", "body": "How many different height-width-image-combination to you have? Maybe you can put this in some css classes?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "201...
[ { "body": "<p>Interesting questions.</p>\n\n<ul>\n<li><p>Is setting 'style' still considered bad practice when creating elements through templating?</p>\n\n<p>Only if you cannot reasonably use css classes (which is your case)</p></li>\n<li><p>Should I be setting the style using jQuery after I generate the HTML ...
{ "AcceptedAnswerId": "45514", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T17:54:43.407", "Id": "29657", "Score": "12", "Tags": [ "javascript", "css", "template", "backbone.js", "underscore.js" ], "Title": "Unordered list element via templatin...
29657
<p>This function's job is to replace several text smilies, e.g. <code>:D</code>, <code>:)</code>, <code>:love</code> with the appropriate smiley image. In my opinion my code has several issues, yet the main problem is that <em>a lot</em> of quite similar regexes are created dynamically: one for each different smilie re...
[]
[ { "body": "<p>You can store the regex as part of the smily metadata.</p>\n\n<pre><code>var replaceTextSmilies = function() {\n var smiliesShortcut = {};\n smiliesShortcut[':)'] = {\n img : 'smile.png'\n };\n /* adding much more */\n\n var smiliesWordy = {};\n smiliesWordy[':angry'] = {\...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T18:13:08.277", "Id": "29660", "Score": "0", "Tags": [ "javascript", "optimization", "regex" ], "Title": "Avoiding dynamic RegEx creation in JavaScript" }
29660
<p>So we have a RESTful webservice that implements CRUD operations for a model, like this one:</p> <pre><code>class MyModel { private long id; private String name; // other fields private boolean completed; private boolean active; // getter and setters } </code></pre> <p>In this webservice the...
[]
[ { "body": "<p>You could use the composite pattern to create a tree of <code>Validator</code> instances. Each node would validate its with its own <code>Validator</code> before delegating to children (if any). This way children don't need to check again what was already validated in parent nodes</p>\n\n<pre><cod...
{ "AcceptedAnswerId": "29689", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T19:25:59.463", "Id": "29662", "Score": "2", "Tags": [ "java", "validation" ], "Title": "Different types of model validation" }
29662
<p>I have such a method that performs a long query search against some data.</p> <pre><code>Task&lt;List&lt;SearchResult&gt;&gt; Search(string query){ ... } </code></pre> <p>I have tried various way to create an IObservable form of it but failed. At the end after some google help I wrote such a method.</p> <pre><cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-10-06T01:31:44.427", "Id": "118703", "Score": "0", "body": "Why do you want to use IObservable<T> rather than Task<T>?" } ]
[ { "body": "<p>using the <code>TaskObservableExtensions</code> from <code>System.Reactive.Threading.Tasks</code> (in the <a href=\"https://www.nuget.org/packages/Rx-Linq/\" rel=\"nofollow\" title=\"NuGet\">Rx Linq DLL</a>) it is easy:</p>\n\n<pre><code>IObservable&lt;List&lt;SearchResult&gt;&gt; observable = Sea...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T20:24:31.927", "Id": "29663", "Score": "5", "Tags": [ "c#", ".net", "system.reactive" ], "Title": "Create an IObservable from a method" }
29663
<p>How can I refactor this code to avoid switch-cases? Is there a way of changing commands without adding new case and make it dynamically...I want the solution not to depend on the amount of cases. For example, if I have 1000 commands..I should obviously write them all as cases? I hope my problem is clear.</p> <pre><...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T20:40:25.417", "Id": "46920", "Score": "4", "body": "Not sure what the classes do but you could register all the functions in a dictionary<string, object> and simply call _action[com.ToLower()].Execute() (Make all your actions imple...
[ { "body": "<p>Here you go:</p>\n\n<pre><code>static void Main(string[] args)\n{\n ConsoleHelp ch1 = new ConsoleHelp();\n Plus pl = new Plus();\n Minus mn = new Minus();\n Divide dv = new Divide();\n Multiply mlt = new Multiply();\n Sinus sin = new Sinus();\n Tangent tan = new Tangent();\n ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T20:34:28.423", "Id": "29664", "Score": "5", "Tags": [ "c#" ], "Title": "how to avoid switch-case" }
29664
<p>I was working through getting myself past the creation of a generic method, that converts a <code>List&lt;T&gt;</code> or <code>List&lt;List&lt;T&gt;&gt;</code>, to <code>T[]</code> or <code>T[][]</code> respectively. Well, let's just consider a maximum dimension of 2 for now.</p> <h2><code>List&lt;T&gt;</code> to ...
[]
[ { "body": "<p>Since you are creating new instance of arrays in your second loop, you don't need to know the size of the \"inner list\". Your \"outer array\" has to be as big as the \"outer list\". In a second phase, you instanciate the \"inner arrays\".</p>\n\n<p>There's a simple way do this:</p>\n\n<pre><code>...
{ "AcceptedAnswerId": "29681", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T21:45:07.453", "Id": "29666", "Score": "3", "Tags": [ "java", "array", "generics" ], "Title": "Better way to write generic method to convert List<List<T>> to T[][]" }
29666
<p>I am doing some console test program, and I have some normal math operations. Example of part of my code:</p> <pre><code>if (flagMultiplyDivide.Equals(true)) { if (currentOperator.Equals('*')) { currentNumberDouble = multiplyNumbers(currentNumberString, temporaryNumberString); if (operatorOn...
[]
[ { "body": "<ol>\n<li>Extract repeated code into separate methods.</li>\n<li>Use <code>==</code> to compare values, C# is not Java, most of the time, you don't need <code>Equals()</code>. And in the case of <code>bool</code>s, you don't need to compare them at all.</li>\n<li>Don't forget to handle invalid input....
{ "AcceptedAnswerId": "29669", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-12T22:58:58.663", "Id": "29668", "Score": "5", "Tags": [ "c#" ], "Title": "What are best practices for writing conditional statements?" }
29668
<p>I am really just looking to make sure I am not making any weird mistakes that could hurt me in the long run or if something seems odd in the way I imagine it to work. This code does work for the way I use it and may lack other more advanced things that I may use in the future but have not implemented yet. I left in ...
[]
[ { "body": "<blockquote>\n <p>First of a note: you say yourself that everything is working. And that\n is what often counts. I hope I'm not to harsh, but it's my way of\n telling things ;)</p>\n</blockquote>\n\n<p>Overall:</p>\n\n<ul>\n<li>you should (try and) avoid an 'if' statement that change the action\no...
{ "AcceptedAnswerId": "29685", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T02:39:51.330", "Id": "29670", "Score": "6", "Tags": [ "php", "object-oriented", "mysqli" ], "Title": "Minimalistic mysql db class" }
29670
<p>Over the weekend I was perusing the web, and came across the programming problem, finding the longest non-decreasing subsequence in a grid, and I wanted to tackle it. I'm a web developer by profession, and sometimes, honestly, I feel like I fit <a href="http://www.codinghorror.com/blog/2009/08/all-programming-is-web...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T21:07:28.137", "Id": "47017", "Score": "1", "body": "Does your function actually work? If the grid you pass to it is `[[0, 9, 8],\n [9, 9, 4],\n [1, 2, 3]]`, for example, does it get the correct sequence `[1, 2, 3, 4, 8, 9]`?" }, ...
[ { "body": "<p>Aside from the fact that your algorithm doesn't work in cases where there is a solution that does not start with the smallest number, I would say that you are doing everything in an unnecessarily complex way, particularly in the way you use objects for all of the numbers and having to make copies ...
{ "AcceptedAnswerId": "29710", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T05:07:34.980", "Id": "29674", "Score": "1", "Tags": [ "javascript", "optimization", "algorithm", "recursion" ], "Title": "Finding the longest non-decreasing subsequence in ...
29674
<p>I need to refactor following class:</p> <pre><code>public class Message { public Guid ID { get; set; } public string MessageIn { get; set; } public string MessageOut { get; set; } public int StatusCode { get; set; } //EDIT could be changed during message lifecycle public bool IsDeletable { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T14:14:30.260", "Id": "46971", "Score": "0", "body": "You said \"you *need* to...\", or is it just esthetics? If `StatusCode` is integral to a `Message` and edit/delete is directly related to `StatusCode` then it looks reasonable as...
[ { "body": "<blockquote>\n <p>I would like to remove these switch statments in the same time</p>\n</blockquote>\n\n<pre><code>[Flags]\npublic enum StatusCode{\n codeX = 1,\n codeY = 2,\n codeZ = 4,\n codeA = 8,\n editable = codeX | codeZ,\n deleteable = codeY | codeZ\n}\n</code></pre>\n\n<p><s...
{ "AcceptedAnswerId": "29692", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-08-13T12:08:27.417", "Id": "29680", "Score": "5", "Tags": [ "c#", "object-oriented", "design-patterns" ], "Title": "Messages with status codes" }
29680
<p>I'm new to ruby on rails, on this project I'm using Ruby 2.0 and Ruby on Rails 3.0.</p> <p>I would like to know if this piece of code can be refactored, as it is</p> <pre><code>unless params["ot_code"].nil? ots = params["ot_code"].gsub(/\r\n?/, "").gsub(";","','").upcase ots[ots.length,1] = "'" ots = ...
[]
[ { "body": "<p>I'm a little worried about your <code>gsubs</code>, but assuming this is what you want to do:</p>\n\n<pre><code>def replace_and_wrap(str)\n return nil if str.nil?\n %Q{'#{str.gsub(/\\r\\n?/, \"\").gsub(\";\",\"','\")}'} \nend\n\nots = replace_and_wrap(params[\"ot_code\"])\nmultiple_circuit = re...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T13:26:39.400", "Id": "29687", "Score": "3", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Is there a way to refactor this code?" }
29687
<p>Just a small code review. Is there a better way to get all folder names?</p> <pre><code>&lt;?php $folders = glob(dirname(__FILE__) . '/myFolder', GLOB_ONLYDIR); foreach ( $folders as $f ) { $lastDsPos = strrpos($v, DIRECTORY_SEPARATOR); $myFolders[] = substr($v, $lastDsPos+1); } </code></pre>
[]
[ { "body": "<p>Have you considered using SPLs RecursiveIteratorIterator and RecursiveDirectoryIterator? Like this:</p>\n\n<pre><code>$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this-&gt;directory), RecursiveIteratorIterator::CHILD_FIRST);\nforeach($iterator as $path){\n if($path-...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T14:51:30.243", "Id": "29691", "Score": "1", "Tags": [ "php", "php5" ], "Title": "Retrieving all directorie names (relative path)" }
29691
<p>I have the following case statements that has to be modified to fit these cases: <code>Dec</code>, <code>Double</code>, <code>Int</code>, <code>Long</code>, <code>Short</code>, <code>Date</code>, and <code>String</code>.</p> <p>Please let me know if there is an easier way to handle this rather than repeating the fo...
[]
[ { "body": "<p>For value types (i.e. all your types except <code>String</code>) you can use the <a href=\"http://msdn.microsoft.com/en-us/library/dtb69x08.aspx\" rel=\"nofollow\"><code>Convert.ChangeType</code> method</a>:</p>\n\n<pre><code>list.Add(Convert.ChangeType(c.Text, theType))\n</code></pre>\n", "co...
{ "AcceptedAnswerId": "29704", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T15:34:35.400", "Id": "29693", "Score": "0", "Tags": [ "vb.net" ], "Title": "Manage Case Statement with (Int, long, short, double.....)" }
29693
<p>We're using a class called <code>Places</code> (inspired by <a href="http://www.drdobbs.com/jvm/solving-the-configuration-problem-for-ja/232601218?queryText=allen%2Bholub" rel="nofollow">Allen Holub's great article on DrDobbs</a>) that resolved our program paths based on the existence of a configuration file, enviro...
[]
[ { "body": "<p>Due to the size of the code I think you'd be better off just adding some comprehensive comments rather than refactor. </p>\n\n<p>So to answer your question:</p>\n\n<p>Did you needlessly complicate it? Yes and No</p>\n\n<p>Yes: It is needless since the code already worked as intended.<br>\nNo: Yo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T17:12:11.687", "Id": "29695", "Score": "3", "Tags": [ "java", "object-oriented" ], "Title": "Resolving paths" }
29695
<p>I am fairly new to writing unit tests, and I was wondering if this approach I have taken is on the right track?</p> <p>Given the following interfaces/classes:</p> <pre><code>public interface ILoggingService { void Log(string message); } public interface IShoppingCart { IList&lt;IShoppingCartItem&gt; Items...
[]
[ { "body": "<p>Your test is testing one thing only which is a very good thing. It is better to have many simple tests instead of one massive and it makes bug finding much easier.</p>\n\n<p>First of all, I would suggest using more descriptive names for both methods and test. Consider calling Calculate() method di...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T17:43:33.357", "Id": "29697", "Score": "3", "Tags": [ "c#", "unit-testing", "moq" ], "Title": "Using MOQ in unit-testing for a shipping calculator" }
29697
<p>I would love it if someone could give me some suggestions for these 2 graph search functions. I am new to scala and would love to get some insight into making these more idiomatic.</p> <pre><code> type Vertex=Int type Graph=Map[Vertex,List[Vertex]] val g: Graph=Map(1 -&gt; List(2,4), 2-&gt; List(1,3), 3-&gt; L...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-24T17:34:09.307", "Id": "47949", "Score": "0", "body": "Your representation of graphs and nodes is broken. Shouldn't that at least be \"type Graph=Map[Vertex,Set[Vertex]]\"? Because no vertex should be listed twice as a connection for...
[ { "body": "<p>OK, so I'm going to start with your DFS method. You're right - you should be able to do it without those vars in the outer function. You should be able to work out why - after all, you have vals in the outer layer of your BFS method. Why? Because your BFS uses a recursive helper function, so t...
{ "AcceptedAnswerId": "30285", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T17:52:31.830", "Id": "29699", "Score": "11", "Tags": [ "scala", "graph" ], "Title": "BFS and DFS in Scala" }
29699
<p>How can I optimize my jQuery? I remove the extra code to attach click event to the header tags.</p> <pre><code>$("#dnn_htmlPan1.htmlPan").find(":header").click(function () { $("#dnn_htmlPan1").find("p").slideToggle("slow"); }); $("#dnn_htmlPan2.htmlPan").find(":header").click(function () { $("#dnn_htmlPan2...
[]
[ { "body": "<p>Without knowing what your elements are or the html around them, i would say just combine the id's into one selector and use $(this).find in the click function. Example:</p>\n\n<pre><code>$(\"#id1, #id2, #id3\").find(':header').click(function(){\n $(this).find('p').slideToggle('slow')l\n});\n</code...
{ "AcceptedAnswerId": "29713", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T21:41:29.573", "Id": "29708", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "How to attach click to header child without reusing the code?" }
29708
<p>I am reading a book on DSA, and the author explains how to generate the permutation of strings using recursion. I want to know if there are better ways of doing the same, unless this is the best solution. Also, could someone help me understand the time-complexity of this algorithm? Recursion is something I use ve...
[]
[ { "body": "<ul>\n<li>The <code>rotate</code> function which reverses a sequence can be done in O(n/2) strictly it is still O(n) but when it is used a lot, then it's better to optimize it.</li>\n<li>The <code>displayWord</code> function is O(n²). It can be made constant by passing the array as argument. If Strin...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-13T23:29:38.440", "Id": "29712", "Score": "6", "Tags": [ "java", "algorithm", "recursion", "combinatorics", "complexity" ], "Title": "Permutation of given string" }
29712
<p>I'm a budding JavaScript programmer, working on an exercise where I'm trying to create two classes (<code>Books</code> and <code>Shelf</code>) and need to have a shelf know what books are on it. I'm pretty new to OOP so I know I'm missing a crucial step (or three). I probably already ran off the rails, but any point...
[]
[ { "body": "<p>There are multiple ways of handling this. If you can pass the Books you want to the Shelf object, that would be probably one of the easiest methods.</p>\n\n<pre><code>//The Shelves\nfunction Shelf (shelfNumber, shelfName) {\n this.shelfNumber = shelfNumber;\n this.shelfName = shelfName;\n ...
{ "AcceptedAnswerId": "29715", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T04:27:50.097", "Id": "29714", "Score": "2", "Tags": [ "javascript", "object-oriented" ], "Title": "How to get two JavaScript classes to talk to each other?" }
29714
<p>Here is my simple ticketing system:</p> <pre><code> &lt;?php session_start(); session_id(); ob_start(); require("../configuration/config.php"); $GetTickets = $con-&gt;query("SELECT * FROM tickets WHERE open='true'"); if(!$_SESSION['Admin']) { header('Location:...
[]
[ { "body": "<p>Profiling is not an art, it's a science.</p>\n\n<p>You need tools to profile your application, and know what eats up performance. It's only this way you'll be able to improve the performance.</p>\n\n<p>For PHP, what's usually used is the xdebug profiler.</p>\n\n<p>w.r.t your code, it's quite small...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T09:43:48.023", "Id": "29717", "Score": "1", "Tags": [ "php", "performance", "beginner", "mysql" ], "Title": "Simple ticketing system" }
29717
<p>This is my first MYSQL schema for caching location data (co-ordinates to place names) and referencing it with a country. </p> <p>I was wondering what everyones feedback was on it, did I do a good job?</p> <pre><code>CREATE TABLE location ( id INT AUTO_INCREMENT PRIMARY KEY, locality VARCHAR(20), administrative_are...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-17T17:26:52.393", "Id": "52497", "Score": "1", "body": "are these two tables linked? I don't see a Foreign key or anything to link the tables together. I do see 2 columns that have the same name in both tables?" }, { "ContentLi...
[ { "body": "<p>For all it's worth, and this is pretty old but for the sake of clearing unanswered reviews, here is my take:</p>\n\n<ul>\n<li><p><code>id INT AUTO_INCREMENT PRIMARY KEY,</code></p>\n\n<p>I find that being more specific in column names makes the code easier to work with, especially when you are usi...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T11:22:36.040", "Id": "29724", "Score": "1", "Tags": [ "sql", "mysql" ], "Title": "First Schema for Location and Countries" }
29724
<blockquote> <p>the Encoding scheme is given below:</p> <p>Don't replace the characters in the even places. Replace the characters in the odd places by their place numbers . and if they exceed 'z', then again they will start from 'a'.</p> <p>example: for a message "hello" would be "ieolt" and for message "m...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T13:04:11.447", "Id": "47051", "Score": "1", "body": "The examples seem strange, by the way. Does \"replace by their place number\" mean \"replace by the letter corresponding to their place number?\". And if yes, for ``hello``, shoul...
[ { "body": "<p>Here's a one liner for you (since the question asks for the minimum number of lines):</p>\n\n<pre><code>encode = lambda s: \"\".join([(c if (i+1) % 2 == 0 else chr(ord('a') + (ord(c) - ord('a') + i + 1) % 26)) for i, c in enumerate(s)])\n</code></pre>\n", "comments": [ { "Content...
{ "AcceptedAnswerId": "29731", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T12:29:26.660", "Id": "29727", "Score": "2", "Tags": [ "python", "strings" ], "Title": "Python abilities on strings" }
29727
<p><strong>The question is:</strong></p> <p>Write the following pseudo in assembler code:</p> <pre><code>if portC bit 3 == 0 (switch content of var1 and var2) else (add var1 with var2 and place the result in var1) </code></pre> <p><strong>My answer is:</strong></p> <pre><code>btfsc portC,3 goto add movf var1,w movw...
[]
[ { "body": "<p>A general disclaimer to this answer should be that I don't know the hardware you're working with, but most of this should be applicable to many architectures.</p>\n\n<h2>Potential optimization #1</h2>\n\n<p>Your code seems correct, but you can make it shorter and potentially more efficient by movi...
{ "AcceptedAnswerId": "29736", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T12:37:58.373", "Id": "29728", "Score": "1", "Tags": [ "assembly" ], "Title": "Assembler PIC programming, is this correct?" }
29728
<p>I am trying to write a simple version of the unix tail utility in haskell to improve my understanding of monads. Here is what I have now. I am pretty sure that this is not quite "Haskell enough" yet. Can you please help me improve my code?</p> <pre><code>import System.Environment import System.Exit import Control.M...
[]
[ { "body": "<p>My first approach is to map the arguments to a list of IO actions and then execute them:</p>\n\n<pre><code>import Control.Monad\nimport System.Environment\n\nlastLines :: Int -&gt; String -&gt; [String]\nlastLines n = reverse.take n.reverse.lines\n\nprintLines :: [String] -&gt; IO ()\nprintLines =...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T13:21:15.493", "Id": "29732", "Score": "5", "Tags": [ "haskell" ], "Title": "Unix tail in haskell" }
29732