body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I'm trying to see if there is a better way to design this. I have a class Animal that is inherited by Male and Female classes (Female class has an additional attribute). I also have a class called Habitat, an instance of each would contain any number of Animals including 0.</p>
<pre><code>class Animal:
def __i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-10T00:40:10.843",
"Id": "34636",
"Score": "2",
"body": "FWIW, don't call `obj.__len__()`, use `len(obj)` instead. Also, no need to use name mangling (double leading underscores): Just use `self.age` or `self._age`, especially use the f... | [
{
"body": "<p>In <code>Habitat.__init__</code>, you've committed a classic beginner's fallacy: using a list as a default argument.</p>\n\n<p>In Python, every call to a function with a default argument will use the same default object. If that object is mutable (e.g. a list) any mutations to that object (e.g. <c... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-10T00:37:16.780",
"Id": "21559",
"Score": "0",
"Tags": [
"python",
"object-oriented",
"design-patterns"
],
"Title": "Instance of one class to contain arbitrary number of instances of... | 21559 |
<p>There are plenty of <code>if</code>s and <code>else</code>s, and someone else told me that using <code>switch</code>/<code>case</code> statements could really clean up the code. However, he didn't implement it for me, so I don't know what I should switch/case.</p>
<p>Also take note that the <code>if (!stricmp(argv[... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T03:53:27.700",
"Id": "34724",
"Score": "2",
"body": "I think you should read a book about refactoring code, as it will help you to understand the changes you will make, and how to set up testing, etc."
},
{
"ContentLicense":... | [
{
"body": "<p>I think you should separate the logic parsing the arguments provided from the logic using the argument parsed. At the moment, you are trying to do everything in one place and I'm not quite sure this is correct (for instance, if a filename is also an option name, this leads to an unexpected behavio... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T03:42:49.027",
"Id": "21562",
"Score": "6",
"Tags": [
"c++",
"error-handling"
],
"Title": "Handling argument flags"
} | 21562 |
<p>I wrote this, and it has helped to avoid the 'Some exception weren't handled' problem. Is there something glaringly wrong with this that I might have missed?</p>
<pre><code> /// <summary>
/// Handles any exceptions on this task, and executes action on specified scheduler.
/// </summary>
/... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T10:20:13.060",
"Id": "34662",
"Score": "0",
"body": "PS: I *think* I wrote this. It was a while back, so it may be that I filched it from somewhere else."
}
] | [
{
"body": "<p>A couple of personal preferences here:</p>\n\n<ul>\n<li>Allow for no <code>scheduler</code> to be passed in and use the default scheduler in that case.</li>\n<li>Allow for no <code>exceptionHandler</code> if the caller is certain no exceptions will occur.</li>\n<li>Check that <code>task</code> isn... | {
"AcceptedAnswerId": "22795",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T07:06:08.760",
"Id": "21568",
"Score": "6",
"Tags": [
"c#",
"extension-methods",
"task-parallel-library"
],
"Title": "Task.Finally extension, good, bad, or ugly?"
} | 21568 |
<p>I have a requirement in my current project that will need a Prioritised Queue that supports the IObservable interface. Please notify me of any problems with the implementation that I currently have:</p>
<p><strong>ObservablePriorityQueue<T></strong></p>
<pre><code>public sealed class ObservablePriorityQueue&... | [] | [
{
"body": "<ol>\n<li>At first, I was confused what exactly did the implementation of <code>IObservable<T></code> mean. You should properly document that.</li>\n<li>You don't need to have a separate lock objects. If you're locking on a specific object, I think you should use that object in the <code>lock</... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T12:33:53.117",
"Id": "21574",
"Score": "4",
"Tags": [
"c#",
"performance",
"priority-queue"
],
"Title": "ObservablePriorityQueue<T> Implementation"
} | 21574 |
<p>I've implemented merge sort in Scala: </p>
<pre><code> object Lunch {
def doMergeSortExample() = {
val values:Array[Int] = List(5,11,8,4,2).toArray
sort(values)
printArray(values)
}
def sort(array:Array[Int]) {
if (array.length > 1 ){
var firstArrayLength = (array.length/2)
var... | [] | [
{
"body": "<p>Just a few unsorted ideas:</p>\n\n<ul>\n<li><p>Mergesort can be very nicely expressed using Scala's streams. In particular:</p>\n\n<pre><code>def merge(first: Stream[Int], second: Stream[Int]): Stream[Int] =\n (first, second) match {\n case (x #:: xs, ys@(y #:: _)) if x <= y => x #:: m... | {
"AcceptedAnswerId": "21590",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T13:08:00.910",
"Id": "21575",
"Score": "9",
"Tags": [
"algorithm",
"sorting",
"scala",
"mergesort"
],
"Title": "Merge sort in Scala"
} | 21575 |
<p>I think this is the simplest way to slugify urls. You have any contra-indication?</p>
<pre class="lang-php prettyprint-override"><code>function url_clean($str){
$str = iconv('utf-8', 'us-ascii//TRANSLIT', $str);
$clean_str = preg_replace(array('/\'|\"/','/ /'),array('','-'),$str);
return $cl... | [] | [
{
"body": "<p>There are two issues with your otherwise elegant approach:</p>\n\n<ol>\n<li><p><code>iconv</code> silently cuts the string if a disallowed UTF-8 character is present. The solution would be to add <code>//IGNORE</code> to the <code>iconv()</code> call but 1/ a bug in glibc seems to prevent this 2/ ... | {
"AcceptedAnswerId": "22853",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T13:23:11.167",
"Id": "21576",
"Score": "2",
"Tags": [
"php",
"url"
],
"Title": "PHP creating slugify (clean URL) links in simple way?"
} | 21576 |
<p>I've created a WPF program which can draw lines and circles on a canvas. It works well, but I don't think it's the best solution. How can I make it work better? How would you create this program?</p>
<p><strong><code>MainWindow</code> class:</strong></p>
<pre class="lang-cs prettyprint-override"><code>public par... | [] | [
{
"body": "<p>A little explanation first. I have written your code in a different way. This does not mean that my code is perfect in any way. I just wanted you to see other options and possibilities to achieve the same result. I'm open for comments if supported by valid arguments. </p>\n\n<p>First of all I sugg... | {
"AcceptedAnswerId": "21583",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T14:03:37.103",
"Id": "21579",
"Score": "5",
"Tags": [
"c#",
"wpf",
"xaml"
],
"Title": "WPF circle and line drawer solution"
} | 21579 |
<p>This is an HTML / JavaScript app for calculating someones body mass index.
The app does conversion of metric to standard measurements and standard to metric.</p>
<p>It outputs:</p>
<ul>
<li>BMI </li>
<li>weight category</li>
<li>ideal weight range for given height </li>
<li>percentage over/under ideal weight</li>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T16:30:51.093",
"Id": "34680",
"Score": "0",
"body": "I know sometimes things are purely up to a dev in the way they style their code, but please, try not to do this: `type = \"text\"` and instead remove the spaces on either side of ... | [
{
"body": "<ol>\n<li><p>Constants; instead of creating a bunch of standalone keys I'd group them in a single object, like:</p>\n\n<pre><code>var bmiConstants = {\n POUNDS_IN_STONE: 14,\n KGS_PER_POUND: 0.453592,\n INCHES_IN_FOOT: 12,\n CMS_PER_INCH: 2.54,\n CMS_PER_METRE: 100,\n INPUT_ERROR_MS... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T15:13:19.903",
"Id": "21581",
"Score": "7",
"Tags": [
"javascript",
"html"
],
"Title": "Calculating Body Mass Index (BMI)"
} | 21581 |
<p>I GET a HTML response from AJAX over cors and the response is a table. Each category has its title and sub elements. The title names vary quite a bit and are likely to change in the future. The sub elements in each title change almost on a daily basis, but the DOM structure doesn't.</p>
<p>Is there a way I could ge... | [] | [
{
"body": "<p>I have a hard time believing this code is working the way you want it to. </p>\n\n<p>But to answer your question, here is how I would get rid of that if statement. Use a two dimensional array as a lookup table and push items into the arrays there.</p>\n\n<pre><code>var classifiedFilter = functi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T16:30:49.580",
"Id": "21588",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"ajax"
],
"Title": "AJAX response DOM element selection"
} | 21588 |
<p>I was refactoring some code and found this:</p>
<pre><code>DateTime CurrentDateTime = System.now();
Datetime ESTDate = Datetime.newInstance(CurrentDateTime.year(),CurrentDateTime.month(),CurrentDateTime.day(),CurrentDateTime.hour(),CurrentDateTime.minute(),CurrentDateTime.second());
String myDateFormat = ESTDate.fo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T22:30:15.823",
"Id": "34691",
"Score": "3",
"body": "What's language is that?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T23:32:58.757",
"Id": "34694",
"Score": "0",
"body": "@CyrilleK... | [
{
"body": "<p>The programmer probably didn't understand how quoting works in <code>DateTime.format()</code> - just couldn't get the 'T' to appear in the string, so bailed, put the space there and replaced it. Creating <code>ESTDate</code> from <code>CurrentDateTime</code> is particularly weird, though!</p>\n",
... | {
"AcceptedAnswerId": "29239",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T22:11:43.307",
"Id": "21595",
"Score": "4",
"Tags": [
"optimization",
"salesforce-apex"
],
"Title": "Format current date"
} | 21595 |
<p>I've written a script using the Django ORM to store 'configuration settings' and interacting with the Google Drive API and another API. The script creates a base project folder and subfolders in Google Drive for a list of records, and posts links back to the source database. I'm a beginner in Python, so I'm not sure... | [] | [
{
"body": "<pre><code># Celery tasks\n@periodic_task(run_every=crontab(hour=\"*\", minute=\"*\", day_of_week=\"*\"))\ndef sync_folders():\n configs = Configuration.objects.all()\n for config in configs:\n user = config.user\n client = create_client(user, config)\n</code></pre>\n\n<p>I'd do: ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-11T22:26:37.427",
"Id": "21597",
"Score": "3",
"Tags": [
"python",
"performance",
"http",
"django",
"google-drive"
],
"Title": "Storing folders of list of records in Google D... | 21597 |
<p>For the <code>m_listeners</code> BlockingCollection<>, I know it's a bit hacky right now, but I'm not sure what to use instead (List<>, Dictionary<>, something else?). I want to be able to add/remove listeners at the same time as I may be broadcasting to those listeners without throwing null reference exce... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T00:45:48.903",
"Id": "34698",
"Score": "0",
"body": "You don't ever need to unregister a callback?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T01:10:40.213",
"Id": "34699",
"Score": "0",
... | [
{
"body": "<p>Answering my own question here based off suggestions in the question comments.</p>\n\n<p>This seems to work decently well. Good to have debugger Output Console open and see the behaviour of registering/unregistering logs to the GUI textbox (especially multiple clicks).</p>\n\n<p>I changed from us... | {
"AcceptedAnswerId": "21638",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T00:11:36.860",
"Id": "21600",
"Score": "2",
"Tags": [
"c#",
"multithreading"
],
"Title": "Simple ThreadSafe Log Class"
} | 21600 |
<p>I am new to javascript and want to make sure I am on the right track when playing a sound. Is there anything I should not be doing better or not be doing at all. Below is a simple function. </p>
<pre><code><script language="javascript" type="text/javascript">
function playSound(soundfile) {
if (navigato... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T09:03:04.430",
"Id": "34713",
"Score": "0",
"body": "Why do you use [`embed`](http://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element) instead of [`audio`](http://www.w3.org/TR/html5/embedded-content-0.html#the-audio-el... | [
{
"body": "<p>Regarding the HTML:</p>\n\n<h3><code>script</code> element</h3>\n\n<p>For JavaScript, <a href=\"http://www.w3.org/TR/html5/scripting-1.html#the-script-element\" rel=\"nofollow\">you can</a> simply use <code><script></code> without the <code>type</code> attribute:</p>\n\n<blockquote>\n <p>If... | {
"AcceptedAnswerId": "21643",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T03:57:49.153",
"Id": "21604",
"Score": "2",
"Tags": [
"javascript",
"html5"
],
"Title": "Playing sound on a button click"
} | 21604 |
<p>I am pulling multiple feeds from youtube that have a callback function which makes markup from each feed. They add that markup to a documentFragment stored in var data. When all the feeds have contributed what they should, a final callback runs. Each feed can deal with its own thumbnails and page menu, so it makes s... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><code>data</code> should be declared with <code>var</code>, so should a number of other variables. Please paste your code into the JSHint.com site and have a look</li>\n<li><p>It is considered better form to have 1 comma separated <code>var</code> statement:</p>\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T04:35:44.043",
"Id": "21605",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"performance",
"plugin"
],
"Title": "Creating and referencing markup....cloning, etc. efficient s... | 21605 |
<p>Sometimes "a" service does not respond and so we need to restart it. Usually it's a glitch in the network. We can have like 100 calls at the same time so the service cannot be restarted for 100 hundred times. The service is a Singleton. The command is called through a dispatcher, it's sync so different calls are exe... | [] | [
{
"body": "<ol>\n<li><p>First of all, it looks like as a workaround for another bug. You might want to fix that bug instead of this workaround.</p></li>\n<li><p>Comments like the following are unnecessary:</p>\n\n<pre><code> /**\n * Logger for this class\n */\n</code></pre>\n\n<p>It just repeats the code and fo... | {
"AcceptedAnswerId": "21684",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T10:19:39.120",
"Id": "21613",
"Score": "5",
"Tags": [
"java",
"multithreading"
],
"Title": "Timing single operation to not be repeated for a fixed time"
} | 21613 |
<p>I am working on project in which I need to display different colors
on RGB led. I am using pwm to drive different colors on LED. My Pic
is PIC24FJ64GA004 with which I am working on now. Basic concept of
this project is to use switch to controls colors. </p>
<p>Colors on RGB led will be according to days and month i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T12:46:28.537",
"Id": "34723",
"Score": "1",
"body": "Hello, and welcome to Code Review! Unfortunately, we only focus on already working code (see the [faq](http://codereview.stackexchange.com/faq)), so your question is off-topic. So... | [
{
"body": "<p>A few comments:</p>\n\n<ol>\n<li>Why check this twice <code>PORTAbits.RA4==1</code> in the same if-block?</li>\n<li><p>Following can be rewritten:</p>\n\n<pre><code>counter++;\nif (counter== 12)\n{ \n counter = 0;\n} \n</code></pre>\n\n<p>to:</p>\n\n<pre><code>if(++counter == 12)\n{\n coun... | {
"AcceptedAnswerId": "21625",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T11:52:45.160",
"Id": "21615",
"Score": "-3",
"Tags": [
"c",
"algorithm",
"performance"
],
"Title": "Project RGB with Switches"
} | 21615 |
<p>I am trying to insert into a database using JDBC and each thread will be inserting into the database. I need to insert into around 30-35 columns. I wrote a stored procedure that will UPSERT into those columns. </p>
<p>The problem I am facing is, if you look at my run method, I have around 30 columns written over th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-09T07:20:35.303",
"Id": "34726",
"Score": "0",
"body": "You can try my suggestion from [this answer](http://stackoverflow.com/a/12887046/1065197)"
}
] | [
{
"body": "<p>Following things are observed in your code:</p>\n\n<ol>\n<li><code>Constants</code> is the name of class itself.</li>\n<li><code>getXXX</code> method is static method in class <code>Constants</code></li>\n</ol>\n\n<p>Going by all above analysis I consider the use of Reflection API to call the <cod... | {
"AcceptedAnswerId": "21622",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-09T07:12:06.103",
"Id": "21620",
"Score": "4",
"Tags": [
"java",
"database",
"jdbc"
],
"Title": "Inserting into database columns"
} | 21620 |
<pre><code>import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
class RemoveDuplicates {
public static void main(String[] args) {
LinkedList<Integer> list = new LinkedList<Integer>();
list.add(1);
list.add(1);
list.... | [] | [
{
"body": "<p>I would not save keystrokes by calling your method <code>rmDuplicates</code>, I would simply call it <code>removeDuplicates</code>.</p>\n\n<p>Using both an Iterator and an index means you're probably doing it wrong.</p>\n\n<p>If you did not have to modify the provided list, I would do the followin... | {
"AcceptedAnswerId": "21631",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T14:45:50.860",
"Id": "21626",
"Score": "1",
"Tags": [
"java"
],
"Title": "Code review for style, clarity and efficiency. Removing duplicates from linkedlist"
} | 21626 |
<p>After being inspired by some MVC style design patterns, I have been trying to separate data from views in my code and move toward a more sensibly organized object based approach. (please, don't bother telling me that my code doesn't follow strict MVC pattern correctly, that is not my concern at this point!) All the ... | [] | [
{
"body": "<p>I cannot answer your scoping question, though I would not bother putting video under tutorial if it gives you hassles. I can give a review of your code.</p>\n\n<ul>\n<li>lowerCamelCasing is good : <code>currentvideo</code> -> <code>currentVideo</code>, <code>currentset</code> -> <code>currentSet</... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T16:03:12.410",
"Id": "21630",
"Score": "2",
"Tags": [
"javascript",
"object-oriented",
"mvc"
],
"Title": "Making one object the property of another whilst avoiding scope issues"
} | 21630 |
<p>I was recently asked to implement an interface for a job interview. the class has methods to add customers and movies, the customers can watch or like movies and add friends. there are methods to get recommendations for users. All public methods in SocialMoviesImpl were defined by the interface, so I could not chang... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T19:17:03.320",
"Id": "34761",
"Score": "0",
"body": "I like this question, but unfortunately, I can't help answer it. I think I'd do it very differently, but I can't tell how much of that is Java idiom (vs the C# I use) and how muc... | [
{
"body": "<p>My thoughts in no particular order:</p>\n\n<ul>\n<li><p>You can remove most of the \"this.\" in your code. That looks terrible to me, sorry.</p></li>\n<li><p>addMovie and lookupMovie should probably be part of a separate class like MovieDatabase</p></li>\n<li><p>Customer.addWatch() has a misleadin... | {
"AcceptedAnswerId": "21646",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T17:28:24.947",
"Id": "21633",
"Score": "6",
"Tags": [
"java",
"interview-questions"
],
"Title": "interview question, friends, movies and likes"
} | 21633 |
<p>Is there a cleaner/more efficient way to loop through the columns in EF implicitly than the way written below?</p>
<pre><code>static void Main(string[] args) {
using (var db = new someDbContext()) {
var query = from p in db.someTable
select new {
column1 = p.c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T18:55:49.713",
"Id": "34757",
"Score": "2",
"body": "Why do you need to loop through each column?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T19:27:02.040",
"Id": "34762",
"Score": "0",
... | [
{
"body": "<p>So I had a look and made a few modifications, see below with comments.</p>\n\n<pre><code>// Made the method generic, the constaint is required by DbSet\nstatic void LoopThroughColumns<T>(Func<someDbContext, DbSet<T>> getTable)\n where T : class\n{\n using (var db = new some... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T17:57:11.323",
"Id": "21634",
"Score": "8",
"Tags": [
"c#",
"entity-framework"
],
"Title": "Looping through columns in Entity Framework"
} | 21634 |
<p>I'm making an image-downloading app that sets the image as the device wallpaper. For this I used the class:</p>
<p><code>ImageDownloader.java</code></p>
<p>This class has a function which accepts a URL and an <code>ImageView</code>. It downloads and assigns the image found at the URL to the ImageView using an <cod... | [] | [
{
"body": "<p>The system you have in place is efficient in the sense that it offloads the network-based work on to an AsyncTask, and the callback updates the wallpaper.</p>\n\n<p>You don't give the details of your <code>ImageLoader</code> <code>AsyncTask</code>, but you could neaten a few things up by putting t... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T18:07:01.760",
"Id": "21635",
"Score": "6",
"Tags": [
"java",
"beginner",
"android",
"image",
"url"
],
"Title": "Image-downloader/wallpaper setter"
} | 21635 |
<p>I'm new to scala and I'm noticing I have some repeating code in my controllers.</p>
<p>I'm wondering if anyone can give some hints for traits and parameterization for eliminating duplicate code for basic crud operations on the web services - I'm still a little confused about how to use scala 'generics'/parameters.<... | [] | [
{
"body": "<p>for all the option matchers you could use getOrElse\nAnd remember: Option is also a list with all given features</p>\n\n<p>here an example</p>\n\n<pre><code>val resultsPerPageOption = request.queryString.get(\"numResults\")\nval size= resultsPerPageOption.map(_.head.toInt).getOrElse(defaultPageSiz... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T18:55:33.127",
"Id": "21637",
"Score": "6",
"Tags": [
"scala"
],
"Title": "Scala Play Controller - Refactoring out Duplication for Restful Web Services"
} | 21637 |
<p>I've written a simple Python module that depends on watchdog to monitor for modified files, then runs various integration and build processes.</p>
<p>I'm fairly new to Python, so I'd appreciate all criticism. For example of how I'm using the module <a href="http://github.com/hbmartin/kirb" rel="nofollow">see this<... | [] | [
{
"body": "<pre><code>import sys, os, time, copy, logging\nfrom watchdog.observers import Observer\nfrom watchdog.events import FileSystemEventHandler\n\n\nclass ChangeHandler(FileSystemEventHandler):\n def __init__(self, callback):\n if callable(callback):\n self.callback = callback\n ... | {
"AcceptedAnswerId": "21641",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T19:41:10.277",
"Id": "21639",
"Score": "5",
"Tags": [
"python",
"beginner",
"file-system",
"modules",
"makefile"
],
"Title": "Monitor filesystem for continuous integrat... | 21639 |
<p>I wrote it more for educational reasons and less as something that can compete with existing alternatives. </p>
<p>But I enjoyed writing it and wish to get some feedback, JavaScript is my second language :)</p>
<p>(I hope the main issue is lack of comments, but I wonder if there is anything else hairy about the co... | [] | [
{
"body": "<p>I like the demo, from a once over:</p>\n\n<ul>\n<li><p>the functionNames make my eyes glaze over, data tables variables should be sorted and tabbed in my mind:</p>\n\n<pre><code> var functionNames = [ \n { name: \"matrix\", type: functionParamTypes.length... | {
"AcceptedAnswerId": "43742",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T19:59:57.717",
"Id": "21640",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"plugin"
],
"Title": "jQuery plugin for easy CSS3 transformation"
} | 21640 |
<p>I've been writing a collection of signal processing function optimized with SSE intrinsics (mostly for audio processing). Here is a linear interpolation function I wrote. It works well and is quite fast (much better than straight lerp), but I'm using the full 8 registers available, and I'm wondering if there's somet... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T23:09:47.127",
"Id": "34778",
"Score": "0",
"body": "Chris, welcome to Code Review! Please format your code using spaces, not tabs, as the latter don't display properly (I've edited your question to fix that)."
}
] | [
{
"body": "<p>One improvement would be to restrict the number of (random) memory accesses. First notice is that for each sourceY[fixed] there's also a memory read from sourceY[fixed+1];</p>\n\n<p>I believe these should be at least combined to single 64-bit memory accesses.</p>\n\n<p>A more crucial improvement w... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-12T22:29:19.190",
"Id": "21644",
"Score": "3",
"Tags": [
"c++",
"assembly",
"sse"
],
"Title": "Trying to improve and better understand Intel SSE intrinsics"
} | 21644 |
<p>This may be a poor title name. So I'm basing what I did <a href="http://forums.codeguru.com/showthread.php?231156-MFC-String-How-to-convert-between-a-CString-and-a-BSTR" rel="nofollow">from this website</a>.</p>
<p>The idea is though that I have made a lot of work to a Service Object for a OPOS MSR device. (useless... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T11:51:57.493",
"Id": "34795",
"Score": "0",
"body": "What exactly do you want reviewed? What should we look for?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T13:58:30.960",
"Id": "34804",
"... | [
{
"body": "<ol>\n<li>This <code>BYTE* bTmp = new BYTE[4];</code> could just be put on the stack with <code>BYTE bTmp[4];</code> (the proper term is actually automatic storage duration which in most cases means it ends up on the stack). This normally avoids a call to <code>malloc</code> and you don't have to del... | {
"AcceptedAnswerId": "35967",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T04:30:11.630",
"Id": "21649",
"Score": "5",
"Tags": [
"c#",
"c++"
],
"Title": "OPOS DirectIO event review"
} | 21649 |
<p>I'm currently converting a CSS 960 fluid grid to SASS. How can I improve my current implementation? My column classes <code>.two.columns</code> are getting a bit unruly. Is there a better way to write them?</p>
<pre><code>// Variables
$width: 960px;
.container {
position: relative;
width: $width;
ma... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T08:33:47.443",
"Id": "34788",
"Score": "0",
"body": "It's possible to write a loop that will generate those, using names such as \"column.8\" and \"offset-by-3\" (that is, 3 instead of three). I don't know SASS enough to write it m... | [
{
"body": "<p>You could use a for loop to have it generate the columns for you, like...</p>\n\n<pre><code>$grid-column: 16;\n$grid-gutter: 10px;\n$column-width: 50px;\n\n.column {\n position: relative;\n display: inline;\n float: left;\n margin-right: ($grid-gutter / 2);\n margin-left: ($grid-gut... | {
"AcceptedAnswerId": "21656",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T04:54:56.220",
"Id": "21650",
"Score": "3",
"Tags": [
"sass"
],
"Title": "SASS 960 fluid grid"
} | 21650 |
<p>I have an Apps Script that is supposed to run through the spreadsheet, and if a company belongs to a certain country (there's a country column), set the value of the region row to something (e.g. Africa).</p>
<p>The spreadsheet has more than 8500 rows and this is the dirty code I have. It's working, but if there's... | [] | [
{
"body": "<p><strong>TL;DR</strong> : My comments won't improve the performances much. Also, I've never used Apps Script.</p>\n\n<p>This being said, here what I did : I decided to change details to make your code more concise (removing variables used only once for instance).</p>\n\n<pre><code>function setRegio... | {
"AcceptedAnswerId": "21655",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T09:38:22.983",
"Id": "21654",
"Score": "2",
"Tags": [
"google-apps-script"
],
"Title": "Script for recording a country in which a company belongs"
} | 21654 |
<p>I have a web scraping application that contains long string literals for the URLs. What would be the best way to present them (keeping in mind that I would like to adhere to <a href="http://www.python.org/dev/peps/pep-0008/#maximum-line-length" rel="nofollow">PEP-8</a>.</p>
<pre><code>URL = "https://www.targetwebsi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T14:25:55.910",
"Id": "96329",
"Score": "1",
"body": "I would put the URLS in a config file, or take them as a parameter."
}
] | [
{
"body": "<p>You could use continuation lines with <code>\\</code>, but it messes the indentation:</p>\n\n<pre><code>URL = 'https://www.targetwebsite.co.foo/\\\nbar-app/abc/hello/world/AndThen\\\n?whatever=123&this=456&theother=789&youget=the_idea'\n</code></pre>\n\n<p>Or you could use the fact tha... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T12:57:03.020",
"Id": "21658",
"Score": "5",
"Tags": [
"python",
"url"
],
"Title": "Presenting long string literals (URLs) in Python"
} | 21658 |
<p>This is a Python module I have just finished writing which I plan to use at Project Euler. Please let me know how I have done and what I could do to improve it.</p>
<pre><code># This constant is more or less an overestimate for the range in which
# n primes exist. Generally 100 primes exist well within 100 * CONS... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-15T08:24:01.633",
"Id": "34936",
"Score": "0",
"body": "It is a good idea to always follow PEP-0008 style guidolines: http://www.python.org/dev/peps/pep-0008/"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-05... | [
{
"body": "<p>General programming issues (non-Python specific):</p>\n\n<ul>\n<li><p><strong>Avoiding duplicated code:</strong> <code>listToNthPrime()</code> and <code>nthPrime()</code> are identical beside the indexing. The later could be changed to <code>def nthprime(termin): return listToNthPrime(termin)[-1]<... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T13:38:43.503",
"Id": "21659",
"Score": "3",
"Tags": [
"python",
"programming-challenge",
"primes"
],
"Title": "Project Euler: primes in Python"
} | 21659 |
<p>The code does seem a bit repetitive in places such as the <code>parenturlscraper</code> module and the <code>childurlscraper</code> module.</p>
<p>Does anyone have any recommendations for improving my code and condensing it a little?</p>
<p>In essence, the code scrapes <a href="http://planecrashinfo.com/database.h... | [] | [
{
"body": "<pre><code>__version__ = '0.1'\n__author__ = 'antmancoder'\n\n# Importing of modules required for the script to run successfully\n</code></pre>\n\n<p>Comments should be used for the non-obvious parts of your code. Explaining that we have imports is obvious. It doesn't need a comment.</p>\n\n<pre><cod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T14:36:39.040",
"Id": "21663",
"Score": "1",
"Tags": [
"python",
"url",
"web-scraping"
],
"Title": "URL and source page scraper"
} | 21663 |
<p>I have to define a lot of values for a Python library, each of which will represent a statistical distribution (like the Normal distribution or Uniform distribution). They will contain describing features of the distribution (like the mean, variance, etc). After a distribution is created it doesn't really make sense... | [] | [
{
"body": "<p>I'm not sure how Pythonic this is, but how about something like this:</p>\n\n<pre><code>class DynaObject(object):\n def __init__(self, *args, **kwargs):\n for (name, value) in kwargs.iteritems():\n self.__setattr__(name, value)\n\nclass Uniform(DynaObject):\n __slots__ = [\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T05:55:06.033",
"Id": "21666",
"Score": "10",
"Tags": [
"python",
"scala"
],
"Title": "Scala inspired classes in Python"
} | 21666 |
<p>Basically, I did an object (using hibernate) with a field called sorting_order. This field needs to be unique and I wish to swap two object by one. So one element has to be after or before the current element to be able to move. My object can only move by one up or down. I came up with this code, but I was wondering... | [] | [
{
"body": "<p>My thoughts in somewhat random order</p>\n\n<ul>\n<li><p>A boolean that indicates up/down could be improved with public 2 constants in your class UP = 0, DOWN = 1, and then the caller uses either constant. Or even better, use and ENUM as mentioned by cl-r.</p></li>\n<li><p>To be more DRY I would c... | {
"AcceptedAnswerId": "22703",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T17:04:18.913",
"Id": "21672",
"Score": "4",
"Tags": [
"java",
"optimization",
"algorithm",
"design-patterns",
"generics"
],
"Title": "Move object by one up or down algo... | 21672 |
<p>I wanted to be able to consistently label an arbitrary number of objects on my site. It's pretty simple, but I if there's a more clever way...</p>
<pre><code>// Usage:
// ColorTable.getColor('my link name');
ColorTable = {
'_colors' : [
'#F4BB2E',
'#2DE656',
'#66CCFF',
'#6666FF',
'#CC66FF',
... | [] | [
{
"body": "<p>Minor nitpicks:</p>\n\n<p>None of you keywords are reserved words (especially if it starts with an underscore!) so encasing them in single-quotes is superfluous.</p>\n\n<p><code>ColorTable.tableSize</code> is an example of the <a href=\"http://www.codinghorror.com/blog/2012/07/new-programming-jarg... | {
"AcceptedAnswerId": "21679",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T19:22:53.203",
"Id": "21676",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "Rotating color table object (for easy and consistent labeling)"
} | 21676 |
<p>So I made a socket communication library. And a part of it is <code>IConnection</code> </p>
<pre><code>public enum ConnectionState
{
NotConnected, Connecting, Connected, Authenticated, Disconnecting, Disconnected
}
public interface IConnection
{
ConnectionState State { get; }
event Action Connected;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T23:47:12.617",
"Id": "34833",
"Score": "0",
"body": "Maybe the class that works with the connection (the one that represents protocol layer) should expose the `Authenticated` event?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>You're not quite correct saying that IConnection has no ideas about protocol layer - in your defininition IConnection provides events about authentication process. So your code should have some connections between IConnection and protocol layer. I have no clue about entire relationships between la... | {
"AcceptedAnswerId": "22698",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-13T22:34:27.197",
"Id": "21680",
"Score": "2",
"Tags": [
"c#",
"authentication",
"library",
"socket"
],
"Title": "Properties and on change events"
} | 21680 |
<p>i created a database class from a good tutorial and wanted to put it up here so it would get in some search results. it took me about 2 days to find it. also i added a few custom functions to it.. here it is :P and if there is something that can be done better or more proficiently please feel free to let me know.</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T02:39:36.633",
"Id": "34839",
"Score": "0",
"body": "Code Review is meant for reviewing code that *you* wrote, not code that you found on the internet."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T... | [
{
"body": "<p>Those constants, <code>DB_HOST</code> etc, since there's no easy way to redefine them, pretty much ensure that you can only ever have one database per run of your app. Maybe this is an issue for you; maybe it's not. But it can be a showstopper if you have to use two databases. I'd at least acce... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T01:41:05.653",
"Id": "21685",
"Score": "1",
"Tags": [
"php",
"mysql",
"classes",
"pdo"
],
"Title": "PHP PDO Custom class ple"
} | 21685 |
<p>I just started to learn Objective C with <em>Programming in Objective C</em> by Stephen G. Kochanand and I would love to get your feedback to see if I'm getting OOP concept with Objective-C right.</p>
<p><strong>GraphicObject.h</strong></p>
<pre><code>#import <Foundation/Foundation.h>
@interface GraphicObje... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-24T21:01:29.267",
"Id": "41196",
"Score": "0",
"body": "This is primarily an issue for Stack Exchange sites, and a *little* less crucial when you're looking at code in your full-screen IDE. But, please try to avoid putting so much emp... | [
{
"body": "<p>I have to make the same suggestion as for your last question: use properties and stick to name conventions</p>\n\n<p>Your code as it is</p>\n\n<pre><code>#import <Foundation/Foundation.h>\n\n@interface GraphicObject : NSObject\n\n{\n int fillColor;\n int lineColor;\n BOOL filled;\n}... | {
"AcceptedAnswerId": "22723",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T02:38:36.977",
"Id": "21688",
"Score": "2",
"Tags": [
"beginner",
"objective-c",
"computational-geometry"
],
"Title": "Creating shapes program with multiple classes (different ... | 21688 |
<p>I've tried to write a bash script that gives me a general overview of the status of git repos I have cloned/created. It's not meant to replace <code>git status</code> by any means, but give an overview of several repos. </p>
<p>Keep in mind I'm not the most knowledgeable about bash scripting AND git, so I imagine t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-03T11:48:07.903",
"Id": "38096",
"Score": "0",
"body": "Have you tried [`fgit`](https://github.com/l0b0/fgit)? It's served me well for years. Disclaimer: I'm the author."
}
] | [
{
"body": "<p>Yes there is a better way of filling an array. You can use globbing inside of array parens. Also I suggest being explicit about what you do in bash and use <code>declare -a</code> to declare arrays and later on <code>declare</code> for other variables</p>\n\n<pre><code>declare -a repos=(~/repos/* ... | {
"AcceptedAnswerId": "22878",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T03:01:52.570",
"Id": "21691",
"Score": "3",
"Tags": [
"bash",
"shell"
],
"Title": "Improve a script to generally check status of several git repos"
} | 21691 |
<p>I am doing web apps, mostly single page apps. So i have to give absolute and fixed positioning a lot via css. </p>
<p>For Example, consider this page layout:</p>
<pre><code><html>
<div class="app-header">
</div>
<div class="main-app-area"> <!-- app contains four pages -->
<di... | [] | [
{
"body": "<p>Have a look at this, maybe this helps a little. I made only little changes. first of all you have to know a child element is always positioned absolute or relative to his parent. so it is important to make child and parent elements, except you want a div as a placeholder to load the data in anothe... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T05:54:42.180",
"Id": "22695",
"Score": "2",
"Tags": [
"javascript",
"html",
"css",
"layout"
],
"Title": "HTML - single page layout - absolute positioning"
} | 22695 |
<p>To provide some background context, I'm implementing a web-based solution (Java, Spring, Hibernate) that allows the creation/authoring of task-centric workflow documents. Basically a workflow provides an ordered collection of tasks (and related content) for a user to step through.</p>
<p>One of the available task ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T12:47:48.557",
"Id": "34865",
"Score": "2",
"body": "Why can't you have a `List` of `InternationalText`s?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T13:01:04.200",
"Id": "34867",
"Score":... | [
{
"body": "<ol>\n<li><p>I'd extract out a validation method:</p>\n\n<pre><code>private boolean isValidCoordinates(final int x, final int y) {\n if (x < 0 || x > 4 || y < 0 || y > 4) {\n return false;\n }\n return true;\n}\n</code></pre>\n\n<p>Currently it's duplicated.</p></li>\n<li>... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T07:06:06.390",
"Id": "22696",
"Score": "2",
"Tags": [
"java",
"database",
"reflection",
"hibernate"
],
"Title": "ORM Entity with many similar relationships"
} | 22696 |
<p>This should tell me whether the product is taxable or imported. Name should indicate if the product is imported or certain keywords should tell that the product is non-taxable (chocolates, book, pills).</p>
<p>Could you please review the following class products?</p>
<pre><code>class Product
NON_TAXABLE = [/choc... | [] | [
{
"body": "<p>Your <code>is_taxable?</code> function code does not seem to work. The issue is that <code>taxable</code> is never going to be true, so you'll never assign a new value. You want to write <code>if !taxable</code> instead. Your code becomes:</p>\n\n<pre><code>def is_taxable?\n taxable = false\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T07:41:28.763",
"Id": "22699",
"Score": "3",
"Tags": [
"object-oriented",
"ruby",
"finance"
],
"Title": "Determining if a product is taxable or imported"
} | 22699 |
<p>I came across polymorphism in the book that I'm reading and decided to do a little experiment. Essentially what I did was to create a base class called <code>Asset</code> and two subclasses that derive from Asset, called <code>Property</code> and <code>Stock</code>. I created instances of these two types and passed ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T11:08:43.873",
"Id": "34861",
"Score": "1",
"body": "Just because something is allowed doesn't mean it's a good idea to do it."
}
] | [
{
"body": "<p>You have to learn a lot about OOP... There is no polymorphism in your code, as this principle is designed to tackle exactly the kind of code you've written. </p>\n\n<p>The code that uses <code>Asset</code> <strong>should never</strong> branch its logic based on actual derived type (otherwise it wo... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T08:45:55.397",
"Id": "22702",
"Score": "0",
"Tags": [
"c#",
"polymorphism"
],
"Title": "Is this the proper way to find the subclass of a polymorphic superclass?"
} | 22702 |
<p>I am new to node.js and asynchronous programming and this is my first small project to learn it. I have written a small Telnet chat server and the program works but I want to know if this is the correct way to write programs in node.js (asynchronous programming model).</p>
<pre><code>var tcp = require('net');
var S... | [] | [
{
"body": "<p>From a once over:</p>\n\n<p><strong>Naming</strong></p>\n\n<ul>\n<li>variable names should start with a lower case letter, unless they are constructors\n<ul>\n<li><code>Server</code> -> <code>server</code></li>\n<li><code>Cpwd</code> -> <code>password</code></li>\n</ul></li>\n<li><code>pwd</code> ... | {
"AcceptedAnswerId": "38797",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T12:03:03.843",
"Id": "22706",
"Score": "2",
"Tags": [
"javascript",
"node.js",
"asynchronous",
"chat"
],
"Title": "Simple Telnet chat server"
} | 22706 |
<p>As part of a larger web app we are producing, I was asked to help build functionality to tie a page's shopping cart into <code>localStorage</code> for persistence. What follows are the three functions that I wrote that produce a JSON representation of the cart, and stores it in LS.</p>
<p>As far as I can tell, it a... | [] | [
{
"body": "<p>You should write a thin wrapper around <code>localStorage</code> so that you don't have to constantly ask <code>if (localStorage)</code> every time you want to use it. You can also do that test once, and if it doesn't exist, stub it out with a simple <code>{}</code>:</p>\n\n<pre><code>if (!localSt... | {
"AcceptedAnswerId": "22714",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T14:59:36.513",
"Id": "22711",
"Score": "3",
"Tags": [
"javascript",
"json",
"logging",
"e-commerce",
"browser-storage"
],
"Title": "localStorage functions for website s... | 22711 |
<p>I am leaning Haskell and decided to do the following <a href="http://www.scs.stanford.edu/11au-cs240h/labs/lab1.html" rel="nofollow">lab assignment</a> from <em>CS240h: Functional Systems in Haskell</em>. I welcome any advice on more idiomatic coding style and performance tips. </p>
<p>Notes:</p>
<ul>
<li>I chose ... | [] | [
{
"body": "<p>Inside do notation, you don't need to use <code>_ <-</code> to discard the value of a computation. So\n<code>_ <- update frequencies word (count + 1)</code> can be written as <code>update frequencies word (count + 1)</code></p>\n\n<p>Haskell programmers tend to prefer immutable collections l... | {
"AcceptedAnswerId": "22940",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T15:21:14.187",
"Id": "22713",
"Score": "6",
"Tags": [
"haskell"
],
"Title": "Counting word frequencies in Haskell"
} | 22713 |
<p>I have written a Backbone View (javascript) for a component called "twist-panel".</p>
<p>A twist panel is basically a card flip, it has a front and back side, and can flip to the back and to the front.</p>
<p>Here is the code:</p>
<pre><code>var TwistPanel = Backbone.View.extend({
initialize: function() {
t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T19:29:26.363",
"Id": "34898",
"Score": "0",
"body": "`var self = this;` seems to be missing in toFront?"
}
] | [
{
"body": "<p>The usual way I approach the problem is by asking: what <em>does</em> change?</p>\n\n<ul>\n<li><code>self.atFront</code> is flipped: not an issue here, you can simply write <code>self.atFront = !self.atFront</code>.</li>\n<li>conditions using <code>atFront</code> vs. <code>!atFront</code> (not an ... | {
"AcceptedAnswerId": "22742",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T16:37:02.657",
"Id": "22718",
"Score": "4",
"Tags": [
"javascript",
"backbone.js"
],
"Title": "Javascript plugin DRY"
} | 22718 |
<p>We need to select a model reference from a view. To do this we need to add a dropdownlistfor. This is based on a selectlist containing database models.</p>
<h2>passing selectlists by viewbag</h2>
<p>This solves our problem, but we do not like using ViewBag:</p>
<pre><code>public ActionResult Create()
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T09:34:15.477",
"Id": "34883",
"Score": "2",
"body": "In such cases i'm adding my selectlist to my model and pass it to my view, but stil wondering if there is a better solution +"
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<p>I think there are a few things that can be fixed here, but overall I don't think this is automatically an anti-pattern. It could just be executed a little better.</p>\n\n<p><em>Caveat: I don't practice what I preach nearly as often as I should.</em></p>\n\n<p>What I tend to do in my own projects, ... | {
"AcceptedAnswerId": "22806",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T09:30:05.553",
"Id": "22719",
"Score": "7",
"Tags": [
"c#",
"mvc",
"asp.net-mvc-4"
],
"Title": "Passing a selectlist to the view based on database models from viewmodel is a MV... | 22719 |
<p>I am trying to convert myself from using mysql extension to using PDO, with that being said I was curious if I am going about this the right way.</p>
<p>I have a custom logging system that I built I am wondering if the way I implemented this would work or not. I am planning on duplicating the main functions of PDO ... | [] | [
{
"body": "<p>This mostly looks good to me. \nI don't think that logging exceptions should be the concern of your rDB class. Also, you could utilize the <a href=\"https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md\" rel=\"nofollow\">PSR logger interface</a></p>\n\n<pre><code... | {
"AcceptedAnswerId": "22782",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T17:02:22.267",
"Id": "22720",
"Score": "6",
"Tags": [
"php",
"object-oriented",
"classes",
"pdo"
],
"Title": "PHP Extending PDO Class"
} | 22720 |
<p>I'm using a lightweight jQuery popup plugin called 'bPopup'. I'm using it on my website at the moment to load multiple popup windows when clicked. I was recently told that my code was inefficient as I was loading multiple popups with multiple JavaScript 'listeners':</p>
<pre><code><script type="text/javascript"&... | [] | [
{
"body": "<p>He is right. Think about maintenance. </p>\n\n<p>If you wanted to add another link that popped up another element you would need to add yet another listener function. Removing one would be the same thing. Too many things to keep track of.</p>\n\n<p>Change the code to add the event according to... | {
"AcceptedAnswerId": "22729",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T18:20:11.223",
"Id": "22724",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Using multiple popup windows with bPopup"
} | 22724 |
<p>What is the best way to <a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself" rel="nofollow">DRY</a> this code up?</p>
<pre><code>class NotificationsController < ApplicationController
before_filter :load_user
def unsubscribe
if @facebook_admin && @facebook_admin.auth_key == params[:auth... | [] | [
{
"body": "<p>Verbosity of a controller is typically a signal of dubious design. As I see it, you have two sensible options:</p>\n\n<ol>\n<li><p>If <code>User</code> and <code>FacebookAdmin</code> are two very different user entities: they should be treated in two separate controllers.</p></li>\n<li><p>If <code... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T19:17:21.307",
"Id": "22727",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Unsubscribing Facebook admins and regular users from notifications"
} | 22727 |
<p>I've been using JavaScript for some time now, but mostly just jQuery to prettify web pages. I've started doing some serious development with it in the last year.</p>
<p>So, I want to make sure I'm not doing something stupid. I found <a href="http://www.yuiblog.com/blog/2007/06/12/module-pattern/">a post about the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T21:13:08.237",
"Id": "34914",
"Score": "1",
"body": "I strongly suggest reading http://addyosmani.com/resources/essentialjsdesignpatterns/book/#revealingmodulepatternjavascript it's a great resource on JS design patterns, it's free ... | [
{
"body": "<ul>\n<li><p>Deep Namespacing Pitfalls</p>\n\n<p>JavaScript was not designed to handle very deep namespaces and does not have built-in ways to handle such. And further more, JS is NOT your typical, classical OOP language like Java, C++ and C# so better avoid such conventions.</p>\n\n<p>Also, I forgot... | {
"AcceptedAnswerId": "22758",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T21:02:38.613",
"Id": "22730",
"Score": "8",
"Tags": [
"javascript",
"design-patterns"
],
"Title": "JavaScript event handlers, scope, and the module design pattern"
} | 22730 |
<p>I'm making a comment box using a contenteditable div, but I want to remove formatting from text a user might copy/paste into it (also no <kbd>CTRL+B</kbd> or <kbd>CTRL+I</kbd> shortcuts allowed either). Only "approved" formatting ("tagged" names, URLs, etc).</p>
<p>Originally I went the regex route but was informed... | [] | [
{
"body": "<p>I struggled with the same issue in the past, and decided to simply use a disposable DOM element to convert the HTML to plaintext:</p>\n\n<pre><code>var message = \"...\"; // Contains HTML markup\nvar tmp = document.createElement(\"DIV\");\ntmp.innerHTML = message;\nvar message = tmp.textContent||t... | {
"AcceptedAnswerId": "26162",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T21:04:34.530",
"Id": "22731",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"dom",
"formatting"
],
"Title": "Stripping formatting from text - Am I using an efficient jQue... | 22731 |
<p>I'm writing the markup for <a href="https://i.stack.imgur.com/H9CKZ.jpg" rel="nofollow noreferrer"><em>Corpora - A Business Theme</em></a>:</p>
<p>And started from the header section:</p>
<p><img src="https://i.stack.imgur.com/M9Y7W.jpg" alt="Screenshot of header"></p>
<p>Here is my markup for it:</p>
<pre><code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T21:21:14.560",
"Id": "34917",
"Score": "3",
"body": "Welcome, SakerONE! Thanks for your question; I embedded the header screenshot for you."
}
] | [
{
"body": "<h3><code>address</code></h3>\n<p>I'd enclose the <code>ul.primaryContacts</code> in <em>one</em> <code>address</code> element (not every item separately):</p>\n<pre><code><address>\n <ul class="primaryContacts">\n <li>Phone: <em class="headerPhone">1.8... | {
"AcceptedAnswerId": "22748",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T21:13:48.820",
"Id": "22732",
"Score": "8",
"Tags": [
"html",
"html5"
],
"Title": "Semantically correct html5 markup"
} | 22732 |
<p>So the task is that a string being passed to one of my methods looks like this</p>
<p><code><DIV><GKY><UID><END></code></p>
<p>it is generated this way from another program, so it will always have that format. Now to sum up how it works is like this.. This is to represent 3 byte arrays a DI... | [] | [
{
"body": "<p>First of all separate code into header (<code>.hpp</code>) and implementation file (<code>.cpp</code>)</p>\n\n<p><strong>Header : (<code>my_header.hpp</code>)</strong></p>\n\n<pre><code>#ifndef MY_HEADER\n#define MY_HEADER\nclass KeyInputParser\n{\npublic:\n KeyInputParser () // there is no ne... | {
"AcceptedAnswerId": "22756",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-14T21:58:13.243",
"Id": "22734",
"Score": "2",
"Tags": [
"c++",
"parsing"
],
"Title": "String parser review"
} | 22734 |
<p>As the title says, I'm trying to make my code less horrible looking! For a university practical, I've to use recursive methods to return the even references in a collection of Integer objects stored in an <code>ArrayList</code>.</p>
<p>For example, if the input is [1, 2, 3, 4], my method should return [1, 3] (i.e. ... | [] | [
{
"body": "<p>I'm not sure if you're tied to having the method signature <code>public static ArrayList<Integer> evenList(ArrayList<Integer> tList)</code> and if you have to use the <code>deepClone</code> method you've got here, but if you aren't tied down to these restrictions, there are cleaner way... | {
"AcceptedAnswerId": "22737",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-02-14T23:00:32.623",
"Id": "22736",
"Score": "4",
"Tags": [
"java",
"recursion"
],
"Title": "Finding objects with even references tidier"
} | 22736 |
<p>So I am working on a LMS project and I have a User class that will handle everything about the user such as registration, login, showing list of courses that they are subscribed to, etc.</p>
<p><b>User.class.php</b></p>
<pre><code>class User {
protected $_firstName;
protected $_lastName;
protected $_em... | [] | [
{
"body": "<p>First of all I would split the <code>User</code> class in 2 or 3 classes <code>User</code>, <code>Authentication</code> and <code>Registration</code>. The setter error could easily become Exceptions, which you could collect in you Registration class.</p>\n\n<p>At the end you will have a smaller Us... | {
"AcceptedAnswerId": "22741",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-15T03:48:55.227",
"Id": "22738",
"Score": "4",
"Tags": [
"php",
"object-oriented",
"session"
],
"Title": "How to properly make a user class with a session"
} | 22738 |
<p>I wanted to write a multi-threaded sort, but unfortunately I don't know much about threads, especially in C++11. I managed to make something work, but I would be highly surprised if it was the best way to do it.</p>
<pre><code>template<class T>
void ___sort(T *data, int len, int nbThreads){
if(nbThreads&l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T20:53:17.247",
"Id": "35093",
"Score": "3",
"body": "Don't use '__' in an identifer name.http://stackoverflow.com/a/228797/14065"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-26T15:09:04.170",
"Id"... | [
{
"body": "<p>Something like this is probably more efficient:</p>\n<pre><code>template<class T>\nvoid parallel_sort(T* data, int len, int grainsize)\n{\n // Use grainsize instead of thread count so that we don't e.g.\n // spawn 4 threads just to sort 8 elements.\n if(len < grainsize)\n {\n ... | {
"AcceptedAnswerId": "22749",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-15T09:20:26.287",
"Id": "22744",
"Score": "7",
"Tags": [
"c++",
"multithreading",
"c++11",
"sorting"
],
"Title": "Multi-threaded sort"
} | 22744 |
<p>How can I make my model DRY and KISS?</p>
<pre><code>class Rating < ActiveRecord::Base
attr_accessible :item_type, :item_id, :rating, :voters_up, :voters_down
serialize :voters_up, Hash
serialize :voters_down, Hash
belongs_to :ranks, :polymorphic => true
def self.up(item, user, iteration = 1)
@... | [] | [
{
"body": "<p>Here's a 2-part answer: First, a direct answer to your question, and then an alternative approach to the whole thing.</p>\n\n<p><strong>DRYing the current implementation</strong><br>\nFirstly, I'd make sure that every \"item\" <code>has_one :rating</code>. Right now, you're doing a lot of manual r... | {
"AcceptedAnswerId": "22774",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-15T10:46:40.037",
"Id": "22746",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "ActiveRecord model for upvotes and downvotes"
} | 22746 |
<p>The idea is that i want any size string to put the corresponding hex value into a byte array. I've seen a million ways to do it. Some of them didn't look to clean. My needs are speed over memory, so chose to try and implement a lookup table. Tell me what you think</p>
<pre><code>const BYTE HEX[0x80] = //This is the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-15T23:58:37.097",
"Id": "34986",
"Score": "0",
"body": "Looks to me like you're opening yourself up to potential sign-extension vulnerabilities."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-16T00:29:27.0... | [
{
"body": "<p>Some minor comments:</p>\n\n<ul>\n<li><p>you are assuming there are no invalid chars in the input string.</p></li>\n<li><p>why not pass the string length into the function; the caller has to know it in order to allocate the hex buffer.</p></li>\n<li><p><code>len</code> could be <code>const</code><... | {
"AcceptedAnswerId": "23048",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-15T16:11:23.103",
"Id": "22757",
"Score": "7",
"Tags": [
"c++",
"parsing",
"converting"
],
"Title": "Char* hex string to BYTE Array"
} | 22757 |
<p>I'm trying to write a JMS Consumer using Akka-Camel. </p>
<p>For now, I'm using <a href="http://ffmq.sourceforge.net/" rel="nofollow">FFMQ</a> as a JMS server. I want to listen on the JMS queue <code>myqueue</code>.</p>
<p>Creating the JMS consumer actor is quite straightforward:</p>
<pre><code>import akka.camel.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-02-16T07:57:52.940",
"Id": "223681",
"Score": "0",
"body": "I found Gist with code sample of how to configure akka-camel jms for weblogic. https://gist.github.com/cjjavellana/2b422e694e5acf253d22"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-15T18:05:58.787",
"Id": "22761",
"Score": "4",
"Tags": [
"scala",
"jms",
"akka"
],
"Title": "Configuring a JMS Component in akka-camel"
} | 22761 |
<h1>Background</h1>
<p>Would like to create a two-key map that is fairly generic. In the existing system, there are a number of ways to name a parameter for a report. Rather than re-writing each report (too much effort), we'd like to simply map the old parameter names to new names.</p>
<p>For example, old names might... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-15T23:04:43.657",
"Id": "34979",
"Score": "1",
"body": "I am not sure if codereview is the right place. You are more asking for a solution, not to review some code. Nevertheless I do not really understand the problem. If you want to ha... | [
{
"body": "<p>I'd go with something which is similar to the mentioned <code>MultiKey</code>: create a <code>ReportParameter</code> class and use it as the key of the map:</p>\n\n<pre><code>public class ReportParameter {\n\n private final String reportName;\n private final Parameter parameter;\n\n publi... | {
"AcceptedAnswerId": "22971",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-15T22:17:31.060",
"Id": "22769",
"Score": "7",
"Tags": [
"java",
"hash-map"
],
"Title": "Two Key HashMap"
} | 22769 |
<p><a href="https://codereview.stackexchange.com/questions/22736/trying-to-make-recursive-code-designed-to-find-objects-with-even-references-tidi">Follow on from this question</a></p>
<p>This is a follow on question from one I asked a few days ago. I am making (or rather have made) a recursive method that takes a list... | [] | [
{
"body": "<p>I already explained in my other post, not to use this <code>tempStorage</code>variable in this way. At least (compared to the other version) you do not change the meaning of it in this version.<br>\nIf you rename it to something like <code>removedItemFromEvenIndex</code> it could be fine. If and r... | {
"AcceptedAnswerId": "22773",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-15T22:29:55.543",
"Id": "22770",
"Score": "3",
"Tags": [
"java",
"recursion"
],
"Title": "Avoiding use of an initialized variable that will either be changed or ignored"
} | 22770 |
<p>So I took a stab at this task to begin learning common lisp. </p>
<p>The idea is that you give it a written representation of a number such as "three thousand and forty nine" and it will output 3049.</p>
<p>I was looking for some input on my lisp and where I'm being daft or even what parts are good.</p>
<p>So wit... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-12-24T22:52:57.900",
"Id": "135971",
"Score": "0",
"body": "If you were bothered by the speed, you could simply generate the numbers representing the N first distinct letters of the words representing numbers, and then or them up to build... | [
{
"body": "<p>There are a couple of issues with your code. Let me describe a few:</p>\n\n<ul>\n<li><p>numbers are not <code>EQ</code>, use <code>EQL</code> or <code>=</code>.</p></li>\n<li><p>Common Lisp has documentation strings. Use them.</p></li>\n<li><p><code>if</code> <code>not</code> <code>progn</code> ca... | {
"AcceptedAnswerId": "22966",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-16T02:09:52.907",
"Id": "22775",
"Score": "3",
"Tags": [
"beginner",
"converting",
"common-lisp",
"numbers-to-words"
],
"Title": "Written numbers to numerical representation"
... | 22775 |
<p>I am building an app for android to control VLC (mediaplayer) that runs on my computer.
At the moment it's just a prototype that works, but I was wondering if I am correctly managing my HandlerThread and Socket.</p>
<p>My fear is that the thread keeps running too long or that I cause memory leaks. I have looked at... | [] | [
{
"body": "<p>From what I can see, it seems like you are doing it correctly.</p>\n\n<p>On some exceptions, you might want to alert your user with a message about what went wrong (for example, \"Connection failed\"). Few users can read stack traces while using an app.</p>\n\n<p>I only have a few comments regardi... | {
"AcceptedAnswerId": "35879",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-16T13:50:32.317",
"Id": "22778",
"Score": "5",
"Tags": [
"java",
"multithreading",
"android",
"socket"
],
"Title": "Socket handling in a thread"
} | 22778 |
<p>I am working on converting a PHP application to MVC, and have a couple questions!</p>
<p>1) I have a main Model object, that I require a database connection for, as well as a User object that uses a database object also. Is it a bad practice to create a new database object for each of these classes, like the follow... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-15T20:52:25.947",
"Id": "35009",
"Score": "3",
"body": "Yes, this is [WET code](http://en.wikipedia.org/wiki/Don%27t_repeat_yourself), bad code. Also consider: [How Not To Kill Your Testability Using Statics](http://kunststube.net/stat... | [
{
"body": "<p>In general, using the \"new\" keyword in any class is bad practice, because you're creating an implicit dependency. Instead, you should follow the \"ask, don't look\" design philosophy and require that the database object be passed to the class, rather than letting the class fetch it. Dependency i... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-15T20:49:01.690",
"Id": "22783",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"mvc"
],
"Title": "Instantiating objects in a MVC in PHP"
} | 22783 |
<p>I have written a piece of python code in response to the following question and I need to know if it can be "tidied up" in any way. I am a beginner programmer and am starting a bachelor of computer science.</p>
<blockquote>
<p><strong>Question:</strong> Write a piece of code that asks the user to input 10 integer... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-16T21:02:21.650",
"Id": "35021",
"Score": "0",
"body": "Thanks everyone for your input, i really appreciate that ! i will take a look at the extra code and try to understand how, where and why it fits in. !"
},
{
"ContentLicens... | [
{
"body": "<p>some advice:</p>\n\n<ul>\n<li>you don't need 10 named variables for the input, use an array instead, and a loop to do it</li>\n<li>use list comprehension to filter out all odd numbers</li>\n<li>take a look at the string formatting docs of python</li>\n</ul>\n",
"comments": [
{
"C... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-16T19:07:26.577",
"Id": "22784",
"Score": "28",
"Tags": [
"python",
"beginner"
],
"Title": "Asks the user to input 10 integers, and then prints the largest odd number"
} | 22784 |
<p>if node[i] and node[i+1] are present in the neighbor[i], then store the 'i' position of node and print the 'i' value of node.</p>
<p>this is also done by reversing the node array(only) and same type of check and print is done with the neighbor[i].</p>
<p>This code is written by me and works well, is there any othe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-16T23:38:12.813",
"Id": "35035",
"Score": "0",
"body": "Does it really work? Can I suggest that you separate the two cases (forward/reverse) into two functions, remove the assumed array sizes (pass them to the functions) and then defin... | [
{
"body": "<p>They key here is to to be able to abstract common functionality away. You're not expressing \"node[i] is in the neighbor array\" nicely. Simply write a function which does it for you:</p>\n\n<pre><code>int node_in_neighbors(int node, int neighbor[], int length) {\n int i;\n\n for(i = 0; i &l... | {
"AcceptedAnswerId": "22858",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-16T19:50:05.293",
"Id": "22786",
"Score": "3",
"Tags": [
"c",
"array"
],
"Title": "Matching element of arrays on a condition"
} | 22786 |
<p>I would like to turn the following:</p>
<pre><code><div>this is a $test</div>
</code></pre>
<p>into</p>
<pre><code><div>this is a <div>$test</div></div>
</code></pre>
<p>currently I have </p>
<pre><code>var regexp = new RegExp('$([^\\s]*)','g'),
html = '<div>this is... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T00:31:51.643",
"Id": "35037",
"Score": "0",
"body": "Maybe you are optimizing too early here."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T01:15:40.240",
"Id": "35039",
"Score": "0",
"b... | [
{
"body": "<p>Sure, use <a href=\"https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/replace\" rel=\"nofollow\">String.replace</a>. As an added bonus, it doesn't fail when there is no match:</p>\n\n<pre><code>'<div>this is a $test</div>'.replace(/(\\$\\w+)/g, '<di... | {
"AcceptedAnswerId": "22856",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T00:00:46.873",
"Id": "22801",
"Score": "2",
"Tags": [
"javascript",
"regex"
],
"Title": "Encapsulate results in div tags"
} | 22801 |
<p>This is a user JavaScript for YouTube. The point is to make the thumbnail bigger on mouseover. I just want some help making it better because I don't want it to waste resources with all the extensions I have and other scrips. I also added Iframes because I have another extension that makes a preview of the video in ... | [] | [
{
"body": "<p>I don't see anything in your code that should cause any performance issues. You're not doing anything iterative, or performing any complex operations; your code just executes linearly and changes some CSS properties. That shouldn't kill performance. </p>\n\n<p>Have you seen anything to indicate... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T00:18:08.850",
"Id": "22803",
"Score": "1",
"Tags": [
"javascript",
"optimization",
"performance",
"video"
],
"Title": "Increasing size of video thumbnail on mouseover"
} | 22803 |
<p>I have recently finished creating my own <code>Deck</code> class for my Poker game. It works the way I want it to, but I would like to know if I can make it better and/or more efficient.</p>
<p><strong>Deck.h</strong></p>
<pre><code>#ifndef DECK_H
#define DECK_H
#include "Card.h"
#include <iostream>
#inclu... | [] | [
{
"body": "<p>Never use <code>using namespace X;</code> in a header file. If I have to include your header you are polluting the global namespace for me and that can cause all sorts of problems in the code. As this is a potential source for bugs I will never use your header file (until you fix it).</p>\n\n<pre>... | {
"AcceptedAnswerId": "22808",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T01:34:43.907",
"Id": "22805",
"Score": "13",
"Tags": [
"c++",
"playing-cards"
],
"Title": "Card Deck class for a Poker game"
} | 22805 |
<p>I have a class that I am using to initialize a form for editing. Once the form is submitted, data validation is done through the setters of my class. Good or bad input will be set in order to re-display them in the form (is this bad?). Everything works fine, but I am not too happy with how I am storing and displayin... | [] | [
{
"body": "<p>The big disadvantage of putting the validation to the setter is that you are never able to set invalid values. In most cases this is fine, but in some scenarios a valid user input differs from a more general valid field content. In addition the validation is also executed to internal setter uses w... | {
"AcceptedAnswerId": "22812",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T04:19:24.693",
"Id": "22810",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"validation"
],
"Title": "Properly storing error messages and displaying them with OOP"
} | 22810 |
<p>Does this part look clean enough? Any suggestions on how to make it cleaner?</p>
<pre><code>if (isCheck)
{
if (isStuck)
{
return GameState.Mate;
}
else
{
return GameState.Check;
}
}
else
{
if (isStuck)
{
return GameState.Stalemate;
}
else
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T13:56:49.563",
"Id": "35063",
"Score": "19",
"body": "I think this is one of the cases where leaving out (some of) braces would improve your code."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T20:33... | [
{
"body": "<p>It depends on what you consider more readable, but you could use a binary-like way of expressing the variables as in a truth table:</p>\n\n<pre>isCheck isStuck Value\n=======================\nT T Mate\nT F Check\nF T Stalemate\nF F Ok\n</pr... | {
"AcceptedAnswerId": "22821",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T12:25:24.370",
"Id": "22815",
"Score": "74",
"Tags": [
"c#",
"enum"
],
"Title": "BOOL×BOOL→ENUM mapping"
} | 22815 |
<p>I'm coding a 2D collision engine, and I need to merge adjacent axis-aligned bounding boxes depending on a direction (left, right, top, bottom).</p>
<p>The four cases are very similar, except for the if condition, and the push_back argument.
Is there any way I can refactor this code without compromising performance... | [] | [
{
"body": "<p>Without knowing much about the <code>AABB</code> type, I'm assuming it has the operations <code>getBottom()</code>, and it's top-left-right couterparts.</p>\n\n<p>What you could do is set up functions which returns the appropiate result and pass it as an argument to the general function. I only sh... | {
"AcceptedAnswerId": "22833",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T13:08:23.567",
"Id": "22817",
"Score": "3",
"Tags": [
"c++",
"performance",
"c++11"
],
"Title": "Remove code duplication inside of a loop preserving performance"
} | 22817 |
<p>I have been trying to make a simple "quiz" program in Python. What I plan to make is, say, a quiz of 3 rounds and each round having 3 questions. And at the end of the every round, the program will prompt the user to go for the "bonus" question or not.</p>
<pre><code>print("Mathematics Quiz")
question1 = "Who is pr... | [] | [
{
"body": "<pre><code>asking = True\nattempts = 0\nwhile asking == True:\n response = input(\"Hit 'a', 'b', 'c' or 'd' for your answer\\n\")\n\n if response == \"d\":\n asking = False\n else:\n if attempts < 1: # 1 = Max Attempts\n print(\"Incorrect!!! Try again.\")\n ... | {
"AcceptedAnswerId": "22825",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T12:25:37.470",
"Id": "22822",
"Score": "3",
"Tags": [
"python",
"quiz"
],
"Title": "Simple quiz program"
} | 22822 |
<p>I have written my own for practice and also some tweaks for my specific requirement. There is an insert which can copy a range (well array copy really) which I am hoping is more efficient than individual element insert.</p>
<p>Can anyone make any comments specifically as regards efficiency and code elegance. I ne... | [] | [
{
"body": "<p>A few minor notes:</p>\n\n<ol>\n<li><p>Comments like the following are unnecessary:</p>\n\n<pre><code>private T[] array; // storage\n</code></pre>\n\n<p>You could call the field as <code>storage</code> and remove the comment.</p></li>\n<li><p>A \"solution\" for the warning in the constructor:</p>\... | {
"AcceptedAnswerId": "22904",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T15:33:13.640",
"Id": "22826",
"Score": "7",
"Tags": [
"java",
"circular-list"
],
"Title": "Circular buffer implementation for buffering TCP socket messages"
} | 22826 |
<p>I would like to advise if the following production code is good to be unit tested. The segment of the production code gets data from a backend service and displays it on the page. It is a class:</p>
<pre><code>...
// Extract this code into a separate method because it is called in more than 1 place
Keywords.protot... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-17T23:45:32.543",
"Id": "42786",
"Score": "0",
"body": "A general tip: Write the unit test first, then write the code that makes the unit test pass. That's the spirit of proper TDD, and that ensures that the code is easily testable."
... | [
{
"body": "<p>You're off to a bad start. You don't have a definition of what your <code>getKeywords()</code> method is supposed to do, which means you can't even begin to test it. On top of that, it seems to be named backwards - <code>getKeywords()</code> calls <code>addKeyword()</code>.</p>\n",
"comments... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T18:45:02.707",
"Id": "22830",
"Score": "1",
"Tags": [
"javascript",
"unit-testing"
],
"Title": "Production code to be good for unit testing"
} | 22830 |
<p>Inspired by <a href="http://jqueryboilerplate.com" rel="nofollow">jqueryboilerplate.com</a>, I extended their boilerplate to fit my needs. Coming from PHP development, I wanted to have a good starting point for writing jQuery plugins with a defined API/interface (more at <a href="http://jquib.web-sav.de" rel="nofoll... | [] | [
{
"body": "<p>Very interesting and fun question. Boilerplate code is a reason to close questions down, but this code is a perfectly valid question.</p>\n\n<p><strong>Naming</strong></p>\n\n<ul>\n<li>JavaScript uses lowerCamelCase variable and function names, avoid names like <code>public_interface</code> and <c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T19:25:51.273",
"Id": "22831",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"api",
"plugin",
"interface"
],
"Title": "jQuery plugin boilerplate jquib"
} | 22831 |
<p>I'm writing a markup for: <br>
<a href="https://i.stack.imgur.com/XiRcL.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XiRcL.jpg" width="200" height="260"></a><br><br>
And I've split it for these sections:</p>
<pre><code><header>
<div id="logo"></div>
<nav id="mainNa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T07:02:15.467",
"Id": "35102",
"Score": "1",
"body": "The template is here: http://templates.websitetemplatesonline.com/Progress-business/index.html and I don't know if it's OK to rip it off like this."
}
] | [
{
"body": "<p>After writing html structure, I explicitly check for at least two things.</p>\n\n<ul>\n<li>Are there any <code>div</code>s that can go away?</li>\n<li>Can I remove any <code>class</code> or <code>id</code>? </li>\n</ul>\n\n<p>Let's try to apply this to your code:</p>\n\n<pre><code><header>\n... | {
"AcceptedAnswerId": "22848",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T19:45:05.187",
"Id": "22832",
"Score": "4",
"Tags": [
"html",
"html5"
],
"Title": "HTML5 semantic layout (div, article, section) and explicit identifiers"
} | 22832 |
<p>I have just started to learn programming with Python. I have been going through several online classes for the last month or two. Please bear with me if my questions are noobish.</p>
<p>One of the classes I am taking asked us to solve this problem.</p>
<pre><code># Define a procedure, check_sudoku,
# that takes as... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T22:58:29.257",
"Id": "35094",
"Score": "0",
"body": "The problem seems poorly stated. A Sudoku grid has *three* types of constraint: rows, columns, and *blocks*. A grid that only has row and column constraints is known as a [Latin s... | [
{
"body": "<p>I would use <a href=\"http://docs.python.org/2/library/stdtypes.html#set-types-set-frozenset\"><code>set</code></a> to do the checks, and you can build the columns using some <a href=\"http://docs.python.org/2/library/functions.html#zip\"><code>zip</code></a> magic:</p>\n\n<pre><code>def check_sud... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T21:28:47.017",
"Id": "22834",
"Score": "5",
"Tags": [
"python",
"beginner",
"sudoku"
],
"Title": "Check_sudoku in Python"
} | 22834 |
<p>Sadly <a href="https://connect.microsoft.com/VisualStudio/feedback/details/752794/std-chrono-duration-cast-lacks-double-support">VS2012's <code>duration_cast</code> is broken</a>, and I actually need the functionality which is broken. So, I wrote my own: </p>
<pre><code>template<typename ToUnit, typename Rep, ty... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T16:06:01.957",
"Id": "35136",
"Score": "0",
"body": "Links don;t work for me. What is a duration_cast<> supposed to do?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T16:28:06.807",
"Id": "35140"... | [
{
"body": "<p>I can't say for sure about the internal logic but I can point some problems or things that could be improved in your piece of code:</p>\n\n<ul>\n<li><p>First of all, <code>typename</code> is missing before the names, making your code non-working with some compilers. I would also use <code>using</c... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-17T22:33:13.260",
"Id": "22836",
"Score": "7",
"Tags": [
"c++",
"c++11",
"casting"
],
"Title": "Is this a conforming implementation of duration_cast?"
} | 22836 |
<p>I've used EF-DB first approach and have written a simple app to retrieve the data from the database and show it in the view. The code is simple and ok for a beginner like me, but how can I implement an effective design-pattern like interface-specification pattern or generic repository pattern, and possibly dependenc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T09:25:57.347",
"Id": "35106",
"Score": "1",
"body": "If you want to improve performance, you can start by removing the intermediate `ToList()` calls, you probably don't even need em. If EF complains about the operations you're doin... | [
{
"body": "<p>The only way DI (IoC) is going to improve this code is by extracting the creation and disposal of your data context. This also means you can mock it for your unit tests.</p>\n\n<p>You could argue the DataContext already is a Repository.</p>\n\n<p>You could do one of:</p>\n\n<ul>\n<li>Leave it as i... | {
"AcceptedAnswerId": "23000",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T09:08:05.167",
"Id": "22850",
"Score": "1",
"Tags": [
"c#",
"performance",
".net",
"asp.net",
"entity-framework"
],
"Title": "How can I implement the generic repository... | 22850 |
<p>I've written an implementation of the back-propagation algorithm in Clojure (<a href="https://gist.github.com/m0a0t0/4976438" rel="nofollow">here</a>). This is my first attempt at Clojure where the code totals more than ten lines and so it is not very idiomatic; specifically in one of my functions I have this:</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-02T03:54:30.170",
"Id": "85574",
"Score": "0",
"body": "Refactor the inner loop into another function. Also, the loops could be turned into reducers. These would clean up the code considerably :)"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T14:19:58.913",
"Id": "22859",
"Score": "3",
"Tags": [
"clojure",
"neural-network"
],
"Title": "Back-propagation implementation"
} | 22859 |
<p>I'm creating a CRUD page. My first approach was use the same class editCategory.php for doing these actions:</p>
<ul>
<li>If this file is called via GET and categoryId parameter doesn't exist -> shall show a empty form</li>
<li>If this file is called via GET and categoryId parameter is provided -> shall show a form... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T21:24:48.417",
"Id": "35159",
"Score": "1",
"body": "I'm not quite sure everything is wrong here. I'd expect `$action = isset($_POST[\"action\"]);` to assign a boolean value to $action as per http://php.net/manual/fr/function.isset.... | [
{
"body": "<p>Your concept using the HTTP verbs is pretty much the idea behind REST. You could go one step further and use the less known verbs like PUT, DELETE, UPDATE. </p>\n\n<p>Also u could use the $_SERVER['REQUEST_METHOD'] to switch between the HTTP modes you would like to process. </p>\n\n<p>I would sugg... | {
"AcceptedAnswerId": "22955",
"CommentCount": "12",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T16:41:41.330",
"Id": "22864",
"Score": "1",
"Tags": [
"php"
],
"Title": "Insert, update and get in the same php file?"
} | 22864 |
<p>I've written a short program to find solutions to the <a href="http://en.wikipedia.org/wiki/36_cube" rel="nofollow">36 Cube puzzle</a>.</p>
<p>I'm trying to break away from my normal Java / imperative style, and would like some feedback on how I'm doing.</p>
<p><strong>Puzzle.scala</strong></p>
<pre><code>package... | [] | [
{
"body": "<h2>Puzzle.scala</h2>\n\n<pre><code>case class CubePuzzle(val board: Board, val availablePieces: List[Piece]) \n</code></pre>\n\n<p>Case classes don't need \"val\" before field names.</p>\n\n<pre><code>def solve(solutionsSoFar: List[Board]=List[Board]()): List[Board] =\n</code></pre>\n\n<p>More idiom... | {
"AcceptedAnswerId": "22902",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T17:52:59.637",
"Id": "22865",
"Score": "5",
"Tags": [
"scala"
],
"Title": "How idiomatic is this Scala 36 Cube Solver?"
} | 22865 |
<p>At work, we have a "pair programming ladder" where you can keep track of who is pairing with whom (based on check-ins). The idea is to promote "promiscuous pairing" where each developer eventually pairs with every other developer.</p>
<p>In our team, this was being updated <em>manually</em>, so I thought of writin... | [] | [
{
"body": "<pre><code>from git import *\n</code></pre>\n\n<p>Generally import from * is frowned upon as it makes it more difficult to figure out where stuff comes from</p>\n\n<pre><code>import re\nfrom collections import Counter\n\nlist = [\"Adam\", \"Bill\", \"Carl\", \"David\", \"Eddie\", \"Frank\", \"George\... | {
"AcceptedAnswerId": "22872",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T18:27:25.200",
"Id": "22866",
"Score": "3",
"Tags": [
"python",
"parsing",
"matrix",
"git"
],
"Title": "Pair programming matrix"
} | 22866 |
<h3>Premise</h3>
<p>Consider the following method:</p>
<pre><code>static String formatMyDate(Date date) {
return new SimpleDateFormat("yyyy-MM-dd").format(date);
}
</code></pre>
<p>It's often desirable to memoize <code>DateFormat</code> objects so they can be reused rather than repeatedly instantiating new ones.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T19:04:59.003",
"Id": "35151",
"Score": "2",
"body": "Is there a reason you have to use java.util.Date instead of JodaTime? The JodaTime library has a DateTimeFormat class that is thread-safe. As a side note, you can look at the so... | [
{
"body": "<p>It looks like the questions are very specific. You should probably formulate a goal. Is your main goal to reduce code duplicity? Memory usage? Speed (however we define it here)? Something else? A combination of previous items? (which makes life harder the more items you combine)\nThis affects the ... | {
"AcceptedAnswerId": "22908",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T18:32:35.467",
"Id": "22867",
"Score": "7",
"Tags": [
"java",
"memoization",
"guava"
],
"Title": "Helper class to memoize DateFormats application-wide"
} | 22867 |
<p>I'm trying to run a bit of code when my <code>loginManager</code> is logged in. It might be already, or I might be waiting:</p>
<pre><code>var loginManager = chrome.extension.getBackgroundPage().LoginManager;
// If the foreground is opened before the background has had a chance to load, wait for the background.
//... | [] | [
{
"body": "<p>I would recomend you watch <a href=\"https://tutsplus.com/lesson/custom-events-and-the-observer-pattern/\" rel=\"nofollow\">this video</a> about custom events and the Observer Pattern (Pub/Sub) by Jeffery Way. He does a great job of explaining this concept and also provides some good reading mater... | {
"AcceptedAnswerId": "22893",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T18:33:37.993",
"Id": "22868",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"backbone.js"
],
"Title": "Login manager model"
} | 22868 |
<p>Could someone please point out the error(s) in the given code? It was downvoted on Stack Overflow without any explanation, but it seems to be working fine for me:</p>
<pre><code>int value(char roman)
{
switch(roman)
{
case 'I':return 1;
case 'V':return 5;
case 'X':return 10;
c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T02:57:24.213",
"Id": "35169",
"Score": "1",
"body": "Roman Numeral converter in 855 chars :-) http://codegolf.stackexchange.com/questions/797/roman-numeral-converter-function/828#828"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>There is a G++ compile warning (<code>g++ -Wall</code>):</p>\n\n<pre><code>roman.cpp: In function ‘int value(char)’:\nroman.cpp:18:1: warning: control reaches end of non-void function [-Wreturn-type]\n</code></pre>\n\n<p>It should handle invalid inputs too. (Furthermore, it returns 9 for <code>III... | {
"AcceptedAnswerId": "22886",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-18T23:04:13.313",
"Id": "22876",
"Score": "10",
"Tags": [
"c++",
"roman-numerals"
],
"Title": "Converting Roman numerals to decimal"
} | 22876 |
<p>Could someone please help me make this code as professional as it can be? It works fine, but I feel there's a better way of doing this. I would really appreciate some guidance so I learn to code better.</p>
<pre><code> $(function () {
$('#subForm').submit(function (e) {
e.preventDefault... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T16:56:55.790",
"Id": "35208",
"Score": "1",
"body": "Not sure where the bug is, but it looks much better already. I would just call `moveDiv()` instead of `$.change(moveDiv)`;"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cre... | [
{
"body": "<p>This is typical jQuery mess. If you write a lot of code like this every day, consider switching to frameworks like Backbone or Ember.js which will make your life easier. Concerning this code, here are my remarks:</p>\n\n<ul>\n<li>Care more about indentation! All those callbacks are hard enough to ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T00:54:56.980",
"Id": "22879",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"json",
"form"
],
"Title": "jQuery form data"
} | 22879 |
<p>I have a list of elements (well, nested lists of elements, really) that the user can reorder (using jQuery <code>sortable()</code>). A simplified view of the structure is something like:</p>
<pre><code><div class="contentList">
<div class="content" />
<div class="content">
<div... | [] | [
{
"body": "<p>Try using the children selector: <a href=\"http://api.jquery.com/children/\" rel=\"nofollow\">http://api.jquery.com/children/</a>.</p>\n\n<p>This only retrieves the first set of nested items (one level down vs. find which goes all the way down). I'm not sure how you're nested exactly with your ot... | {
"AcceptedAnswerId": "22885",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T04:15:13.943",
"Id": "22881",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"optimization",
"performance"
],
"Title": "Optimize jQuery Iteration"
} | 22881 |
<p>I'm trying to solve the <a href="http://en.wikipedia.org/wiki/Four_color_theorem" rel="nofollow">four color theorem</a> in Ruby.</p>
<p>A map is like this:</p>
<pre><code>ccaaaa
baaadc
babcdc
bbbcdc
abcccc
</code></pre>
<p>I have this, but it's slow. How can I make it better?</p>
<pre><code>#!/usr/bin/env ruby
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T12:23:46.087",
"Id": "35183",
"Score": "0",
"body": "How are you defining slow? The algorithm itself is optimal, and the code is fast! You could go for micro-optimizations, but how fast do you want the code to be? And for what map s... | [
{
"body": "<h1>I/O bottleneck</h1>\n\n<p>Your first bottleneck is not the algorithm. As you see from your <code>time</code> output (<code>0.29s user 0.11s system 10% cpu 3.723 total</code>), your program only spent 10% of his time in the CPU. This means that even if your program took 0ms, you would only gain 10... | {
"AcceptedAnswerId": "22890",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T10:47:25.910",
"Id": "22887",
"Score": "3",
"Tags": [
"optimization",
"ruby"
],
"Title": "Four color theorem"
} | 22887 |
<p>Am I doing it fine?? Its only for setup not executed repeatedly</p>
<pre><code>CREATE TABLE #temp
(
id INT IDENTITY(1, 1),
name_file VARCHAR(500),
depth_tree VARCHAR(10),
is_folder_files VARCHAR(10)
)
/* xp_dirtree selects file from specific l... | [] | [
{
"body": "<p>I think it might be useful to separate comments about the code itself from comments about your general approach (here is your <a href=\"https://stackoverflow.com/questions/14919382/executing-xp-cmdshell-in-remote-server\">related question</a> on SO for reference).</p>\n\n<p>In general the code is ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T17:59:12.383",
"Id": "22896",
"Score": "-1",
"Tags": [
"sql",
"sql-server",
"t-sql"
],
"Title": "Using xp_cmdshell"
} | 22896 |
<p>I have been trying to design a good data layer that will eventually be generated. I am wondering if I have missed anything. The basic architecture contains a service class that handles connecting and eventually transactions. I wrap the <code>IDbConnection</code> in the service class to make sure it gets disposed pro... | [] | [
{
"body": "<p>The drawback is that you are limiting the functionality of your service to perform one query per connection and you have no \"batch mode\"</p>\n\n<p>But maybe you can implement a query batching method!</p>\n\n<p>For this reason, the user of the database service perhaps should have the power to ope... | {
"AcceptedAnswerId": "22899",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T18:48:35.483",
"Id": "22898",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Is wrapping the service layer worthwhile?"
} | 22898 |
<p>I'm creating a system and I'm using EF with Linq. I create my Model (<strong>.edmx</strong>) and using it, I generated my database and my classes. Like the Usuario (user in Portuguese going to keep the names in Portuguese to avoid some misleading).</p>
<pre><code>namespace SistemaBox.Model
{
public partial clas... | [] | [
{
"body": "<p>Your connection string is actually a private class member. I would probably put private keyword explicitly to make it clear.</p>\n\n<p>connString is going to be initialized each time the class instance is created. But the connection string is not going to change in run time so it worth to make con... | {
"AcceptedAnswerId": "22956",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T19:41:47.257",
"Id": "22900",
"Score": "1",
"Tags": [
"c#",
"linq",
"controller"
],
"Title": "Linq to sql performance"
} | 22900 |
<p>I'm basically trying to write a helper function that reads a whole file and returns the data and the number of bytes read.</p>
<p>Can you tell me if is correctly written and used?</p>
<pre><code>#include <iostream>
static char * ReadAllBytes(const char * filename, int * read)
{
ifstream ifs(filename, io... | [] | [
{
"body": "<p>A few things I would do differently:</p>\n<pre><code>static char * ReadAllBytes(const char * filename, int * read)\n{\n ifstream ifs(filename, ios::binary|ios::ate);\n ifstream::pos_type pos = ifs.tellg();\n\n // What happens if the OS supports really big files.\n // It may be larger t... | {
"AcceptedAnswerId": "22907",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T19:42:14.297",
"Id": "22901",
"Score": "16",
"Tags": [
"c++",
"file-system"
],
"Title": "Reading all bytes from a file"
} | 22901 |
<p>Example that could be turned into a button to view user's public ftp where initial page is "<a href="http://user.school.edu/" rel="nofollow">http://user.school.edu/</a>":</p>
<pre><code>javascript:(function( {
var h,i,t;
h=window.location.hostname;i=h.IndexOf('.school.edu');t=h.substring(0,i);
window.locat... | [] | [
{
"body": "<pre><code>(function () {\n var h = window.location.hostname;\n window.location = 'ftp://ftp.school.edu/public/' + h.substring(0, h.indexOf('.'));\n}());\n</code></pre>\n\n<ul>\n<li><p>In JS, you can merge declaration and definition. The compiler takes care of splitting them to declaration and defi... | {
"AcceptedAnswerId": "22924",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T21:21:45.877",
"Id": "22903",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "Parse and Redirect to uri in Javascript"
} | 22903 |
<p>I have a simple servlet which merely serves some cached data back to the user. I also have a background thread which runs at fixed intervals to refresh the cached data. Is this a reasonable implementation?</p>
<pre><code>@WebServlet("/CachingServlet")
public class CachingServlet extends HttpServlet {
private ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T23:25:09.423",
"Id": "35222",
"Score": "0",
"body": "Seems reasonable to me."
}
] | [
{
"body": "<p>you needn't call <code>super.init();</code> <a href=\"http://docs.oracle.com/javaee/6/api/javax/servlet/GenericServlet.html#init%28%29\" rel=\"nofollow\">according to docs</a>, it is a NOP . but as a rule calling initializers of some superclass at the beginning of the overriding method will save y... | {
"AcceptedAnswerId": "22930",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-19T22:21:01.553",
"Id": "22906",
"Score": "1",
"Tags": [
"java",
"multithreading",
"servlets"
],
"Title": "Correct implementation for background task execution in web application?... | 22906 |
<p>I tried to refactoring someone else's code and I found that there is alot of this pattern</p>
<pre><code>def train(a, b, c, d, e, f, g, h, i, j, k): #Real code has longer name and around 10-20 arguments
x = Dostuff()
y = DoMoreStuff(b,c,d,e,f,g,h,x)
z = DoMoreMoreStuff(a,b,d,e,g,h,j,y)
def DoMoreStuff(... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-20T07:31:48.753",
"Id": "35241",
"Score": "5",
"body": "If you asked me, if you have a function that requires that many independent parameters, it's trying to do too much. You could also consider changing it so the function uses keywor... | [
{
"body": "<p>Well, the answer depends on the meaning of the variables. If they are related (and they should be, since the same functions uses them!), then it's a good idea to group them in a dictionary since it makes the code more readable.</p>\n\n<p>However, even if it makes sense to group all variables into ... | {
"AcceptedAnswerId": "22921",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-20T06:50:32.060",
"Id": "22911",
"Score": "3",
"Tags": [
"python"
],
"Title": "Is there any downside to define a function that use one dictionary as an argument instead of several (+10) a... | 22911 |
<p>I've written a class to make async SQL calls and it appears to work like a charm! But I'm a bit concerned about what it means to send a lot of queries to the server and then aborting them by throwing an abort exception on the calling thread. Is this a problem?</p>
<p>The code also launches a lot of threads. Is the... | [] | [
{
"body": "<ul>\n<li>Your code does not follow naming conventions (private fields should be camelCased, and usually have an underscore prefix; parameters should be camelCased)</li>\n<li>there is no need in private properties, use fields instead (<code>ConnectionString</code>)</li>\n<li>It is not an <em>asynchro... | {
"AcceptedAnswerId": "22916",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-20T07:37:40.250",
"Id": "22913",
"Score": "7",
"Tags": [
"c#",
".net",
"sql",
"asynchronous"
],
"Title": "Making async SQL calls"
} | 22913 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.