body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>For my current project we are commnunicating with an old mainframish hospital information system. This system has a service called 'Facelink' which is a simple TCP connection with a fixed set of commands. The problem is that a user can only be logged in one time. As we're hosting a web frontend with a lot of links t...
[]
[ { "body": "<p>Why not place the magic numbers into your class as constants?</p>\n\n<pre><code>class FacelinkProxyServer {\n const USER_ID = \"001 User Identification\"\n // and so on\n}\n</code></pre>\n\n<p>Then you can access them in the class as their name and outside as <code>FacelinkProxyServer::USER_ID...
{ "AcceptedAnswerId": "1524", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-03-29T07:42:36.363", "Id": "1518", "Score": "5", "Tags": [ "php", "object-oriented" ], "Title": "Review for a PHP socket proxy" }
1518
<p>I want to use Tweets sent out by a twitter account as a command to shut down Ubuntu. For this, I've written a Python script using <a href="https://github.com/joshthecoder/tweepy" rel="nofollow">tweepy</a>, a Python library for Twitter. I scheduled the script to run half past the hour every hour (for eg at 5:30, 6:30...
[]
[ { "body": "<pre><code>import tweepy\nimport os\nfrom datetime import datetime\np=None\n</code></pre>\n\n<p>Use of single letter variable names is confusing, I have no idea what p is for.</p>\n\n<pre><code>api= tweepy.API()\n</code></pre>\n\n<p>Put spaces around your =</p>\n\n<pre><code>for status in api.user_ti...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-29T17:24:54.500", "Id": "1525", "Score": "5", "Tags": [ "python", "datetime", "linux", "twitter" ], "Title": "Using tweet as command to shut down Ubuntu" }
1525
<p>The following code generates all \$k\$-subsets of a given array. A \$k\$-subset of set \$X\$ is a partition of all the elements in \$X\$ into \$k\$ non-empty subsets.</p> <p>Thus, for <code>{1,2,3,4}</code> a 3-subset is <code>{{1,2},{3},{4}}</code>.</p> <p>I'm looking for improvements to the algorithm or code. Sp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-04-02T11:48:53.323", "Id": "154375", "Score": "0", "body": "See also: [Iterator over all partitions into k groups?](http://stackoverflow.com/q/18353280/562769)" } ]
[ { "body": "<p>Here's the obligatory recursive version:</p>\n\n<pre><code>def k_subset(s, k):\n if k == len(s):\n return (tuple([(x,) for x in s]),)\n k_subs = []\n for i in range(len(s)):\n partials = k_subset(s[:i] + s[i + 1:], k)\n for partial in partials:\n for p in r...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-29T17:44:53.210", "Id": "1526", "Score": "20", "Tags": [ "python", "algorithm", "combinatorics" ], "Title": "Finding all k-subset partitions" }
1526
<p>Here is the database query needed to create the database:</p> <pre><code>create table Area ( AreaId int primary key identity(1,1), Name nvarchar(64) not null ) create table Level ( LevelId int primary key identity(1,1), Name nvarchar(32) not null, Principle nvarchar(512) not null ) create table Subject ( SubjectI...
[]
[ { "body": "<p>Here are some observations:</p>\n\n<ol>\n<li>Beware of storing calculated information in the database, especially time-sensitive values like <code>YearsOfService</code>. You must ensure to have a (yearly?) process update this column based on the current date and <code>DateOfHiring</code>. What hap...
{ "AcceptedAnswerId": "1543", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-29T20:55:06.960", "Id": "1528", "Score": "7", "Tags": [ "sql", "sql-server" ], "Title": "Database schema for a school" }
1528
<p>I am creating a form class for validating form data, and would like some advice on how to refactor it for best practices. Keep in mind that this is a rough draft.</p> <p>Basically, there is a form abstract class (<code>lev_form</code>), which you would extend. In the extended classes, you would write a <code>__cons...
[]
[ { "body": "<p>I jumped straight down to <code>lev_field_validation</code> as it's the most interesting class.</p>\n\n<ol>\n<li>Whenever I see a giant <code>switch()</code> block, I immediately suspect there are a lot of subclasses trying to break out. Each validation type should be a different subclass with an ...
{ "AcceptedAnswerId": "1532", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-29T22:40:21.557", "Id": "1530", "Score": "2", "Tags": [ "php", "validation", "form" ], "Title": "Form validator class and child classes" }
1530
<blockquote> <p><strong>Exercise 1.31</strong></p> <p>a. The sum procedure is only the simplest of a vast number of similar abstractions that can be captured as higher-order procedures.51 Write an analogous procedure called product that returns the product of the values of a function at points ove...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-03-30T02:52:18.823", "Id": "2665", "Score": "0", "body": "I meant to post this at codereview.stackexchange.com - can it be migrated?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-03-30T03:07:21.597", "Id": ...
[ { "body": "<p>Since your definitions have only two <code>cond</code> clauses, you may replace <code>cond</code> with <code>if</code>. Your iterative definition is a departure from the example of <code>sum</code>. It should return 1 (product identity) when <code>a</code> is greater than <code>b</code>, not nul...
{ "AcceptedAnswerId": "1579", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-30T02:49:42.020", "Id": "1534", "Score": "0", "Tags": [ "lisp", "scheme" ], "Title": "Writing a product() function analogous to sum" }
1534
<p>Given the following recursive definition of sum:</p> <blockquote> <pre><code>(define (sum term a next b) (if (&gt; a b) 0 (+ (term a) (sum term (next a) next b)))) </code></pre> </blockquote> <p>And the task: </p> <blockquote> <p><strong>Exercise 1.30</strong></p> <p>The sum procedur...
[]
[ { "body": "<p>I believe your answer is correct, although I'm not sure why you need the <code>identity</code>, <code>inc</code>, and <code>sum-integers</code> procedure on the bottom for your solution.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-03-30...
{ "AcceptedAnswerId": "1536", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-30T01:48:08.220", "Id": "1535", "Score": "0", "Tags": [ "recursion", "lisp", "scheme", "sicp" ], "Title": "Iterative sum using recursion" }
1535
<p>As an answer to this problem:</p> <blockquote> <p><strong>Exercise 1.29</strong></p> <p>Simpson's Rule is a more accurate method of numerical integration than the method illustrated above. Using Simpson's Rule, the integral of a function f between a and b is approximated as (h / 3) * (y_0 + 4y_1...
[]
[ { "body": "<p>When you call <code>sum</code>, make sure you start with 1 (and not 0). Otherwise, you get an error of + 2 y_0 h / 3. In case of <code>(simpsons-rule cube 1 2 1000)</code>, this error is 0.000666....</p>\n\n<p>Another way to rewrite the series is to group even and odd terms together, excluding t...
{ "AcceptedAnswerId": "1580", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-30T04:07:50.277", "Id": "1538", "Score": "2", "Tags": [ "lisp", "scheme", "sicp", "numerical-methods" ], "Title": "Integral using Simpson's Rule" }
1538
<p>Given this task:</p> <blockquote> <p><strong>Exercise 1.32</strong></p> <p>a. Show that sum and product (exercise 1.31) are both special cases of a still more general notion called accumulate that combines a collection of terms, using some general accumulation function:</p> <p>(accumulate comb...
[]
[ { "body": "<p>Since the only parameter that changes in your recursive definition is <code>a</code>, you can write an inner definition like so:</p>\n\n<pre><code>(define (accumulate combiner null-value term a next b)\n (define (rec a)\n (if (&gt; a b)\n null-value\n (combiner (term a) (rec (nex...
{ "AcceptedAnswerId": "1583", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-30T04:22:13.963", "Id": "1539", "Score": "0", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Show that sum and product are both examples of accumulation" }
1539
<p>Given the following task:</p> <blockquote> <p><strong>Exercise 1.33</strong></p> <p>You can obtain an even more general version of accumulate (exercise 1.32) by introducing the notion of a filter on the terms to be combined. That is, combine only those terms derived from values in the range that ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-01T00:26:22.550", "Id": "2766", "Score": "0", "body": "idk if you consider it contrary to this exercises purpose, or maybe efficiency is it a premium, but you might consider just writing a standalone `filter` function and composing the...
[ { "body": "<p>Since you're recursing only on <code>a</code> and possibly <code>result</code>, you can use an inner <code>define</code> that only changes these arguments.</p>\n\n<p>When an item matches a filter condition, you can ignore it by recursing on the remaining items. You need not give it a <code>null-v...
{ "AcceptedAnswerId": "1590", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-30T05:07:05.873", "Id": "1541", "Score": "1", "Tags": [ "primes", "lisp", "scheme", "sicp" ], "Title": "Filtered-Accumulate" }
1541
<p>Some days ago I made you a question and I got some really useful answers. I will make a summary to those of you who didn't read and I will explain my new doubts and where I have problems now.</p> <p><strong>Explanation</strong></p> <p>I have been working on a program, simulating a small database, that first of all...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-07T12:23:00.473", "Id": "2971", "Score": "1", "body": "It does not sound like a codereview question." } ]
[ { "body": "<p>If you want to optimize your code, I would first suggest you to profile your code (some for windows can be found here : <a href=\"https://stackoverflow.com/questions/67554/whats-the-best-free-c-profiler-for-windows-if-there-are\">https://stackoverflow.com/questions/67554/whats-the-best-free-c-prof...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-30T16:00:50.470", "Id": "1556", "Score": "2", "Tags": [ "c++", "optimization" ], "Title": "Optimizing my code that simulates a database" }
1556
<p>I'm working with the following code which adjusts an int based on multiple elements of an integer array. I am wondering if there's a cleaner, easier-to-read construct for this:</p> <pre><code>int Blue = 0; int[] Adjustments = new int[24]; // ... populate Adjustments if (Adjustments[0] == 255) Blue = 128; else ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-05T16:45:00.760", "Id": "2915", "Score": "1", "body": "You could just write `1 << (7-i)` instead of `AdjustmentStops[i]` and get rid of the array, but it’s up to you to decide whether you find that too unreadable." } ]
[ { "body": "<p>How about the following?</p>\n\n<pre><code>int Blue = 0;\nint[] Adjustments = new int[ 24 ];\nint[] BlueAdditions = new int[] { 128, 64, 32, 16, 8, 4, 2, 1 };\n// ... populate Adjustments\n\nfor ( int i = 0; i &lt; 8; ++i )\n{\n if ( Adjustments[ i ] == 255 )\n {\n Blue += BlueAdditio...
{ "AcceptedAnswerId": "1559", "CommentCount": "1", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-03-30T16:22:16.147", "Id": "1557", "Score": "5", "Tags": [ "c#", "array", "integer" ], "Title": "Adjusting integer based on multiple elements in int array" }
1557
<p>I have a simplified model that looks like this:</p> <pre><code>class Player &lt; ActiveRecord::Base has_many :picks def pick_for_game(game) id = game.instance_of?(Game) ? game.id : game pick = picks.find {|pick| pick.game_id == id} if !pick pick = picks.build(:game_id =&gt; id) end pi...
[]
[ { "body": "<p>You can use <code>find_or_initialize_by</code> dynamic finder, see a guide <a href=\"http://edgeguides.rubyonrails.org/active_record_querying.html#dynamic-finders\" rel=\"noreferrer\">here</a></p>\n\n<p>This would be equivalent to your code:</p>\n\n<pre><code>def pick_for_game(game)\n game_id = g...
{ "AcceptedAnswerId": "1561", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-03-30T17:51:04.763", "Id": "1558", "Score": "6", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Find associated object if exists, otherwise generate it" }
1558
<p>This function will read an expression (made up of tokens) from the vector of tokens passed into it. It will remove the tokens that make up the expression from the vector and return them.</p> <p>A token is added to the expression if</p> <ul> <li>it is the first token</li> <li>it has an operator before it</li> </ul>...
[]
[ { "body": "<p>My first thought is that parsers should be implemented as table driven state machines for exactly the reason you see in the code :-)</p>\n\n<p>Actually, I think breaking this into a set of separate functions is one good approach, and adding a new enum to support it makes it very clear the state of...
{ "AcceptedAnswerId": "1604", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-30T23:01:48.203", "Id": "1564", "Score": "9", "Tags": [ "c++" ], "Title": "Monster token parser function" }
1564
<p>I'm a little unsure as to what code belongs in the services and what belongs in the controllers.</p> <p>Lets say I'm creating a website that requires a fine grained level of permissions (e.g. a user has permissions based on their user level (if they're currently logged in) determining whether they can view, edit, a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-31T14:47:42.217", "Id": "8630", "Score": "0", "body": "Clarifying question: are these WCF services or Web/ASMX services? Are they also written in C# or are they in another language?" }, { "ContentLicense": "CC BY-SA 3.0", "...
[ { "body": "<p>My first instinct is to suggest using built-in ASP.NET Roles. This is handled at the ASP.NET level, so in general you can redirect to the appropriate View. You may have roles for 'Anon' 'Read' and 'ReadWrite' and possibly more. This will help with the first pass authorization, not at the specific ...
{ "AcceptedAnswerId": "1643", "CommentCount": "3", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-03-31T01:12:51.827", "Id": "1567", "Score": "4", "Tags": [ "asp.net-mvc-3", "vb.net" ], "Title": "Is this a proper use of a services project and an ASP.NET MVC controller?" }
1567
<p>Given the following exercise:</p> <blockquote> <p>Exercise 1.37. a. An infinite continued fraction is an expression of the form</p> <p><img src="https://i.stack.imgur.com/mrsXH.gif" alt="infinite continued fraction"></p> <p>As an example, one can show that the infinite continued fraction expansio...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-03-31T02:33:22.897", "Id": "2744", "Score": "0", "body": "this portion of the book - http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-12.html#%_sec_1.3.3" } ]
[ { "body": "<p>Your solutions look good. </p>\n\n<p>I don't see any significantly different way to do the recursive solution. My preferences for whitespace (mostly concerning the <code>if</code>) are a little different. Also, I wouldn't define a function for <code>next</code> in this situation. If for some r...
{ "AcceptedAnswerId": "1578", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-31T02:12:19.007", "Id": "1568", "Score": "0", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Infinite Continued Fraction - iterative and recursive" }
1568
<p>Given the following task:</p> <blockquote> <p>Exercise 1.38. In 1737, the Swiss mathematician Leonhard Euler published a memoir De Fractionibus Continuis, which included a continued fraction expansion for e - 2, where e is the base of the natural logarithms. In this fraction, the Ni are all 1, and ...
[]
[ { "body": "<p>Your definition of <code>d</code> is not quite right. It produces incorrect results for some values of <code>i</code> and it has two special cases which are not necessary. A possible definition is:</p>\n\n<pre><code> (define (d i)\n (cond\n ((divisible? (+ i 1) 3) \n (* (/ (+ i 1)...
{ "AcceptedAnswerId": "1576", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-31T02:52:45.587", "Id": "1569", "Score": "1", "Tags": [ "programming-challenge", "mathematics", "scheme", "sicp" ], "Title": "Compute e using Euler's expansion" }
1569
<p>There are two aspects to this question that are inter-related.</p> <ol> <li>Change I've made to the <code>trie</code> module in python (<a href="http://pypi.python.org/pypi/trie" rel="nofollow">PyPI</a>, <a href="https://github.com/dhain/trie" rel="nofollow">GitHub</a>) to make it serialisable (and deserialisable)....
[]
[ { "body": "<p>Use None rather then Node.no_value.</p>\n\n<p>None is the typical value to use for the absence of value. However, its possible that you actually want to store None in your trie, so that doesn't work.</p>\n\n<p>Checking the type of the object is not really a good plan because somebody could decide ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-31T09:09:14.720", "Id": "1574", "Score": "2", "Tags": [ "python", "trie" ], "Title": "Serialising missing values in trie" }
1574
<p>I'm creating a gradebook. Many students earn a grade in many standards each. I'm hoping to get help analyzing the code below for efficient use of asynchronous result fetching. <code>ofy</code> is an <code>Objectify</code> object, which is basically just a convenience wrapper over the async fetching capabilities of...
[]
[ { "body": "<p>With Objectify, you have the option to use the \"in\" operator in a query. Moreover, it becomes clear from the second block of nested loops that you are only looking for the intersection of the two sets of measuredUserIds and standardIds. So, a single statement should do the trick:</p>\n\n<pre><co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-03-31T13:50:47.757", "Id": "1581", "Score": "2", "Tags": [ "java", "google-app-engine" ], "Title": "Querying the same fields for many different values on AppEngine" }
1581
<p>I've been working on a Stack Overflow like pager for my personal use and I've gotten everything working pretty good. Some of my logic is a bit suspect though, especially the logic in the Pager class itself. I thought I'd try posting this code on here just to see what sort of responses I got. I included my test ca...
[]
[ { "body": "<p>It's a little wonky to have a</p>\n\n<pre><code>public int PageNumbersToShow { get; set; }\n</code></pre>\n\n<p>Then do all dis bizness in the toString() method</p>\n\n<pre><code>if (TotalPages &lt;= PageNumbersToShow) {\n\n for (int i = 1; i &lt;= TotalPages; i++) {\n finalString.Append(n...
{ "AcceptedAnswerId": "1597", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-31T16:19:07.987", "Id": "1585", "Score": "8", "Tags": [ "c#", "asp.net" ], "Title": "Stack Overflow like pager" }
1585
<p>I had this as an interview question, and the interviewer pointed this out. Here's what I wrote:</p> <pre><code>//C# Syntax here public string Reverse(string s) { char[] arr = s.ToCharArray(); int idx = 0; int endIdx = s.Length - 1; for(; idx &lt; endIdx; ++idx, --endIdx) { char temp = ar...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-03-31T16:15:19.683", "Id": "2752", "Score": "4", "body": "I think this would be a better question for codereview.stackexchange.com or stackoverflow." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-03-31T16:18:03....
[ { "body": "<p>I would argue against changing it. This seems to be exactly what for-loops were invented for. Also, why not put the initialization in the for loop?</p>\n\n<p>I would have also preferred</p>\n\n<pre><code>for(int idx=0; idx &lt; endIdx; ++idx, --endIdx) {\n</code></pre>\n\n<p>if only so that I don'...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-31T16:13:57.610", "Id": "1586", "Score": "18", "Tags": [ "c#", "strings", "interview-questions", "comparative-review" ], "Title": "Reversing a string" }
1586
<p>I want to write my own version of <code>HttpUtility.ParseQueryString</code>, because it is not included in the .NET Framework Client Profile. My code is pretty straightforward and simple, but I'm looking at the code of <code>HttpUtility.ParseQueryString</code> with Reflector, and is about 200 lines including the cod...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-03-31T20:24:32.597", "Id": "2759", "Score": "0", "body": "Should I assume my code is OK from not getting any answer?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-02T06:22:11.750", "Id": "2798", "Sco...
[ { "body": "<p>I figure <code>HttpUtility.ParseQueryString</code> is just incredibly robust, and you likely are missing something. But I can't spot anything in particular and it's likely that without deep research you won't be able to cover all the cases which were clearly studied and thought out in Microsoft's ...
{ "AcceptedAnswerId": "1592", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-03-31T18:12:19.840", "Id": "1588", "Score": "12", "Tags": [ "c#", "url" ], "Title": "Get params from a URL" }
1588
<p>Given the following task from <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html" rel="nofollow">SICP</a></p> <blockquote> <p><strong>Exercise 2.1</strong></p> <p>Define a better version of make-rat that handles both positive and negative arguments. Make-rat should normalize the sign...
[]
[ { "body": "<p>To normalize a fraction, one needs to do two things:</p>\n\n<ol>\n<li>fix the signs of numerator and denominator; and</li>\n<li>reduce them to their lowest terms.</li>\n</ol>\n\n<p>Your implementation does these two things just fine. However, there is an easier way. To do (1), simply negate both...
{ "AcceptedAnswerId": "1620", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-01T04:39:54.070", "Id": "1596", "Score": "2", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Make a version of make-rat that handles positive and negative arguments" }
1596
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html" rel="nofollow">SICP</a>:</p> <blockquote> <p><strong>Exercise 2.2</strong></p> <p>Consider the problem of representing line segments in a plane. Each segment is represented as a pair of points: a starting point and an ending ...
[]
[ { "body": "<p>Your definitions of <code>make-segment</code> and <code>make-point</code> can be simply bound to <code>cons</code>; you may do the same for accessors.</p>\n\n<pre><code>(define make-segment cons)\n(define start-segment car)\n(define end-segment cdr)\n\n(define make-point cons)\n(define x-point car...
{ "AcceptedAnswerId": "1614", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-01T04:58:39.810", "Id": "1598", "Score": "2", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Midpoint of a segment" }
1598
<p>I had a job to remove all kinds of comments from the Lua file. I tried to find a usable Python script to this on the net, but Google did not help. </p> <p>Therefore, I made one. This script recognizes all types of comments such as single and multi-Line comments.</p> <p>I would welcome your opinion.</p> <pre><cod...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-03T12:46:27.847", "Id": "2861", "Score": "0", "body": "Link to a site with comment examples is missing." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-03T12:46:58.877", "Id": "2862", "Score": "1", ...
[ { "body": "<p>Firstly, I think you have some subtle bugs. </p>\n\n<ul>\n<li>What if -- appears inside a string?\nIn that case it should not be a\ncomment.</li>\n<li>What if someone ends a block and starts another one on the same line: --]] --[[</li>\n<li>You split on '\\r\\n', if you run this on a linux system...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-01T09:43:43.037", "Id": "1601", "Score": "4", "Tags": [ "python" ], "Title": "Lua comment remover" }
1601
<p>I am new to using classes heavily, and was wondering if going so far as to create a class specifically for templates was going to far. Here is a simplified version of my class template. Yes, I know I the use of <code>unset</code> is not necessary, but I like it there so don't give me any grief for it.</p> <pre><cod...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-02T01:29:06.547", "Id": "2797", "Score": "1", "body": "Could you clarify the usage of this class? It looks to me like a base class to be extended." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-05T18:00:16...
[ { "body": "<p>Philosophically I would try to use built-in classes as much as possible, and this seems like the beginnings of the <a href=\"http://www.php.net/manual/en/class.messageformatter.php\" rel=\"nofollow\">MessageFormatter</a> class. </p>\n\n<p>As a side note, you seem to have a typo:</p>\n\n<pre><code...
{ "AcceptedAnswerId": "1641", "CommentCount": "3", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-01T13:00:09.917", "Id": "1605", "Score": "3", "Tags": [ "php", "classes" ], "Title": "PHP, Is creating a class for templates to much?" }
1605
<p>In <a href="https://stackoverflow.com/questions/5489626/c-f0-vs-perl-f0/5489809#5489809">response</a> to the SO question <em><a href="https://stackoverflow.com/questions/5489626/c-f0-vs-perl-f0">C: f>0 vs Perl: $f>0?</a></em>, the use of overflow to terminate the loop is referred to as "poor programming practice". P...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-08T12:14:24.840", "Id": "108889", "Score": "0", "body": "Use `LLONG_MAX` or `ULLONG_MAX` from `<<limits.h>`." } ]
[ { "body": "<p>Good programming practice is knowing that your loop is going to exit. In your case, the exit condition is <code>fib &lt;= 0</code>. Thinking about the algorithm, is <code>fib</code> ever going to be non-positive?</p>\n\n<p>You want to exit after some sort of condition. For sequences like this you ...
{ "AcceptedAnswerId": "1680", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-01T14:23:04.167", "Id": "1607", "Score": "7", "Tags": [ "c", "integer", "fibonacci-sequence" ], "Title": "Terminating a C loop when maximum hardware limit reached" }
1607
<p>I am hoping the code is readable as is. I can probably just print the XML using streams but I have other reasons for using the library.</p> <p>Please offer any inputs on how to improve program design/structure.</p> <p>The header file </p> <pre><code>#ifndef GEN_XML #define GEN_XML #include &lt;iostream&gt; #incl...
[]
[ { "body": "<p>I would remove the validate method and do some modifications:</p>\n\n<p>About <code>validate</code>:</p>\n\n<ul>\n<li>Check <code>argc</code> and <code>argv</code> outside the class, just provide the <code>filename</code> to the <code>getData</code> method.</li>\n<li>You also need to check when <c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-01T15:14:14.773", "Id": "1608", "Score": "4", "Tags": [ "c++", "xml" ], "Title": "Generating XML file from text input" }
1608
<p>I am trying to cycle through a few of these blocks. They basically narrow down a number of people that fulfill a bunch of attributes.</p> <p>I apologize if this seems really messy, but my database is really taking a toll processing this, and I know there's a better way. I'm just lost on strategy right now.</p> <pr...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-01T19:38:43.747", "Id": "2785", "Score": "0", "body": "It would help if you explained a bit about self.distributions and CardSignup etc. contain." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-01T19:43:45....
[ { "body": "<p>The first thing I notice is that you're calling <code>map.{}.compact</code> when you probably could be calling <code>select{}</code>, that is, you want to select from self.distribution. So that would replace 6 method calls with 3.</p>\n\n<p>If you use select, it always returns an array and never a...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-01T19:12:21.093", "Id": "1611", "Score": "3", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Counting subscribers with matching ZIP code, interests, and sex" }
1611
<p>Having fancy animations in WPF is quite nice so I tried to implement a generic fading animation for <code>UIElements</code> which I use for the Popups in my application. I was wondering if there was anything wrong with it, and thought about posting it here yesterday. There were indeed many things wrong at that time ...
[]
[ { "body": "<p>I would focus on <code>BeginAnimationDetail</code> method. </p>\n\n<ul>\n<li><p><strong>Variable names</strong>. I would rename at least these variables - <code>tempTrans</code> and <code>trans</code>. <code>tempTrans</code> name doesn't give me any idea what is this variable about. I would name i...
{ "AcceptedAnswerId": "1619", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-01T21:30:39.930", "Id": "1617", "Score": "4", "Tags": [ "c#", "wpf", "easing" ], "Title": "Custom UIElement Animations" }
1617
<p>I don't really have any specific questions for this thread. I have been working on an independent project recently and have been learning everything from the web. Just yesterday I became aware of templating and the idea of separating business and presentational logic.</p> <p>I would be very thankful for any comment...
[]
[ { "body": "<p>Well, it's good that you thought of it. And you are definitely moving in the right direction. Your code seems to be fine, but still not very readable and not very structured. Try to organize your code to classes or smaller functions. E.g. this:</p>\n\n<pre><code>if (isset($_GET['sort']))\n if (...
{ "AcceptedAnswerId": "1625", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-02T05:55:12.787", "Id": "1621", "Score": "4", "Tags": [ "php" ], "Title": "Site design for upvote/downvote submissions" }
1621
<p>You may see full code <a href="https://github.com/agladysh/luatexts/blob/9d47f9c7ef1c1e5a9ade29fda0526e392bc7ddeb/src/c/luatexts.c" rel="nofollow">here</a> (note that the link points to the specific commit).</p> <p>Language is "clean C" (that is, a subset of C89, C99 and C++98 — it is intended to compile under all ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-03T07:16:52.050", "Id": "2846", "Score": "2", "body": "This could be a lot simpler. Compare to the functions [pg_utf8_islegal](http://git.postgresql.org/gitweb?p=postgresql.git;a=blob;f=src/backend/utils/mb/wchar.c;h=5b0cf628fe9a470ce...
[ { "body": "<p>One obvious issue - the longest valid Unicode character is represented by 4 bytes in UTF-8. Although it is possible to extend the logic to 5 or 6 bytes, there is no need since Unicode is a 21-bit codeset.</p>\n\n<p>Be careful about using version 3.2 of the Unicode standard; the current version is...
{ "AcceptedAnswerId": "1631", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-02T14:02:20.753", "Id": "1624", "Score": "7", "Tags": [ "c++", "c", "portability", "utf-8" ], "Title": "UTF-8 character reader function" }
1624
<p>I've had a go at writing something that generates a random maze using disjoint sets using the grouping class I found <a href="http://code.activestate.com/recipes/387776-grouping-objects-into-disjoint-sets/" rel="nofollow">here</a>.</p> <p>The way I'm generating the maze is by generating all the cells, with each cel...
[]
[ { "body": "<pre><code>import random\nfrom grouper import Grouper\nimport sys\n\nX = 20\nY = 20\n\nclass Cell():\n</code></pre>\n\n<p>Either put object as the base class, or don't include the (). It doesn't really matter, but I think this is ugly.</p>\n\n<pre><code> \"\"\"Represents a cell in the maze, with a...
{ "AcceptedAnswerId": "1627", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-02T23:00:42.540", "Id": "1626", "Score": "7", "Tags": [ "python" ], "Title": "Generating a random maze using disjoint sets" }
1626
<p>I'm currently working on a project where I am trying to predict a presidential election based on the population density and region of a voter. I wrote a few MATLAB functions to parse the data, but it takes about a minute to run, which seems long. My languages of choice are usually Java or Python and I feel like thi...
[]
[ { "body": "<p>Replacing loops in MATLAB with equivalent matrix operations (a technique commonly referred to as <em>vectorization</em>) often, but not always, leads to improvements in performance. However, this frequently results in code that may be difficult for others to read, so it is advisable to use the pro...
{ "AcceptedAnswerId": "1999", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-04T01:12:00.667", "Id": "1634", "Score": "4", "Tags": [ "optimization", "matrix", "matlab" ], "Title": "Presidential election predictor using matrix-processing" }
1634
<p>Given the following exercise:</p> <blockquote> <p><strong>Exercise 2.5</strong></p> <p>Show that we can represent pairs of nonnegative integers using only numbers and arithmetic operations if we represent the pair a and b as the integer that is the product 2^a * 3^b. Give the corresponding defini...
[]
[ { "body": "<p>Your definition of <code>cons</code> is perfect.</p>\n\n<p>Your definitions of <code>car</code> and <code>cdr</code> contain the <code>log</code> operation, which is a floating-point operation. Not only are its results imprecise, it is not needed to solve this problem. Furthermore, notice that t...
{ "AcceptedAnswerId": "1656", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-04T01:40:50.313", "Id": "1635", "Score": "2", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Represent pairs of nonnegative integers using 2^a * 3^b" }
1635
<p>Given the following exercise:</p> <blockquote> <p><strong>Exercise 2.6</strong></p> <p>In case representing pairs as procedures wasn't mind-boggling enough, consider that, in a language that can manipulate procedures, we can get by without numbers (at least insofar as nonnegative integers are con...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-04T20:58:54.840", "Id": "64377", "Score": "0", "body": "I see that you can define 'inc' as `function inc(n,f,x) {n(f(x))}` and `function inc(n,f,x) {f(n(x))}`. Right?" } ]
[ { "body": "<p>Church defined numerals as the repeated application of a function. The first few numerals are defined thus:</p>\n\n<pre><code>(define zero (lambda (f) (lambda (x) x)))\n(define one (lambda (f) (lambda (x) (f x))))\n(define two (lambda (f) (lambda (x) (f (f x)))))\n</code></pre>\n\n<p>... and so o...
{ "AcceptedAnswerId": "1661", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-04T02:07:06.193", "Id": "1636", "Score": "2", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Church Numerals - implement one, two, and addition" }
1636
<p>From the Extended Exercise beginning in section <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html" rel="nofollow">2.1.4</a>, you can find exercise 2.8:</p> <blockquote> <p>Exercise 2.8. Using reasoning analogous to Alyssa's, describe how the difference of two intervals may be computed. ...
[]
[ { "body": "<p>Looks great. Don't forget to define <code>lower-bound</code> and <code>upper-bound</code> as <code>car</code> and <code>cdr</code> respectively.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-05T11:0...
{ "AcceptedAnswerId": "1662", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-04T02:29:41.437", "Id": "1638", "Score": "1", "Tags": [ "scheme", "sicp", "interval" ], "Title": "Interval Subtraction" }
1638
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html" rel="nofollow">2.11</a></p> <blockquote> <p>Exercise 2.11. In passing, Ben also cryptically comments: ``By testing the signs of the endpoints of the intervals, it is possible to break mul-interval into nine cases, only one of w...
[]
[ { "body": "<p>Your logic is correct.</p>\n\n<p>You may use <code>let</code> instead of <code>let*</code> since the value of one binding does not depend on the value of another binding.</p>\n\n<p>Since efficiency is important, you can cut back on the number of comparisons as well. For example, if <code>u-x</cod...
{ "AcceptedAnswerId": "1691", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-04T04:59:02.780", "Id": "1639", "Score": "1", "Tags": [ "scheme", "sicp", "interval" ], "Title": "A more efficient mul-interval" }
1639
<p>Since I did not get a satisfactory answer <a href="https://stackoverflow.com/questions/5531130/an-efficient-way-to-shuffle-a-json-array-in-java">here</a> (and I really needed to get it going on this weekend), I decided to implement my own Fisher–Yates shuffle, porting the code I found in other SO posts. I know my pr...
[]
[ { "body": "<p>It runs in <span class=\"math-container\">\\$O(n)\\$</span> time so I'm not sure there's a way to improve this. It looks like you've implemented the algorithm pretty well, according the <a href=\"https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle\" rel=\"nofollow noreferrer\">Fisher-Yates...
{ "AcceptedAnswerId": "1642", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-04T06:08:39.277", "Id": "1640", "Score": "3", "Tags": [ "java", "array", "json", "shuffle" ], "Title": "Shuffling a JSON array in Java" }
1640
<p>I've just tried to do some code for <code>TreeMap</code>. The <code>TreeMap</code> concept can be found <a href="http://hcil.cs.umd.edu/trs/91-03/91-03.html" rel="nofollow">here</a>. As an exercise I've tried to find the solution without reading the article.</p> <p>Then, I came across this code. The main problem is...
[]
[ { "body": "<p><strong>repr</strong> shouldn't be used as a general pretty print method. It should give a short description of an object, preferably one which looks like code. </p>\n\n<p>Its best to use correct english in variable names, i.e. children not childs.</p>\n\n<p>Rather then combining a lot of strings,...
{ "AcceptedAnswerId": "1645", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-04T18:13:32.763", "Id": "1644", "Score": "5", "Tags": [ "python", "tree" ], "Title": "TreeMap implementation" }
1644
<p>SICP exercise 2.18 asks the following:</p> <blockquote> <p>Exercise 2.18. Define a procedure reverse that takes a list as argument and returns a list of the same elements in reverse order:</p> </blockquote> <pre><code>(reverse (list 1 4 9 16 25)) (25 16 9 4 1) </code></pre> <p>I wrote this iterative func...
[]
[ { "body": "<p>Not much different from yours, and kind of sloppy with the list mechanics (id generally prefer to use <code>cons</code> over <code>append</code>)</p>\n\n<pre><code>&gt; (define (rev l)\n (if (null? (cdr l))\n l\n (append (rev (cdr l)) (list (car l)))))\n&gt; (rev '(1 2 3 4))\n(4 3...
{ "AcceptedAnswerId": "1654", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-05T05:24:34.233", "Id": "1648", "Score": "2", "Tags": [ "recursion", "lisp", "scheme", "sicp" ], "Title": "Design a procedure to reverse a list" }
1648
<blockquote> <p><strong>Exercise 2.20</strong></p> <p>The procedures +, *, and list take arbitrary numbers of arguments. One way to define such procedures is to use define with dotted-tail notation. In a procedure definition, a parameter list that has a dot before the last parameter name indicates ...
[]
[ { "body": "<p>If one were to abstract out the filter function (named <code>filt</code> here), it would greatly simplify writing <code>same-parity</code>:</p>\n\n<pre><code>(define (filt test? lis)\n (cond\n ((null? lis) lis)\n ((test? (car lis)) (cons (car lis) (filt test? (cdr lis))))\n (else (filt t...
{ "AcceptedAnswerId": "1655", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-05T06:05:56.427", "Id": "1649", "Score": "1", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Filter a list of integers by parity" }
1649
<blockquote> <p><strong>Exercise 2.23</strong></p> <p>The procedure for-each is similar to map. It takes as arguments a procedure and a list of elements. However, rather than forming a list of the results, for-each just applies the procedure to each of the elements in turn, from left to right. The ...
[]
[ { "body": "<p>No. Your function needs to handle the empty list too. If your implementation supports <code>unless</code>, use this:</p>\n\n<pre><code>(define (for-each f l)\n (unless (null? l)\n (f (car l))\n (for-each f (cdr l))))\n</code></pre>\n\n<p>Otherwise, the R5RS-compatible version would be:</p>\...
{ "AcceptedAnswerId": "1652", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-05T06:23:34.690", "Id": "1651", "Score": "1", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "A definition of for-each" }
1651
<p>I don't see any way to refactor this, but something tells me I'm missing something.</p> <pre><code>if val.instance_of?(Hash) then @fields.has_key?(key) ? @fields[key].merge!(val) : @fields.merge!({key =&gt; val}) elsif val.instance_of?(Array) then @fields.has_key?(key) ? @fields[key].push(val) : @fields.mer...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-05T12:16:06.380", "Id": "2909", "Score": "2", "body": "Could you explain what you want the code to do? I have a feeling that it does not do what you want in all cases (for example because `push` and `<<` do the same thing on arrays, bu...
[ { "body": "<p>There are some obvious targets for refactoring, such as <code>Array.new.push(val)</code> instead of <code>[val]</code>, but to me this entire code block stinks. The most obvious <a href=\"http://en.wikipedia.org/wiki/Code_smell\" rel=\"nofollow\">smell</a> is the type checking necessitated by a la...
{ "AcceptedAnswerId": "1833", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-05T11:56:53.763", "Id": "1663", "Score": "3", "Tags": [ "ruby" ], "Title": "Add data of unknown type to a hash" }
1663
<p>I have a list of map entries, and I need an iterable that returns the keys. </p> <p>Of course, we could be naive and copy over into a new collection of the desired type, but that's inefficient.</p> <p>So let's see if we can provide a view of the existing structure using generics. Yes, I was able to do that, but ...
[]
[ { "body": "<p>Just parameterize with both types:</p>\n\n<pre><code>class ListKeyIterable&lt;K,T extends List&lt;? extends Map.Entry&lt;K,?&gt;&gt;&gt; implements Iterable&lt;K&gt;;\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-05T22:12:00...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-05T21:30:23.580", "Id": "1668", "Score": "2", "Tags": [ "java", "iterator" ], "Title": "Can you make this Key-interable view of a List of Maps better?" }
1668
<p>I'm changing code that writes data to a DB, so I have a dump (a text file) of an earlier run to compare against, to ensure that my changes don't screw things up. Here goes:</p> <pre><code>def dbcheck(cursor): dbresult = list() cursor.execute("SELECT COLUMN FROM TABLE") for item in cursor.fetchall(): ...
[]
[ { "body": "<p>Use zip to iterate over both iterators at the same time. It'll only use the memory needed to hold a single entry from each at a time.</p>\n\n<pre><code>def dbcheck(cursor):\n cursor.execute(\"SELECT COLUMN FROM TABLE\")\n with open(dbdump) as f:\n for item, line in zip(cursor, f):\n ...
{ "AcceptedAnswerId": "1674", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-05T22:02:19.110", "Id": "1669", "Score": "5", "Tags": [ "python" ], "Title": "Reducing memory usage when comparing two iterables" }
1669
<p>I was wondering if my code will produce a true singleton. I am creating an Android app, and all activities should access my API through one instance of the <code>SyncApi</code> class.</p> <pre><code>public class Api { private static SyncApi api = null; static { synchronized (api) { if...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-06T09:24:07.117", "Id": "2930", "Score": "2", "body": "If you don’t want laziness, why not initialise the `SyncApi` instance directly in the declaration? No need for the `static` constructor. Java guarantees that initialisation of stat...
[ { "body": "<p>In Java there’s an established idiom for creating a <a href=\"http://en.wikipedia.org/wiki/Singleton_pattern\">thread-safe singleton</a>, due to Bill Pugh:</p>\n\n<pre><code>public class Api {\n private Api() { }\n\n private static class SingletonHolder { \n public static final SyncAp...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-06T03:56:45.273", "Id": "1673", "Score": "41", "Tags": [ "java", "android", "singleton" ], "Title": "Is my code a 'safe' singleton?" }
1673
<p>Is there a better way of doing this?</p> <pre><code>File.open( "/etc/my.cnf" ) do |f| f.grep( /^testdir/ ) do |line| test1 = line.chop.gsub(/ /,"") test2 = test1.sub(/.*=/, "") RETURN_PATH = "#{test2}/test_ups" end end </code></pre>
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-06T14:30:28.310", "Id": "2936", "Score": "3", "body": "What's wrong with this one? What do you want to improve? Define *better*." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-06T14:33:36.767", "Id": "...
[ { "body": "<p>Aside from not using a constant for <code>RETURN_PATH</code> (which is obviously wrong and will cause Ruby to warn you), it seems reasonable enough to me.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-0...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-06T14:29:19.257", "Id": "1677", "Score": "2", "Tags": [ "ruby", "mysql", "ruby-on-rails", "parsing" ], "Title": "Extracting and mangling a parameter from a MySQL configuration fi...
1677
<p>Which one of the following is preferrable and why when writing C macro?</p> <p><strong>Type 1</strong></p> <pre><code>#define I2C_START() I2C_WAIT_IDLE(); SSP1CON2bits.SEN = 1 </code></pre> <p><strong>Type 2</strong></p> <pre><code>#define I2C_START() \ do ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-16T04:20:20.290", "Id": "3214", "Score": "0", "body": "http://c-faq.com/cpp/multistmt.html explains it in detail." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-08T17:28:13.567", "Id": "70750", "Sc...
[ { "body": "<p>I prefer the second one because it can be used with normal compound stamens without modifications or accidentally being used incorrectly.</p>\n<pre><code>if (condition)\n I2c_START; \n</code></pre>\n<p>Type 1: FAIL<br />\nType 2: OK</p>\n<p>Of course with good coding standards that can be avoi...
{ "AcceptedAnswerId": "1686", "CommentCount": "2", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-06T16:56:46.907", "Id": "1679", "Score": "7", "Tags": [ "c", "macros" ], "Title": "'do { statement; } while(0)' against 'statement' when writing C macro?" }
1679
<p>I've written the code below to do some work on machine learning in R. I'm not overly happy with some bits of it, and I suspect I could improve it quite a bit. Bits I'm specifically interested in looking at are how to deal with appending to vectors in the loop, and whether I can combine all of the functions <code>kf....
[]
[ { "body": "<p>You can avoid appending to vectors (which can cause re-allocation of space and can considerably slow things down in principle; though in your case of only a length 10 vector that shouldn't be noticeable) if you allocate them to the needed size initially and then assign within them.</p>\n\n<pre><co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-06T18:07:25.917", "Id": "1681", "Score": "5", "Tags": [ "r", "clustering", "machine-learning" ], "Title": "Performing machine learning" }
1681
<p>Of course the recursive version is trivial:</p> <pre><code>hanoi n = solve n 1 2 3 solve 0 _ _ _ = [] solve n from help to = (solve (n-1) from to help) ++ [(from,to)] ++ (solve (n-1) help from to) </code></pre> <p>However my iterative version looks terrible with a lot of code repetition:</p> <pre><code>hanoi n =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-12T09:54:47.347", "Id": "60462", "Score": "0", "body": "Iterative solutions: http://rosettacode.org/wiki/Towers_of_Hanoi#Iterative http://cboard.cprogramming.com/cplusplus-programming/26380-iterative-towers-hanoi.html http://hanoitower...
[ { "body": "<p>Umm. What about</p>\n\n<pre><code>import Data.Bits\nhanoi :: Int -&gt; [(Int, Int)]\nhanoi n = map (\\x -&gt; ((x .&amp;. (x-1)) `mod` 3, ((x .|. (x-1)) + 1) `mod` 3)) [1..shift 1 n]\nmain = print $ hanoi 5\n</code></pre>\n\n<p>?</p>\n", "comments": [ { "ContentLicense": "CC BY-S...
{ "AcceptedAnswerId": "1913", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-06T18:48:23.743", "Id": "1684", "Score": "8", "Tags": [ "haskell", "tower-of-hanoi" ], "Title": "Towers of Hanoi in Haskell" }
1684
<p>An anagram is like a mix-up of the letters in a string: </p> <blockquote> <p><strong>pots</strong> is an anagram of <strong>stop</strong> </p> <p><strong>Wilma</strong> is an anagram of <strong>ilWma</strong></p> </blockquote> <p>I am going through the book <a href="http://rads.stackoverflow.com/amzn/clic...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-07T04:23:57.783", "Id": "2957", "Score": "1", "body": "Scott's answer is great, so to your other question you should use `StringBuilder` because it doesn't use synchronization here. It will be faster and you aren't using multiple threa...
[ { "body": "<p>This is essentially asking you to compare if two sets are equivalent, thinking of the strings as a set of characters where the order doesn't matter.</p>\n\n<p>For an O(n) runtime algorithm, you could iterate through the first string, and count the number of instances of each letter. Then iterate ...
{ "AcceptedAnswerId": "1704", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-06T22:29:28.977", "Id": "1690", "Score": "11", "Tags": [ "java", "strings", "interview-questions" ], "Title": "Optimizing Java Anagram checker (compare 2 strings)" }
1690
<p>Motivating SO question: <a href="https://stackoverflow.com/questions/5454195/is-there-a-c-cli-smart-pointer-project-e-g-scoped-ptr">Is there a C++/CLI smart pointer project (e.g. scoped_ptr)?</a></p> <p>I'm interested in any reviewer comments, and especially identified bugs or inconsistencies with the native scoped...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-07T09:37:13.847", "Id": "2963", "Score": "0", "body": "Well the code seems to fine. But on [this page](http://www.functionx.com/cppcli/classes/Lesson13b.htm) this syntax is used for copy ctor : `ClassName(const ClassName^ & Name);` Wha...
[ { "body": "<p>I have only superficially tested the code so far, but it seems to make sense. However, there are some details where I'm either missing something (which wouldn't surprise me, I'm more at home with C#) or the code is more complex than it needs to be. Any comments are appreciated!</p>\n\n<ul>\n<li>Th...
{ "AcceptedAnswerId": "1746", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-07T03:27:29.087", "Id": "1695", "Score": "19", "Tags": [ ".net", "pointers", "c++-cli" ], "Title": "scoped_ptr for C++/CLI (ensure managed object properly frees owned native object...
1695
<p>With just a brief look over I can think of a large amount of changes that would improve the clarity but I would love to see how someone else would refactor this mess. </p> <p><strong>Spec</strong></p> <p><img src="https://i.stack.imgur.com/ebKzE.png" alt="Spec"></p> <p><strong>Code</strong></p> <pre><code>sta...
[]
[ { "body": "<p>My first instinct was “why do you construct all these expressions, only to compile it and return just the function — why not just use lambdas directly”... but after a second thought it seems that this wouldn’t be any clearer at all, so I think using expressions here is actually really nice :)</p>\...
{ "AcceptedAnswerId": "1723", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-07T04:15:33.230", "Id": "1699", "Score": "5", "Tags": [ "c#" ], "Title": "Implementation of String.prototype.replace" }
1699
<blockquote> <p><strong>Exercise 2.27</strong></p> <p>Modify your reverse procedure of exercise 2.18 to produce a deep-reverse procedure that takes a list as argument and returns as its value the list with its elements reversed and with all sublists deep-reversed as well. For example,</p> <pre><code...
[]
[ { "body": "<p>The main problem with using <code>snoc</code> (or <code>append</code>, which your <code>snoc</code> effectively does) is that <em>each</em> call is O(n). This makes your function O(n²), which is (pun intended) deeply problematic.</p>\n\n<p>Here's my O(n) implementation, which is tail-recursive alo...
{ "AcceptedAnswerId": "1701", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-07T04:33:34.980", "Id": "1700", "Score": "0", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Producing a deep-reverse procedure" }
1700
<p>I want to get <code>distinct</code> of two columns from an SQL table. Can I optimize this query?</p> <pre><code>create TABLE #Temporary_tbl ( ProductColour VARCHAR(50), ProductSize VARCHAR(20), ) insert into #Temporary_tbl (ProductColour) select distinct productcolour from sho...
[]
[ { "body": "<p>This will give you the same result as your sql.</p>\n\n<pre><code>select distinct ProductColour, null as ProductSize\nfrom shoptransfer\n\nunion all\n\nselect distinct null as ProductColor, ProductSize\nfrom shoptransfer\n</code></pre>\n\n<p>You don't actually need the \"as\" clause on the second ...
{ "AcceptedAnswerId": "1709", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-07T05:59:16.643", "Id": "1703", "Score": "5", "Tags": [ "sql", "sql-server" ], "Title": "Get distinct of two columns" }
1703
<p>Because I don't like using <code>\</code> to break long lines (to comply with PEP8), I tend to do something like this:</p> <pre><code>message = "There are {} seconds in {} hours." message = message.format(nhours*3600, nhours) print(message) </code></pre> <p>It also makes code cleaner. Is this an okay way of doing ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-07T18:33:42.040", "Id": "2989", "Score": "1", "body": "Not really a Code Review, I feel this is more appropriate at [Programmers.SE](http://programmers.stackexchange.com/)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationD...
[ { "body": "<p>Nothing necessarily wrong with doing that - I use that for situations that the message would be used more than once. However, for one-shot, multiline messages I'd do:</p>\n\n<pre><code>message = \"There are %d seconds \" % nhours*3600\nmessage += \"in %d hours.\" % nhours\nprint message\n</code><...
{ "AcceptedAnswerId": "1719", "CommentCount": "2", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-07T16:20:41.737", "Id": "1716", "Score": "6", "Tags": [ "python" ], "Title": "Is it okay to 'abuse' re-assignment?" }
1716
<p>I wrote <a href="https://github.com/jacktrades/Lispy/tree/master/liSpy" rel="nofollow">this interpreter</a> a little while ago and was hoping I could get some comments/criticisms. It it somewhat similar to the "languages as libraries" concept of Racket, though obviously with less features.</p> <p>Another goal was ...
[]
[ { "body": "<p>There is a hidden bug in the interpreter.</p>\n\n<p>Your <code>eval-body</code> calls <code>eval-arguments</code> to evaluate the body expressions of a compound procedure, but the evaluation order of <code>map</code> it not defined in Scheme. The procedure bodies should be evaluated with <code>for...
{ "AcceptedAnswerId": "1917", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-07T16:58:02.537", "Id": "1718", "Score": "3", "Tags": [ "scheme", "interpreter" ], "Title": "Interpreter framework for writing Scheme-like interpreters in < 60 loc" }
1718
<p>I'm only asking because almost the entire code base I've inherited here, in C# and PHP, looks like this:</p> <pre><code>if (varOne == flag) { run_some_sql(); set_some_flag = true; } if (varTwo == flag) { run_some_sql(); set_some_flag = true; } if (varThree == flag) { run_some_sql(); set_so...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-04-07T22:42:41.170", "Id": "2998", "Score": "3", "body": "Well, at least you are sure you will do better than the previous employees. ;p" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-08T03:29:06.230", "I...
[ { "body": "<p>No, you haven't lost your mind. It should more like...</p>\n\n<pre><code>// declared and set somewhere\nflags = new int[x];\n\n//...\n\nfor (int value: flags) {\n if (value == flag) {\n run_some_sql();\n set_some_flag = true;\n }\n}\n</code></pre>\n\n<p>...assuming that the flags are...
{ "AcceptedAnswerId": "1722", "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-04-07T19:44:34.373", "Id": "1720", "Score": "9", "Tags": [ "c#", "design-patterns" ], "Title": "Executing functions and declaring flags with a long battery of if conditions" }
1720
<p>I am looking for a suggestion or advises about some code I have written. I build an online application about 3 month ago the app registers new buildings including description names and so on. The app works perfectly and does what it suppose to. While working on it I was constantly learning and improving my skills. ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-08T11:49:19.680", "Id": "3009", "Score": "2", "body": "Welcome to CodeReview.SE. Please post your code in the post and remove the link to the pastebin. All of this is mentioned in the FAQ: http://codereview.stackexchange.com/faq. Th...
[ { "body": "<p>When it comes down to improving the structure there's reallly 2 ways to go about it when it comes to the client side.</p>\n\n<p>I can see that your loading your CSS Directly within the page, this can be a pro when it comes to loading speeds, but with today's internet speeds that's practically noth...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-08T03:11:42.363", "Id": "1724", "Score": "3", "Tags": [ "php", "javascript" ], "Title": "The first major app CMS writen" }
1724
<p>I have written some survey functionality for a project. Basically, a generic survey form that can be composed of sections and questions.</p> <p>I have a <code>Survey</code> class, <code>Questions</code> and <code>Sections</code>. The <code>Survey</code> is basically a tree, where each node can be a <code>Question...
[]
[ { "body": "<blockquote>\n <p>I'm using the static member Depth to\n keep track of how deep the visitor has\n gone. Could it be problematic having\n state on my extension methods static\n class?</p>\n</blockquote>\n\n<p>Absolutely. The reason for this is simply that <code>static</code> methods should always...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-08T13:23:53.487", "Id": "1729", "Score": "11", "Tags": [ "c#", "design-patterns", "tree" ], "Title": "Composite and Visitor patterns for tree-based survey functionality in C#" }
1729
<blockquote> <p>Define a procedure square-tree analogous to the square-list procedure of exercise 2.21. That is, square-list should behave as follows:</p> <pre><code>(square-tree (list 1 (list 2 (list 3 4) 5) (list 6 7))) (1 (4 (9 16) 25) (36 49)) </code></pre> <p>Define square-tree both di...
[]
[ { "body": "<p>Your direct definition of <code>square-tree</code> is correct.</p>\n\n<p>Your definition using <code>map</code> calls <code>square-tree</code>; to make it properly recursive, call <code>map-square-tree</code> instead. Further, you may recurse on the <code>subtree</code> itself. This will make yo...
{ "AcceptedAnswerId": "1749", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-08T14:14:50.070", "Id": "1732", "Score": "1", "Tags": [ "recursion", "lisp", "scheme", "sicp" ], "Title": "Square-tree using maps and recursion" }
1732
<blockquote> <p>Exercise 2.31. Abstract your answer to exercise 2.30 to produce a procedure tree-map with the property that square-tree could be defined as</p> <pre><code>(define (square-tree tree) (tree-map square tree)) </code></pre> </blockquote> <p>I wrote the following solution:</p> <pre><code>(define ...
[]
[ { "body": "<p>Your direct definition of <code>tree-map</code> looks good.</p>\n\n<p>The version using <code>map</code> may be written more succinctly (with the recursive portion factored out) as follows:</p>\n\n<pre><code>(define (tree-map f tree)\n (define (rec tree)\n (map (lambda (subtree)\n ((...
{ "AcceptedAnswerId": "1837", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-08T14:23:47.483", "Id": "1733", "Score": "4", "Tags": [ "lisp", "tree", "scheme", "sicp" ], "Title": "Abstract tree-map function" }
1733
<p><strong>EDIT: My code DOES not work, see <a href="https://gis.stackexchange.com/questions/294380/if-rectangle-corner-points-have-same-nearest-neighbor-does-whole-interior">https://gis.stackexchange.com/questions/294380/if-rectangle-corner-points-have-same-nearest-neighbor-does-whole-interior</a></strong></p> <p>Giv...
[]
[ { "body": "<p>In short, try <a href=\"http://ngwww.ucar.edu/ngmath/cssgrid/csshome.html\" rel=\"nofollow noreferrer\">cssgrid</a> from <a href=\"http://ngwww.ucar.edu/\" rel=\"nofollow noreferrer\">NCAR Graphics</a>.</p>\n\n<p>At length:</p>\n\n<p>There's <a href=\"https://stackoverflow.com/questions/545870/alg...
{ "AcceptedAnswerId": "10142", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-04-09T02:41:05.910", "Id": "1739", "Score": "7", "Tags": [ "performance", "perl", "geospatial", "google-maps" ], "Title": "Spherical Voronoi diagram, binary splitting approach" }
1739
<p>I need to figure out the best way to deal with memory pre-allocation</p> <p>Below is pseudo-code for what I am doing now, and it seems to be working fine.</p> <p>I am sure there is a better way to do this, I would like to see if anyone has any good idea.</p> <p>In Thread A I need to allocate 300 MB of memory and ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-09T01:06:41.130", "Id": "3027", "Score": "1", "body": "Wait, if it seems to be working fine, then what exactly are you looking for? I'm confused..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-09T01:09:1...
[ { "body": "<p>Another approach I can think of could be this. Get rid of <code>myMemory</code> altogether. Once you receive data in thread B, allocate memory and copy that data (as you're doing now). Send thread C a message that data is received. Once thread C copies the data into its internal buffer, thread C c...
{ "AcceptedAnswerId": "1742", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-09T01:00:13.053", "Id": "1741", "Score": "2", "Tags": [ "c++", "multithreading" ], "Title": "Multi-Threaded Memory Preallocation" }
1741
<blockquote> <p>Given a Binary Search Tree, determine its k-th element in inorder traversal.</p> </blockquote> <p>Here's my node structure:</p> <pre><code>struct node { int elem; node *left, *right; static node* create(int elem) { node *newnode = new node; newnode-&gt;elem = elem...
[]
[ { "body": "<p>If you add a total count field to each node, you can find the k-th element efficiently (in logarithmic time) by writing a method like this (untested):</p>\n\n<pre><code>node *kth(int k)\n{\n assert(k &gt;= 0 &amp;&amp; k &lt; total);\n\n if (left != NULL) {\n if (k &lt; left-&gt;total...
{ "AcceptedAnswerId": "1777", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-09T20:26:52.123", "Id": "1750", "Score": "4", "Tags": [ "c++", "tree" ], "Title": "Finding the k-th element in a BST" }
1750
<p>I have written the following tiny extension method to help me when I'm working with sequences in which I have to find a pattern.</p> <pre><code>public static IEnumerable&lt;T[]&gt; SearchPattern&lt;T&gt;(this IEnumerable&lt;T&gt; seq, params Func&lt;T[], T, bool&gt;[] matches) { Contract.Requires(seq != null)...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-09T22:47:55.747", "Id": "3048", "Score": "0", "body": "I haven't looked at the details of your code, but just keep in mind that LINQ itself -- as well as the `yield` statements -- are *very* inefficient." }, { "ContentLicense":...
[ { "body": "<p>The way a tail call works at the IL level, is that the current stack frame is discarded before calling the method*. So whatever the called method returns is effectively by the calling method. I read somewhere that Microsoft's x64 JIT will optimise this into a loop while their x86 JIT will leave it...
{ "AcceptedAnswerId": "1756", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-09T22:17:20.433", "Id": "1753", "Score": "11", "Tags": [ "c#", ".net" ], "Title": "Searching a sequence for a pattern" }
1753
<p>Lately I seem to run into a situation very frequently where I want to write something like the following:</p> <pre><code>var x = condition1 ? value1 : condition2 ? value2 : condition3 ? value3 : condition4 ? value4 : throw new InvalidOperationException(); </code></pre> <p>Suppose the conditions...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-10T23:18:25.757", "Id": "3075", "Score": "1", "body": "How odd. `throw` expressions are legal in `?:` expressions in C++." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-16T21:52:28.607", "Id": "3222", ...
[ { "body": "<p>I would avoid using such statement. It doesn't seem to be a right place for this construction inside <code>?:</code> operators and I do not see major benefits in using it. I would consider using following options: </p>\n\n<p>1) </p>\n\n<pre><code>Type variable;\nif (condition1) variable = value1;...
{ "AcceptedAnswerId": "1779", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-10T16:00:00.217", "Id": "1760", "Score": "14", "Tags": [ "c#", "exception" ], "Title": "What’s your opinion on a Throw() method?" }
1760
<p>I don't want anything to execute if any preceding step fails:</p> <pre><code>#!/bin/sh file="v0.9" renamed=$file".tar.gz" dir="utils/external/firepython/" location="https://github.com/darwin/firepython/tarball/$file" wget --no-check-certificate $location --output-document=$renamed &amp;&amp; \ mkdir -p $dir &amp;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-11T14:35:54.057", "Id": "3097", "Score": "1", "body": "If you use tar -zxf it will gunzip the file for you." } ]
[ { "body": "<p>You're looking for <code>set -e</code>. From <a href=\"http://pubs.opengroup.org/onlinepubs/009695399/utilities/set.html\">POSIX</a>:</p>\n\n<blockquote>\n <p><code>-e</code>\n When this option is on, if a simple command fails for any of the reasons listed in <a href=\"http://pubs.opengroup.org/...
{ "AcceptedAnswerId": "1768", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-10T17:34:16.707", "Id": "1766", "Score": "7", "Tags": [ "shell", "sh" ], "Title": "Shell script to download and extract a tarball from GitHub" }
1766
<p>I have been trying to wrap my head around MVVM for the last week or more and still struggling a bit. I have watched <a href="http://www.lab49.com/files/videos/Jason%20Dolinger%20MVVM.wmv" rel="nofollow">Jason Dolingers MVVM video</a> and gone through <a href="http://reedcopsey.com/series/windows-forms-to-mvvm/" rel=...
[]
[ { "body": "<p>It seems your implementation is correct. You also touch a common discussion of MVVM.</p>\n\n<p><a href=\"https://stackoverflow.com/q/772214/590790\">In MVVM should the ViewModel or Model implement INotifyPropertyChanged?</a></p>\n\n<p>One could argue you could let the model implement INotifyProper...
{ "AcceptedAnswerId": "1789", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-11T01:13:24.003", "Id": "1771", "Score": "6", "Tags": [ "c#", "datetime", "wpf", "mvvm" ], "Title": "Simple clock view model" }
1771
<p>I'm trying to figure out how to do this more dynamically. Right now I save each and every form field individually/manually. I would love to maybe have some kind of master form list that I could loop through. I'm fairly new to C#, so I don't know many tricks yet. Please let me know what you think.</p> <p>Here is my ...
[]
[ { "body": "<p>It looks like what you're trying to do here is possible by using .NET's built-in support for application settings. Check out <a href=\"http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx\" rel=\"nofollow\">this link</a> for details on how to use it. Essentially, you can define your settings wi...
{ "AcceptedAnswerId": "1778", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-11T01:43:24.100", "Id": "1772", "Score": "7", "Tags": [ "c#", "xml" ], "Title": "XML settings implementation" }
1772
<p>At work I am developing an application using hand-coded Swing, and I've found that I have an easier time reading, writing, and maintaining hierarchical component creation using code blocks like:</p> <pre><code> JPanel mainPanel = new JPanel(new BorderLayout()); { JLabel centerLabel = new JLabel(); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-11T10:37:52.503", "Id": "3091", "Score": "0", "body": "I'd argue it looks difficult to follow because of the way you're using F# - WinForms certainly isn't its choice arena, and while there may be coincidental conveniences, it is inher...
[ { "body": "<p>Here is my take on your code:</p>\n\n<pre><code>open System\nopen System.Windows.Forms\n\nlet form =\n new Form(\n Width = 400,\n Height = 300,\n Visible = true,\n Text = \"Hello World Form\")\n\n// Menu bar, menus \nlet mMain = \n let miQuit = new MenuItem(\"&am...
{ "AcceptedAnswerId": "2869", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-11T02:29:25.513", "Id": "1773", "Score": "11", "Tags": [ "winforms", "f#", "swing" ], "Title": "Approach to programmatically building hierarchical GUI components" }
1773
<blockquote> <p>Exercise 2.35. Redefine count-leaves from section <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-15.html" rel="nofollow">2.2.2</a> as an accumulation:</p> <pre><code>(define (count-leaves t) (accumulate &lt;??&gt; &lt;??&gt; (map &lt;??&gt; &lt;??&gt;))) </code></pre> </blockquote> ...
[]
[ { "body": "<p>The code doesn't handle the case of only a single leaf, i.e.</p>\n\n<pre><code> (count-leaves 'leaf)\n</code></pre>\n\n<p>but I guess that's a side-effect of the original problem formulation. A cleaner solution would be</p>\n\n<pre><code>(define (count-leaves t)\n (if (pair? t)\n (accumulate...
{ "AcceptedAnswerId": "1892", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-11T03:46:19.563", "Id": "1775", "Score": "6", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Redefine count-leaves as an accumulation" }
1775
<p>An algorithm is a set of ordered instructions based on a formal language with the following conditions:</p> <ul> <li><strong>Finite</strong>. The number of instructions must be finite.</li> <li><strong>Executable</strong>. All instructions must be executable in some language-dependent way, in a finite amount of tim...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-11T05:57:01.993", "Id": "1780", "Score": "0", "Tags": null, "Title": null }
1780
An algorithm is a sequence of well-defined steps that define an abstract solution to a problem. Use this tag when your issue is related to algorithm design.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-11T05:57:01.993", "Id": "1781", "Score": "0", "Tags": null, "Title": null }
1781
<p>I have written a cart Class, it use session to store data. Is the code well implemented or could been better? You can rewrite my code if you can.</p> <p>Each item have a number of options with price</p> <p>Each Option can have many extras or without extras</p> <p><strong>For example:</strong> </p> <p>Item 1 -> (...
[]
[ { "body": "<p>OK, bear with me here, but the formatting stinks.</p>\n\n<p>I won't rewrite the code for you, but I will continue to provide the information that I can to enable you to do so, should you (based on existing knowledge, or in any of my opinions being finely refuted by others) choose to disagree, then...
{ "AcceptedAnswerId": "1792", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-11T16:21:19.690", "Id": "1784", "Score": "6", "Tags": [ "php", "php5" ], "Title": "Cart Class feedback" }
1784
<p>I am trying to use <code>HibernateCompositeUser</code> type to handle i18n specific data in my application. I am trying to use the below approach.</p> <p>I have a table named <code>master table</code> which contains all locale independent data, while I have created another table <code>master_translation</code> whic...
[]
[ { "body": "<p>I'm not too familiar with Hibernate, so just some generic notes:</p>\n\n<ol>\n<li><p>DBMSs usually have case-insensitive attribute names, so a lot of people use underscore to separate words in attribute and table names.</p>\n\n<blockquote>\n<pre><code>&lt;column name=\"SHORTDESCRIPTION\"/&gt;\n&lt...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-11T17:23:28.037", "Id": "1786", "Score": "11", "Tags": [ "java", "hibernate" ], "Title": "Is this the way to use HibernateCompositeUser type for handling localized contents?" }
1786
<p>UPDATE: I didn't write the library pasted below I just make use of it. I'm unable to paste the <a href="https://github.com/ocanbascil/Performance-AppEngine/blob/master/PerformanceEngine/__init__.py" rel="nofollow">part I wrote</a> here because the message exceeds 30k characters when I try to do so. </p> <p>I have b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-11T21:57:20.317", "Id": "3118", "Score": "5", "body": "Welcome to code review! If you read the FAQ you'll learn that any code that you want reviewed should really be pasted into your question. Its also geared towards smaller pieces of ...
[ { "body": "<pre><code>\"\"\"\nCurious thing: A dictionary in the global scope can be referenced and changed inside a function without using the global statement, but it can not be redefined.\n\"\"\"\n</code></pre>\n\n<p>It's default behavior for global variable. When you try to redefine global variable inside s...
{ "AcceptedAnswerId": "1835", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-11T21:48:59.503", "Id": "1791", "Score": "4", "Tags": [ "python" ], "Title": "Review request: My App Engine library (python)" }
1791
<p><a href="http://php.net/" rel="nofollow">PHP</a> (stands for: PHP: Hypertext Preprocessor) is a widely-used general-purpose scripting language that is especially suited for web development.</p> <p>For this purpose, PHP code can be embedded into the HTML source document and interpreted by a web server with a PHP pro...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-12T02:40:42.030", "Id": "1800", "Score": "0", "Tags": null, "Title": null }
1800
PHP is a widely-used, general-purpose scripting language that is especially suited for web development.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-12T02:40:42.030", "Id": "1801", "Score": "0", "Tags": null, "Title": null }
1801
<blockquote> <p>Exercise 2.37. Suppose we represent vectors v = (vi) as sequences of numbers, and matrices m = (mij) as sequences of vectors (the rows of the matrix). For example, the matrix <img src="https://i.stack.imgur.com/1HQmE.gif" alt="matrix m"></p> <p>is represented as the sequence ((1 2 3 ...
[]
[ { "body": "<p>Your definition of <code>transpose</code> is correct, although it can be written succinctly as:</p>\n\n<pre><code>(define (transpose mat)\n (accumulate-n cons null mat))\n</code></pre>\n\n<p>The remaining two definitions may be written more succinctly by using functions defined earlier. Notice t...
{ "AcceptedAnswerId": "1914", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-12T02:48:06.000", "Id": "1802", "Score": "5", "Tags": [ "lisp", "scheme", "matrix", "sicp" ], "Title": "Matrix multiplication and dot-product" }
1802
<blockquote> <p><strong>Exercise 2.39</strong></p> <p>Complete the following definitions of reverse (exercise 2.18) in terms of fold-right and fold-left from exercise 2.38:</p> <pre><code>(define (reverse sequence) (fold-right (lambda (x y) &lt;??&gt;) nil sequence)) (define (reverse sequence) (fold-lef...
[]
[ { "body": "<p>Yep, youve got it. I don't think there are any reasonable alternatives.</p>\n\n<p>It's umderstandable if you were hoping to avoid <code>append</code> with some clever combo of <code>cons</code>/<code>car</code>/<code>cdr</code> but i dont believe there is such a way.</p>\n", "comments": [], ...
{ "AcceptedAnswerId": "1838", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-12T03:51:22.880", "Id": "1803", "Score": "5", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Reverse in terms of fold-right and fold-left" }
1803
<p>I'm new to rails and have built a multi-model form. It's working, but some of the code doesn't feel right.</p> <p>The model code is below. I'm using <a href="https://github.com/plataformatec/devise" rel="nofollow">Devise</a> for my user authentication:</p> <pre><code># models/signup.rb class Signup &lt; ActiveReco...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-12T17:59:22.700", "Id": "3136", "Score": "2", "body": "Any reason you're using a Signup model and controller, instead of doing it directly from Company?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-12T18...
[ { "body": "<p>Firstly (and yes I did read the comments) the signup model seems unessential.</p>\n\n<p>So firstly we should do away with that, if you need to associate payment details then that could easily be done directly on the company model.</p>\n\n<p>Secondly you controller is getting a bit cuddly. In favou...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-12T03:54:00.290", "Id": "1804", "Score": "4", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Cleaning up a multi-model view in Rails3" }
1804
<p>C# is a multiparadigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform. C# is also used with non-Microsoft implementations (most notably, <a href="http://www.mono-project.com/" rel="nofollow noreferrer">Mono</a>).</p> <h2>C# Background</h2> ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-04-12T13:00:51.323", "Id": "1808", "Score": "0", "Tags": null, "Title": null }
1808
C# is a multi-paradigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform. Use this tag for questions related to C#. In case a specific version of the framework is used, you could also include that tag; for instance .net-2.0.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-04-12T13:00:51.323", "Id": "1809", "Score": "0", "Tags": null, "Title": null }
1809
<p>This is an intersection-detection algorithm I developed as an alternative method to the one developed for my coursework. I won't post some of the other functions as they are used in the coursework too, feel free to ask if their names aren't self explanatory. This function simply returns whether 2 <code>bcw</code> ob...
[]
[ { "body": "<p>A few quick stylistic things:</p>\n\n<ol>\n<li>Don't use &lt;>, its considered an older style use != instead</li>\n<li>When comparing against None, use \"x is None\" not \"x &lt;> None\" or \"x != None\" This is because there is only one None object so its more correct to compare object identity</...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-12T14:02:37.787", "Id": "1810", "Score": "3", "Tags": [ "python", "algorithm", "collections", "collision" ], "Title": "Intersection-detection algorithm" }
1810
<p>This is a small extension based on a <code>boost::property_tree</code>, which supports arbitrary values for the properties and appropriate serialization. It can be used as an alternative to QSettings in Qt and provides very convenient way to pass properties inside your applications.</p> <p>I would like to have a c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-26T21:43:16.913", "Id": "3445", "Score": "0", "body": "Looks interesting. Maybe add some comments or test case to illustrate how it is used and what it bring over boost (if it is pertinent) would be great. Your coding style looks prett...
[ { "body": "<p>I think use boost::serialize is not are good idea. I read about this library (not all Boost) and they have problem compatibility with previous versions.</p>\n\n<p>I wrote other property container and property manager some times ago. And we use template class, without Boost, like this:</p>\n\n<pr...
{ "AcceptedAnswerId": "2081", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-12T17:34:40.537", "Id": "1818", "Score": "10", "Tags": [ "c++", "tree", "extension-methods", "boost" ], "Title": "Small C++ Boost extension based on boost::property_tree" }
1818
<pre><code>function reformat($data, $registration = false) { // Initializing aircompanies codes $iata = new iata; for ($i = 0; $i &lt; count($data); $i = $i + 6) { if ($registration) { $r = str_replace('&lt;nobr&gt;', '', $this-&gt;prep_value($data[$i])); $block[$i]['reis'] =...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-06-09T14:35:41.320", "Id": "245328", "Score": "0", "body": "This question could use some explanation of what the code is supposed to do and how it works." } ]
[ { "body": "<pre><code>function reformat($data, $registration = false) {\n // Initializing aircompanies codes\n $iata = new iata;\n $block = array();\n for ($i = 0; $i &lt; count($data); $i += 6) {\n $block[$i] = array(\n 'airport' =&gt; $this-&gt;prep_value($data[$i + 1]),\n ...
{ "AcceptedAnswerId": "1829", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-12T18:12:29.260", "Id": "1819", "Score": "0", "Tags": [ "php", "formatting" ], "Title": "Formatting some data about some airlines" }
1819
<p>So, here's my code:</p> <pre><code>public class NList : SExp, IEnumerable&lt;Object&gt; { private Object _car; private NList _cdr; IEnumerator&lt;Object&gt; IEnumerable&lt;Object&gt;.GetEnumerator() { return new NListEnumerator(this); } IEnumerator IEnumerable.GetEnumerator() {...
[]
[ { "body": "<p>There is a serious flaw in your handling of the empty list. A user would expect that these definitions are equivalent, but they ain't:</p>\n\n<pre><code>Nlist n1 = new NList(\"x\");\nNlist n2 = new NList(\"x\", new NList());\n</code></pre>\n\n<p>I strongly recommend to have an explicit subclass fo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-04-12T20:13:41.563", "Id": "1830", "Score": "4", "Tags": [ "c#", "iterator", "lisp" ], "Title": "LISP-like list class" }
1830
<p>I'm trying to speed up the following code for summing doubles with full precision, based on a <a href="http://code.activestate.com/recipes/393090/" rel="nofollow">Python recipe</a> from Raymond Hettinger. Any thoughts on how to make this go faster?</p> <pre><code>-- Full precision summation based on http://code.ac...
[]
[ { "body": "<p>You could write <code>hilo</code> as <code>hilo :: Double -&gt; Double -&gt; [Double]</code>, which returns <code>[hi,lo]</code> for <code>lo /= 0</code> and <code>[hi]</code> for <code>lo = 0</code>. Then you can write <code>partials</code> as</p>\n\n<pre><code>partials x = foldl' (\\acc p -&gt; ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-12T23:00:44.157", "Id": "1834", "Score": "6", "Tags": [ "performance", "haskell" ], "Title": "Full-precision summation in Haskell" }
1834
<p><strong>NOTE: My implementation is based on codeproject <a href="http://www.codeproject.com/KB/threads/CritSectEx.aspx">article</a> by Vladislav Gelfer.</strong></p> <p>Based on <a href="http://www.codeproject.com/script/Membership/View.aspx?mid=541463">valdok</a>'s codes, I rewrote the critical section class. The ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-13T12:08:26.630", "Id": "3155", "Score": "1", "body": "It would be nice if you provided unit tests for this piece of code, because it's hard to test it's correctness based on only it's implementation. *Also, why not stick to something ...
[ { "body": "<p>To be honest it is quite difficult to verify this sort of thing works by dry running code.</p>\n\n<p>I would take the original code and design some test cases which show it working.\nRun them with and without the code.</p>\n\n<p>Then design some test cases which fail due to the problem you have sp...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-13T02:48:50.420", "Id": "1836", "Score": "8", "Tags": [ "c++", "multithreading", "locking" ], "Title": "C++ critical section with timeout" }
1836
<p>Does this code look OK?</p> <pre><code>public Map&lt;String, String&gt; getById(long id) { String sql = "select * from " + this._TABLE_NAME + " where id = ?"; PreparedStatement p; Map&lt;String, String&gt; result = new HashMap&lt;String, String&gt;(); try { p = conn.prepareStatement(sql); ...
[]
[ { "body": "<p>Why not just do it like:</p>\n\n<pre><code>while(rs.next()) {\n result.put(....);\n return result;\n}\n</code></pre>\n\n<p>You can also wrap it in a <code>try</code>-<code>catch</code>-<code>finally</code>.</p>\n\n<p>Also, the use of prepared statement may not be justified in this example, s...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-13T04:32:55.177", "Id": "1839", "Score": "7", "Tags": [ "java", "sql", "jdbc" ], "Title": "Accessing the only element of Java ResultSet" }
1839
<p>From the section called <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html" rel="nofollow">Nested Mappings</a></p> <blockquote> <p><strong>Exercise 2.40</strong></p> <p>Define a procedure unique-pairs that, given an integer <code>n</code>, generates the sequence of pairs (<code>i</code>...
[]
[ { "body": "<p>Your code</p>\n\n<pre><code>(define (enumerate-integers start end)\n (if (&gt;= start end)\n (list end)\n (cons start (enumerate-integers (+ 1 start) end))))\n\n(define (unique-pairs n)\n (flat-map (lambda (i) \n (map (lambda (j) (list i j)) \n (enumerate...
{ "AcceptedAnswerId": "1891", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-13T06:06:33.690", "Id": "1841", "Score": "1", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Defining a unique-pairs procedure" }
1841
<p>How can I write this code better?</p> <pre><code>$cookieUrl = 'https://-------------/ps/scc/login.php'; $sessionUrl = 'https://-------------/ps/scc/php/check.php'; $balanceUrl = 'https://-------------/SCWWW/ACCOUNT_INFO'; $vars = "LOGIN={$this-&gt;login}&amp;PASSWORD={$this-&gt;password}"; $response = $this-&gt;_se...
[]
[ { "body": "<p>It is not perfect example, but your code might be like this:</p>\n\n<pre><code>function __construct()\n{\n//...\n $this-&gt;cookieUrl = 'https://-------------/ps/scc/login.php';\n $this-&gt;sessionUrl = 'https://-------------/ps/scc/php/check.php';\n $this-&gt;balanceUrl = 'https://------...
{ "AcceptedAnswerId": "1856", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-13T06:44:30.163", "Id": "1844", "Score": "4", "Tags": [ "php", "parsing" ], "Title": "Parse the phone balance from the operator site" }
1844
<blockquote> <p>Exercise 2.41. Write a procedure to find all ordered triples of distinct positive integers i, j, and k less than or equal to a given integer n that sum to a given integer s.</p> </blockquote> <pre><code>(define (enumerate-integers i j) (if (= i j) (list j) (cons i (enumerate-in...
[]
[ { "body": "<p>Does this variant fit?</p>\n\n<pre><code>#lang racket\n(define (filtered-by-sum-triples s n)\n (filter (sum-equal? s)\n (unique-triples n)))\n\n(define (unique-triples n)\n (unique-sequences n 3))\n\n(define (unique-sequences n arity)\n (define (rec num arity tail)\n (if (= arity 1)...
{ "AcceptedAnswerId": "1894", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-13T07:09:07.590", "Id": "1845", "Score": "8", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Find all distinct triples less than N that sum to S" }
1845
<p>I use VS 2008 and .NET 3.5</p> <p>I have this code using CustomChannelFactory and Proxy ServiceReference. I would like refactor using lambdas, Action, ...</p> <p>any suggestions ?</p> <pre><code>ServiceDependencias.IDependencias svcDependencias = null; public void Dependencias(List&lt;MfaFicheroForm&gt; listaFic...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-13T20:30:39.857", "Id": "3166", "Score": "3", "body": "One of the reasons people normally program in english, is so more people can easily understand it ... e.g. like when doing a code review. ;p" }, { "ContentLicense": "CC BY-...
[ { "body": "<p>I don't know any Spanish so it was a bit difficult to understand exactly what was going on (I recommend you provide English translations/descriptions of non-English class names and string literals as comments next time).</p>\n\n<ul>\n<li><p>Why do you create a temporary variable that is only use t...
{ "AcceptedAnswerId": "1924", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-13T09:22:56.490", "Id": "1854", "Score": "3", "Tags": [ "c#", "proxy" ], "Title": "Refactor for using ChannelFactory" }
1854
<p>This might be a bit silly because there are like a thousand ways to do this, but I'm struggling to come up with one that I like. I feel like this should fit in one line, but I don't like re-using read_attribute(:length) lots and I don't like the below because it's not that clear.</p> <pre><code># returns a human-re...
[]
[ { "body": "<p>Assuming that len is an integer you won't need to use floor. You can do something like this</p>\n\n<pre><code>\"#{len/3600}h #{(len/60) % 60}m\" unless len.nil?\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "Creat...
{ "AcceptedAnswerId": "1867", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-13T09:44:37.840", "Id": "1855", "Score": "5", "Tags": [ "ruby", "datetime", "formatting", "null" ], "Title": "Formatting a possibly nil value as hours and minutes" }
1855
<p>I could use the function <code>Intersection</code>, but it returns a <strong>sorted</strong> list. That's why I have to do my own, but it looks too big. I hope it could be done shorter.</p> <pre><code>lists = {{1, 2, 3, 4, 5}, {1, 2, 3, 4}, {2, 3, 4, 5}}; Fold[ Function[ {a, b}, Select[b, MemberQ[a, #] &amp;] ]...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-15T09:44:09.233", "Id": "3191", "Score": "0", "body": "what should be result of Intersect[{{1,2},{2,1}}] ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-17T10:55:57.983", "Id": "3233", "Score": "0...
[ { "body": "<p>Most efficient and simple way for this is to sort each list before applying such algorithm. \nIn this case you do not need to check if each number is memeber of other list but you just pick first number and compare whit other elements from beginning.</p>\n\n<p>This is reason that Mathematica retur...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-13T10:58:58.080", "Id": "1858", "Score": "5", "Tags": [ "wolfram-mathematica" ], "Title": "Lists' intersection keeping elements' order" }
1858
<pre><code>public final class Descriptors { public static final EnumValueDescriptor TIME_SETTING = new EnumValueDescriptor( R.string.pref_label_time_setting, Measures.TIME_SETTING_12, R.string.pref_time_setting_12, Measures.TIME_SETTING_24, R.string.pref_time_setting_24); publi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-13T18:34:43.723", "Id": "3162", "Score": "3", "body": "if would make our lives easier if you tell us what is your actual question" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-28T18:08:27.337", "Id": ...
[ { "body": "<p>This class doesn't have any responsibilities, it just holds a group of static variables. It is unclear what the purpose of these variables are. I am sure there is a better way to achieve your goal as I doubt you actually need to be storing these details here.</p>\n", "comments": [ { ...
{ "AcceptedAnswerId": "1925", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-13T13:34:23.077", "Id": "1859", "Score": "0", "Tags": [ "java", "android" ], "Title": "Specify table data in code, reference objects" }
1859
<p>In the similar vein as <a href="https://codereview.stackexchange.com/questions/836/is-toienumerablet-good-practice">ToIEnumerable</a> and <a href="https://stackoverflow.com/questions/1577822/passing-a-single-item-as-ienumerablet">FromSingleItem</a></p> <p>Is this a good improvement for making lists on the fly?</p> ...
[]
[ { "body": "<p>As developers we're pretty used to where the keys for all kinds of brackets, braces and parenthesis are and while I agree you may save (a negligible amount of) twists and turns of the wrist, you're just substituting keystrokes for keystrokes, IMO.</p>\n\n<p>You've already made me (as a colleague) ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-04-13T16:06:43.723", "Id": "1863", "Score": "5", "Tags": [ "c#" ], "Title": "Is ToEnumerable<T> for multiple items a good practice?" }
1863