body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I want to create pair, where <code>new UnorderedPair(ObjA, ObjB) == UnorderedPair(ObjB, ObjA)</code> returns <code>true</code>. I also want to avoid any (un)boxing.</p>
<p>Have I gone about this in the correct way?</p>
<pre><code>public struct UnorderedPair<T> : IEquatable<UnorderedPair<T>>
{
... | [] | [
{
"body": "<p>One thing: I would make the <code>struct</code> <a href=\"https://stackoverflow.com/questions/3751911/why-are-c-sharp-structs-immutable/3753640#3753640\">immutable</a> since mutable <code>struct</code>s <a href=\"https://stackoverflow.com/questions/441309/why-are-mutable-structs-evil\">have</a> <a... | {
"AcceptedAnswerId": "8588",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-02T14:24:36.280",
"Id": "8587",
"Score": "3",
"Tags": [
"c#"
],
"Title": "Is this an ok implementation of an UnorderedPair?"
} | 8587 |
<p>I often need to parse tab-separated text (usually from a huge file) into records. I wrote a generator to do that for me; is there anything that could be improved in it, in terms of performance, extensibility or generality? </p>
<pre><code>def table_parser(in_stream, types = None, sep = '\t', endl = '\n', comment =... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-02T09:56:42.030",
"Id": "13425",
"Score": "0",
"body": "@RikPoggi: I asked moderator to move it there. Thank you"
}
] | [
{
"body": "<p>One thing you could try to reduce the amount of code in the loop is to make a function expression for these.</p>\n\n<pre><code> if types is None:\n record = {col : fields[no] for no, col in enumerate(header)}\n else:\n record = {col : types[col](fields[no]) for no, col in enumerate(header)... | {
"AcceptedAnswerId": "8590",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-02T09:40:15.453",
"Id": "8589",
"Score": "3",
"Tags": [
"python",
"performance",
"parsing",
"generator"
],
"Title": "Text parser implemented as a generator"
} | 8589 |
<p>I wrote a C++ program for review and got feedback that I had not used any kind of extensibility of object orientation.</p>
<p>I am wondering if this is a clearly defined concept or one that is more in the eye of the beholder? How would you define using extensibility of object orientation?</p>
<p>My sample program ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-02T16:12:36.423",
"Id": "13434",
"Score": "0",
"body": "I think seeing how the `Token` members are used and seeing the `Indexer::operator+=` methods might help a lot."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": ... | [
{
"body": "<p>The code shown implements only <code>operator+=(word)</code> but calls only <code>operator+=(token)</code>. Is one defined trivially in terms of the other?</p>\n\n<p>Unless you could reasonably expect some requirement for <code>indexer += token;</code> to do something different from <code>indexer ... | {
"AcceptedAnswerId": "8608",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-02T15:00:10.847",
"Id": "8591",
"Score": "6",
"Tags": [
"c++",
"object-oriented"
],
"Title": "How could this object oriented design class be improved for future extensibility?"
} | 8591 |
<p>Simple static class that will write out a message that is passed in. The SpriteSheet is 256x256 and the A-Z starts at line 240 and the 0-9 starts at 248. Each character is 8x8. I hate the <code>if (ix >= 32)</code> and wondered if there is a tidier way of doing this? I'm pleased it's only one <code>Draw</code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-03T18:11:40.570",
"Id": "13486",
"Score": "0",
"body": "Do the sprites (`SpriteSheet`) ever change?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T08:50:30.817",
"Id": "13514",
"Score": "0",
... | [
{
"body": "<p>It is hard to suggest improvements because the variable names are not very meaningful and, thus, it is hard to understand what they are for and which is the intention behind the code.<br>\nLesson to learn: <strong>using meaningful variable names is important</strong>.</p>\n\n<p>Here is an attempt.... | {
"AcceptedAnswerId": "8630",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-02T17:07:31.470",
"Id": "8600",
"Score": "2",
"Tags": [
"c#",
"optimization"
],
"Title": "Help tidying up a Draw call"
} | 8600 |
<p>I wrote this class today, but I am trying to figure out how to make it more accurate. I pass in seconds and multiply by 1000 to make it milliseconds, and the time does not line up. I need the ability to have multiple timers, so using <code>timer_gettime()</code>, which limits one clock per process, is not an option.... | [] | [
{
"body": "<h1>Timer Accuracy:</h1>\n\n<p>I would say you currently have a bug in your code as you sleep 1 sec between checking each Timer object. After a sleep you should check all the Timer objects once this is complete then go back to sleep.</p>\n\n<h2>Timer Granularity</h2>\n\n<p>sleep() is very course grai... | {
"AcceptedAnswerId": "8623",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-03T00:36:21.367",
"Id": "8611",
"Score": "3",
"Tags": [
"c++",
"linux",
"timer",
"pthreads"
],
"Title": "Linux C++ Timer Class: How can I improve the accuracy?"
} | 8611 |
<p>This is a basic program I wrote that lets you select a band, and give a description about the band and publish what you wrote.</p>
<p>Are there ways I can apply concepts of OOP to improve this code? Any help and tips would be greatly appreciated!</p>
<p>(I tried to put this on JSFiddle, but it was rendering diffe... | [] | [
{
"body": "<p>I have several comments on both your HTML and your JS.</p>\n\n<p>We'll start with the HTML:</p>\n\n<ul>\n<li><p>You can keep it much cleaner by <a href=\"http://en.wikipedia.org/wiki/Unobtrusive_Javascript\" rel=\"nofollow\">separating Javascript from it completely</a>. For example, instead of doi... | {
"AcceptedAnswerId": "8675",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-03T00:57:16.227",
"Id": "8612",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "Publishing a description about a selected band"
} | 8612 |
<p>I've implemented Jon Bentley's bitmap sorting algorithm from Column 1 of his Programming Pearls book. This code supports user-defined integer range (works from <code>Integer.MIN_VALUE</code> to <code>Integer.MAX_VALUE</code>), but for now only works on a distinct set of integers.</p>
<p>In order to avoid overflow i... | [] | [
{
"body": "<p>An idea: I'd try to implement the algorithm with bigger data types (<code>int</code>, <code>long</code>) instead of the <code>byte</code>.</p>\n\n<p>Some notes:</p>\n\n<ol>\n<li><p>I'd create a <code>BYTE_SIZE</code> constant for <code>8</code>, try to avoid magic numbers.</p>\n\n<pre><code>privat... | {
"AcceptedAnswerId": "8632",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-03T02:21:35.197",
"Id": "8613",
"Score": "5",
"Tags": [
"java",
"algorithm",
"sorting",
"bit-twiddling"
],
"Title": "Jon Bentley's bitmap sort implementation"
} | 8613 |
<p>I am making an app that allows the user to type chemical equations (H<sub>2</sub>O + NaCl) to the screen. The user taps, inside a tableviewcell, a custom textfield and types on a custom keyboard (both subclasses of uiviews). The vc doesn't have an actual instance of the keyboard, and the keyboard instead appears bec... | [] | [
{
"body": "<p>A UILabel is a view. Make your FormulaLabel class into just a Formula class that inherits from NSObject instead of UILabel.</p>\n\n<pre><code>@interface Formula : NSObject\n</code></pre>\n\n<p>Store data for one formula in the Formula class. The Formulas could be stored in the view controller vi... | {
"AcceptedAnswerId": "9080",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-03T06:28:01.227",
"Id": "8615",
"Score": "1",
"Tags": [
"design-patterns",
"objective-c",
"mvc"
],
"Title": "App for typing chemical equations to the screen"
} | 8615 |
Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications that enables malicious attackers to inject client-side script into web pages viewed by other users. An exploited cross-site scripting vulnerability can be used by attackers to bypass access controls such as the s... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-03T07:27:04.757",
"Id": "8617",
"Score": "0",
"Tags": null,
"Title": null
} | 8617 |
<p>I'm a C# programmer and I would like to start getting better at coding in C. I wrote a function which reads a space delimiters settings file (supports comments / and #).
The code works fine. But from the point of view of C coding style, I'd like to know if this code is well written.</p>
<p>example settings file:</p... | [] | [
{
"body": "<p>First of all, <code>getc</code> returns an <code>int</code>, not a <code>char</code> so change <code>char t_firstChar;</code> to <code>int t_firstChar;</code> (a <code>char</code> might not be able to hold <code>EOF</code>).</p>\n\n<hr>\n\n<p>In C it is conventional to put the pointer asterisk nex... | {
"AcceptedAnswerId": "8639",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-03T15:14:18.767",
"Id": "8620",
"Score": "9",
"Tags": [
"c",
"parsing"
],
"Title": "Read a space delimiters settings file in C"
} | 8620 |
<p>I have taken a stab at creating my first jQuery script from scratch. I use this to post an update to a Django application that allows a user to "follow" another user. I am sure that there are better ways to do this and I appreciate any help that anyone can give.</p>
<pre><code><script type="text/javascript">
... | [] | [
{
"body": "<p>This is how I'd do it. There may be flaws because you haven't provided your HTML.</p>\n\n<p>I assume that within the <code>click</code> handler, you only want to interact with the current element being clicked. The reason I say that is because you had <code>$('.follow')</code> a number of times in... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-03T15:14:22.013",
"Id": "8621",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Application for allowing a user to \"follow\" another user"
} | 8621 |
<p>I have a properties file I'm using for GIS software. You have a feature like a road, then properties under it, like so:</p>
<pre><code>{
"road": {
"colour": "rgb(0,0,0)"
},
"railway": {
"colour": "rgb(100,100,100)"
}
}
</code></pre>
<p>Now I need to group these into categories, f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-05T00:26:44.857",
"Id": "13550",
"Score": "0",
"body": "This has nothing at all to do with php."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T20:51:07.390",
"Id": "13748",
"Score": "0",
"bo... | [
{
"body": "<p>Assuming you're using JavaScript to manipulate the object, you could also split it up into 2 different structures, one for maintaining the hierarchy and another for easy access:</p>\n\n<pre><code>var hierarchy = {\n transportation: {\n road: {\n colour: \"rgb(0,0,0)\"\n ... | {
"AcceptedAnswerId": "8629",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-03T15:41:06.233",
"Id": "8622",
"Score": "0",
"Tags": [
"json"
],
"Title": "JSON formatting and processing hierarchies"
} | 8622 |
<p>I've just started working with Workflow (WF4) and have been playing with an idea of using it in MVC3.0 controller actions to see if it improves the maintainability of complex actions; also potentially giving the ability to make multiple DB calls in parallel to populate the output model. Along with this I've been l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T16:28:46.267",
"Id": "13690",
"Score": "2",
"body": "Just FYI - C# 4 introduced the Code Contracts library so you can do `Contract.Requires(inputModel != null)` which is more semantic and has interesting AOP possibilities. For examp... | [
{
"body": "<p>I cannot believe this went unanswered for 5 and a half years (I guess I can, it <em>is</em> a difficult question to answer) - I'm going to try to answer it from the respect of early 2012, and the respect of today (mid 2017).</p>\n\n<hr>\n\n<h1>2012</h1>\n\n<p>The biggest concern I see comes from t... | {
"AcceptedAnswerId": "173263",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-03T15:56:33.393",
"Id": "8624",
"Score": "6",
"Tags": [
"c#",
"asp.net-mvc-3",
"asynchronous"
],
"Title": "MVC Async Action Invoking Workflow"
} | 8624 |
<p>I have been building my own carousel over the past few days. I am not a jQuery guru, just an enthusiast, and I think my code is a little sloppy, hence the post.</p>
<p>Basically what happens is:</p>
<ul>
<li>If someone hits the page with a # values in the URL it will show the appropriate slide and example would be... | [] | [
{
"body": "<p><strong>1) Separation of Concerns</strong></p>\n\n<p>Start by refactorring your code in to more granular functions.\nYou can read more about SoF at <a href=\"http://en.wikipedia.org/wiki/Separation_of_concerns\" rel=\"nofollow\">http://en.wikipedia.org/wiki/Separation_of_concerns</a></p>\n\n<p>Upd... | {
"AcceptedAnswerId": "8635",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-03T19:59:14.863",
"Id": "8634",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"animation"
],
"Title": "Carousel for website"
} | 8634 |
<p>I wrote a framework and I want to hear the thoughts of other on the design patterns it uses. Every method contains three design patterns - adapters(strategy), intercepting filters, and observers.</p>
<p>A normal class/method in a class looks like this:</p>
<pre><code>class Run extends PVStaticObject{
public s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-05T18:37:15.480",
"Id": "13582",
"Score": "0",
"body": "Do not approach this problem from the point of view of the common solution of using DI/IoC/Strategy. This is none of those and does NOT strive to be it. These design patterns are ... | [
{
"body": "<p>Firstly, that is a ridiculous of boilerplate to put into every function. That alone means I'd never have anything to do with that code.</p>\n\n<p>Secondly, I don't see how its a good idea. Basically, all of these constructs allow the modification of the behaviour of the object. My functions won't ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-03T20:58:45.297",
"Id": "8637",
"Score": "5",
"Tags": [
"php",
"design-patterns",
"functional-programming"
],
"Title": "Design pattern for adapter"
} | 8637 |
<p>Under sage from another CR post I'm crafting an OOP MySQL connection/query class. Nothing new, but a place to start plying OOP PHP. Here is the current design,what would aid speed and portability?</p>
<p><strong>conf/config.php</strong></p>
<pre><code><?php
//Inlcude the Data Access Layer: Db
require_once (dir... | [] | [
{
"body": "<p>This code binds your Db object to the global constants. Its going to be difficult to connect to more than 1 database. Your DB class isn't doing anything for you.</p>\n\n<p>The solution to this is: <strong>injection</strong>. You should pass in the settings for the Db in the constructor. Below ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T03:45:46.050",
"Id": "8642",
"Score": "2",
"Tags": [
"mysql",
"performance",
"object-oriented",
"php5"
],
"Title": "OOP MySQL connection class"
} | 8642 |
<p>The factory should only have the responsibility of creating instances and <em>knowing what types</em> of instances to create, without having the added overhead of knowing about configurations. </p>
<p>With that in mind, here is how I would approach the problem: </p>
<pre><code>/// <summary>
/// Each class th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T19:18:06.047",
"Id": "13537",
"Score": "3",
"body": "I've been following your ongoing quest for this for most of your posts. I may be out of line here, but I just have to say: Do you *REALLY* need this level of abstraction? I get th... | [
{
"body": "<p>Sure, you can do that, why not? Isn't it easy to pass a list of Levels instead of a Level in GenerateProblem? Without more details on what you really want to do with that list, it's hard to answer.</p>\n\n<p>Unfortunately, as Willem van Rumpt said in comments, we're currently at the ProblemConfigu... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T06:17:35.737",
"Id": "8647",
"Score": "3",
"Tags": [
"c#",
"design-patterns"
],
"Title": "How to add a new feature to this factory model?"
} | 8647 |
<p>Please critique my word frequency generator. I am a beginner programmer so any criticism are welcome.</p>
<p>Original Code: <a href="http://pastebin.com/rSRfbnCt" rel="nofollow">http://pastebin.com/rSRfbnCt</a></p>
<p>Here is my revised code after the feedback:</p>
<pre><code>import string, time, webbrowser, coll... | [] | [
{
"body": "<pre><code>import string, time, math, webbrowser\n\ndef timefunc(function, *args):\n start = time.time()\n data = function(*args)\n end = time.time()\n timetaken = end - start\n</code></pre>\n\n<p>I'd recommend calling this <code>time_taken</code> as its slightly easier to read.</p>\n\n<p... | {
"AcceptedAnswerId": "8670",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T08:57:34.783",
"Id": "8648",
"Score": "6",
"Tags": [
"python",
"strings"
],
"Title": "Word frequency generator in Python"
} | 8648 |
<p>I've created a website that displays weather and currency rates for London and New York. The following is an abstract from my <code>cityConfig.php</code> script. Is this a good approach for adding variables from each city into an array? </p>
<pre><code>// Define arrays //
$cities = array();
$currencyRateHeading... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T12:03:36.943",
"Id": "13515",
"Score": "1",
"body": "*Another alternative I considered was to create extra variables by adding either a 1 or a 2 to the end of the variable name* - No, do not do this; it's naive (no offense). Can you... | [
{
"body": "<p>First of all, regarding your use of array_push(), I quote the <a href=\"http://se2.php.net/manual/en/function.array-push.php\" rel=\"nofollow\">documentation</a>: \"Note: If you use array_push() to add one element to the array it's better to use $array[] = because in that way there is no overhead ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T11:46:38.813",
"Id": "8649",
"Score": "2",
"Tags": [
"php",
"array"
],
"Title": "Setting configuration arrays"
} | 8649 |
<p>I am trying to create a stamp order / preview form for a site and have gotten fairly far on my own, with a little help from Google and of course you all. If you can suggest any other method of going about this, please guide me in the right direction. Also, I need to figure out how to put a border, the same colour as... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T12:29:22.803",
"Id": "13519",
"Score": "0",
"body": "I have included the code for you to see (As the FAQ says)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T12:41:56.953",
"Id": "13520",
"Sc... | [
{
"body": "<p>It is my first code review, I hope I'll be clear enough to explain why I would have done things like that.</p>\n\n<p>Here is how I would have it done - I removed the setCookie part because it was not used in what you show to us - :</p>\n\n<pre><code><html>\n <head>\n <meta... | {
"AcceptedAnswerId": "8664",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T12:13:04.323",
"Id": "8650",
"Score": "9",
"Tags": [
"javascript",
"beginner"
],
"Title": "Stamp order / preview form for a site"
} | 8650 |
<p>I create python dictionary based on the parsed data:</p>
<pre><code>user_details['city'] = None
if api_result.get('response')[1] and api_result.get('response')[1][0]:
api_result_response = api_result.get('response')[1][0] # city details
if api_result_response:
user_details['city'] = int(api_result_r... | [] | [
{
"body": "<p>You should just use <code>try</code>/<code>except</code> here:</p>\n\n<pre><code>try:\n response = api_result['response'][1][0]\n user_details['city'] = int(response['cid'])\n city_name = response['name']\nexcept KeyError, IndexError:\n pass\nelse:\n # do something\n</code></pre>\n\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T13:27:42.437",
"Id": "8652",
"Score": "4",
"Tags": [
"python"
],
"Title": "Python dictionary usage"
} | 8652 |
<p>Bulls and cows is a variation of the popular game called 'Mastermind', On a sheet of paper, the players each write a 4-digit secret number. The digits must be all different. Then, in turn, the players try to guess their opponent's number who gives the number of matches. If the matching digits are on their right posi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T04:23:04.590",
"Id": "13522",
"Score": "3",
"body": "Use a linked list instead of a vector, then erasure is much cheaper. Or copy just the eligible solutions to a brand new vector. Either one avoids the expense of copying elements... | [
{
"body": "<ol>\n<li><p>Use <code>char[n]</code> instead of string to store each individual solution.</p></li>\n<li><p>Copy just the eligible solutions to a brand new <code>vector</code> (as <em>Ben Voigt said</em>) instead of deletion.</p></li>\n</ol>\n\n<p>Assume <code>n<=10</code>. So, memory you need is ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T04:19:17.117",
"Id": "8656",
"Score": "10",
"Tags": [
"c++",
"algorithm"
],
"Title": "\"Bulls and cows\" algorithm"
} | 8656 |
<p>I have a function which is supposed to replace all instances of variables (represented as <code>NSStrings</code>) from an <code>NSDictionary</code> with their corresponding values before calling another procedure. I ended up doing this with a simple <code>for</code> loop, though I suspect that there is a better way.... | [] | [
{
"body": "<pre><code>+ (double)runProgram:(id)program usingVariables:(NSDictionary *)variables { \n NSMutableArray *stack;\n if ([program isKindOfClass:[NSArray class]]) {\n</code></pre>\n\n<p>Checking the type of incoming parameters is a little suspicious. Do you really want to allow other parame... | {
"AcceptedAnswerId": "8661",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T15:57:27.907",
"Id": "8659",
"Score": "8",
"Tags": [
"objective-c"
],
"Title": "Replacing Items in an NSMutableArray"
} | 8659 |
<p>I am trying to fetch information out of <a href="http://en.wikipedia.org/wiki/SHOUTcast">SHOUTcast</a> for mutiple users at the same time. Here is my current code:</p>
<pre><code><?php
header("Access-Control-Allow-Origin:*");
function failOut($http, $text) {
header('HTTP/1.x ' . $http);
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-05T11:41:19.883",
"Id": "13574",
"Score": "2",
"body": "Well first I'd suggest you ditch the mysql_* functions. :) Both PHP and MySQL have moved on a lot since the early days and the mysql_* set of functions really just don't cut it a... | [
{
"body": "<ol>\n<li><p>If you want to use this function you should have buffering:</p>\n\n<blockquote>\n<pre><code>function failOut($http, $text) {\n header('HTTP/1.x ' . $http);\n die(htmlspecialchars($text));\n}\n</code></pre>\n</blockquote>\n\n<p>Otherwise it's possible that the script sends out some ... | {
"AcceptedAnswerId": "44519",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T18:12:40.383",
"Id": "8666",
"Score": "7",
"Tags": [
"php",
"mysql",
"http"
],
"Title": "What is better for the code segment, sockets or multiple processes?"
} | 8666 |
<p>Here's my C++ code:</p>
<pre><code>bool isPrime(double value) {
if (value == 2) // ensure 2 returns true
return true;
else if (value <= 1) // eliminate 1 and all negative numbers
return false;
else if (fmod(value, 2) == 0) // eliminate all even num... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T17:55:13.840",
"Id": "13634",
"Score": "0",
"body": "I don't know how efficient the implementation is of `fmod()` on your system, but statements like `if ((value & 0x1) == 0)` is likely a faster way to detect even numbers. That's po... | [
{
"body": "<p>2 things:</p>\n\n<ol>\n<li><code>isPrime(9)</code> returns <code>true</code> because you're using <code><</code> in the loop's termination clause instead of <code><=</code>.</li>\n<li>You don't need to add a special case for eliminating even numbers, you can just change the loop's starting p... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T18:41:14.527",
"Id": "8667",
"Score": "18",
"Tags": [
"c++",
"primes"
],
"Title": "Is this C++ naive primality test done right?"
} | 8667 |
<p>I've got a simple thing that I inherited from another developer and think it could be replaced with something a bit more elegant. What this is doing is comparing the length of a string to a set value, and setting the font size accordingly:</p>
<pre><code>if(maxLen<50){$('.fc-cards').css('font-size',40);}
if(maxL... | [] | [
{
"body": "<p>So, a linear mapping from 50-200 onto 40-20 is (40-20)/(200-50) = 0.1333 font size points per length. So we can can compute this as</p>\n\n<pre><code>$('.fc-cards').css('font-size', 20 + 0.1333 * (200 - maxLen));\n</code></pre>\n\n<p>for a sliding linear falloff in font size. If you want to clamp ... | {
"AcceptedAnswerId": "8680",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-03T14:53:35.127",
"Id": "8679",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Algorithm to replace this duplicated code"
} | 8679 |
<p>Any suggestions on better way to remove the last word from a string?</p>
<pre><code>$words = str_word_count($text, 1);
$lastWord = array_pop($words);
$textWithoutLastWord = implode(" ", $words);
</code></pre>
<p>or </p>
<pre><code>$lastSpacePosition = strrpos($text," ");
$textWithoutLastWord =substr($text,0,$last... | [] | [
{
"body": "<p>Regular expressions are your friend, this should find the last word and remove it while keeping the final punctuation. This may not work with multiline strings, you'll have to fiddle with the regular expression.</p>\n\n<pre><code>$textWithoutLastWord = preg_replace('/\\W\\w+\\s*(\\W*)$/', '$1', $w... | {
"AcceptedAnswerId": "8810",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-05T14:43:17.643",
"Id": "8683",
"Score": "2",
"Tags": [
"php",
"strings"
],
"Title": "Remove last word from string"
} | 8683 |
<p>I'm trying to make my function more versatile by removing hard coded data.</p>
<pre><code>function get_currency_rate($currencySource) {
if (isset($currencySource)) {
$feed = $currencySource;
} else {
echo 'Feed not found. Check URL';
}
if (!$feed) {
echo('Feed not found');
... | [] | [
{
"body": "<p>Well the first thing I notice is that your <code>get_currency_rate()</code> function requires a <code>$currencySource</code> to be added as a parameter. Which makes the first if statement a little redundant. The other thing is that <code>get_currency_rate()</code> is setting the variable <code>$ra... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-05T17:05:35.377",
"Id": "8684",
"Score": "3",
"Tags": [
"php",
"xml",
"url",
"configuration",
"rss"
],
"Title": "Configuring a currency converter to get exchange rate feeds f... | 8684 |
<p>It's often useful to strip carriage returns out of a plain text document, for example when copying and pasting into a field that automatically wraps lines. However, it's usually a good idea to leave some of the carriage returns in — most obviously at paragraph breaks, but also around bullet lists, section headings,... | [] | [
{
"body": "<p>Two things:</p>\n\n<ol>\n<li>Try using <code>String</code> instead of <code>[Char]</code>, it reads a lot easier (imho).</li>\n<li>Don't use <code>head</code>, use pattern matching instead. It reads better, and it's good practice, because if it passes an empty list you will get an error (though yo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-02-05T18:42:58.530",
"Id": "8687",
"Score": "3",
"Tags": [
"algorithm",
"strings",
"haskell"
],
"Title": "\"Intelligent\" removal of carriage returns that preserves paragraph breaks, he... | 8687 |
<p><a href="http://www.r-project.org" rel="nofollow noreferrer" title="R project homepage">R is an open source programming language and software environment</a> for statistical computing and graphics. It is an implementation of the <a href="http://lib.stat.cmu.edu/S/Spoetry/Tutor/slanguage.html" rel="nofollow noreferre... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T05:56:36.363",
"Id": "8689",
"Score": "0",
"Tags": null,
"Title": null
} | 8689 |
R is a free, open source programming language and software environment for statistical computing and graphics. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T05:56:36.363",
"Id": "8690",
"Score": "0",
"Tags": null,
"Title": null
} | 8690 |
<p>I have an <code>NSArray</code> called <code>program</code> and I need to scan it and then produce an <code>NSSet</code> of objects that fit the test <code>isOperation:</code>. If none are found I should return <code>nil</code>. I wrote the following code. How would you make this better? (FYI - the fact the progra... | [] | [
{
"body": "<p>The only real issue I see is that you're leaking memory. You are allocating a mutable set that you never release and then copying it to presumably make it immutable thus leaking more memory.</p>\n\n<pre><code>+ (NSSet *) variablesUsedInProgram:(id)program {\n NSMutableSet *variablesUsed = [[NSM... | {
"AcceptedAnswerId": "8702",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T06:26:56.213",
"Id": "8691",
"Score": "1",
"Tags": [
"objective-c"
],
"Title": "Scanning an NSArray to produce an NSSet"
} | 8691 |
<p>This function takes an array of strings and numbers and recursively processes it as a kind of "calculating program". The structure is based on Reverse Polish Notation, so the top object in the stack (last in the array) determines what to do with the next one (or two) items in the program. For example, if the array... | [] | [
{
"body": "<p>Instead of returning an error-String, I would pass in a nil'ed-NSError object by reference, and write an error to it, in case it occurred. the returned object would be nil</p>\n\n<pre><code>+ (NSNumber *)popOperandOffProgramStack:(NSMutableArray *)stack error:(NSError **)error\n{\n //…\n err... | {
"AcceptedAnswerId": "8800",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T06:44:30.980",
"Id": "8693",
"Score": "3",
"Tags": [
"recursion",
"objective-c",
"math-expression-eval"
],
"Title": "RPN-Stack-Based Recursive Calculator Needs Tuneup"
} | 8693 |
<p>This is a method which takes an input of a "page" object, which includes SortOrder. It then fetches the existing page items from a database and attempts to re-index.</p>
<p>I don't think this is at all efficient and reads horribly and wondered if anybody could make some recommendations?</p>
<pre><code> public ... | [] | [
{
"body": "<p>Here's a little bit of how I'd reorganize. The key elements which could affect speed are: creating the repository only once, using the LINQ extension <code>Any</code> which has the possibility of optimizing the SQL generated and early return if there are no entries in the database.</p>\n\n<pre><co... | {
"AcceptedAnswerId": "8704",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T14:38:18.830",
"Id": "8699",
"Score": "1",
"Tags": [
"c#",
"asp.net-mvc-3"
],
"Title": "Improving readability and logic on \"re-indexing\" method"
} | 8699 |
<p>I have posted such question at StackOverflow but the single answer I got there was to ask here.<br>
My task is to get elements fading in while the user is scrolling. Here is my link - <a href="http://layot.prestatrend.com/" rel="nofollow">http://layot.prestatrend.com/</a> I have made it with the help of such jQuery ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T19:31:19.443",
"Id": "13642",
"Score": "0",
"body": "Can you clarify what you mean by \"fade for elements while scrolling\"? I see nothing on the page that does fade in while scrolling, I just see things fading in as you hover over ... | [
{
"body": "<p>The onScroll event is generally very performance hungry, since it is called quite often, while scrolling. Looping through all \"ajax_block_product\" elements on every singel call, even if most of them might be outside of the viewport, makes it even worse. But you can use some specialities of JS to... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T15:18:46.640",
"Id": "8700",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Fading in while scrolling - is this an elegant solution?"
} | 8700 |
<p>I've reusing this code for multiple areas and will like to make it more short and/or portable. What suggestions or changes could I make to simplify shorten it's callback processes?</p>
<pre><code> $("#add_question_member").submit(function(){
$.ajax({
type:'post',
... | [] | [
{
"body": "<p><a href=\"http://jsfiddle.net/YNtPh/8\" rel=\"nofollow\">Here is a jsfiddle where I cleaned it up for you</a></p>\n\n<p>I did not actually test it so there might be a syntax error here and there but its how you would do it overall.\nIt might not be 100% but it should get you started as far as the ... | {
"AcceptedAnswerId": "8711",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T16:39:01.063",
"Id": "8705",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "How can I Shorten and Simplify Ajax callback processes?"
} | 8705 |
<p>I wrote a bash script to print contents of files in a given directory in a loop.</p>
<p>How can I improve command line parameters handling to the script? I feel the parameter processing as of now uses too much code and it is quite clumsy. I think I had to write too much code to validate the the option arguments are... | [] | [
{
"body": "<p>A few suggestions at your disposal: You can make use of <code>getopts</code> instead of <code>getopt</code> to avoid <code>shift</code> operation. You can make use of a simple flag to make sure that the mandatory <code>-c</code> option has been passed. Also from <a href=\"https://stackoverflow.com... | {
"AcceptedAnswerId": "8923",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T02:15:01.783",
"Id": "8706",
"Score": "6",
"Tags": [
"bash",
"file-system",
"linux"
],
"Title": "Printing a directory's contents in a loop"
} | 8706 |
<p>I have data that I want to insert in a database. Sometime a piece of data is already in the database, so I just want to update the fields that changed.</p>
<p>For example, if I insert these rows one after the other:</p>
<blockquote>
<pre class="lang-none prettyprint-override"><code>id | field1 | field2 | field3... | [] | [
{
"body": "<p>I think it is.</p>\n\n<p>What you are asking for is known as <code>UPSERT</code> - a <a href=\"http://en.wikipedia.org/wiki/Portmanteau\" rel=\"nofollow\">portmanteau</a> of <code>UPDATE</code> and <code>INSERT</code>. Some databases support <code>UPSERT</code> intrinsically, but some don't. A qui... | {
"AcceptedAnswerId": "8721",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T17:08:44.853",
"Id": "8708",
"Score": "2",
"Tags": [
"sql",
"mysql",
"pdo"
],
"Title": "Updating only certain fields on a database row"
} | 8708 |
<p>I'm fairly new to Ruby, and I've been refactoring this code (it's a silly app, but it's helping me learn) as I learn more and more best practices and features new to Ruby 1.9 (e.g., hashrocket alternative). I figure having more experienced Rubyists give feedback on the short program will help me learn faster. So, wi... | [] | [
{
"body": "<p>Generally Rubyists define methods in the underscore-lowercase pattern: <code>def twitter_auth</code>, <code>def send_tweet</code>. Additionally most that I've encountered prefer to drop the <code>()</code> from method calls: <code>twitter_authenticate creds; send_tweet creds</code></p>\n\n<p>Other... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T17:40:57.787",
"Id": "8710",
"Score": "3",
"Tags": [
"ruby",
"twitter"
],
"Title": "Entering and authorizing Twitter credentials"
} | 8710 |
<p>I'm a JavaScript coder trying to teach myself Java using online tutorials and ebooks. I have now created my very first applet but feel it only really goes to show the depth of my unappreciation for Java's capabilities. Please, give me some advice as to how to use Java better so that my future projects can be less ef... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T05:34:04.710",
"Id": "13635",
"Score": "2",
"body": "java applets aren't used much (if at all) anymore. Most java apps are server side only with frontend doing html/css/javascript."
}
] | [
{
"body": "<p>Quick overview, I didn't run this code and only reading lines from top to the bottom:</p>\n\n<ol>\n<li><p>Use <code>JApplet</code> (Swing) instead of prehistoric <code>Applet</code> (AWT) that came from last millenium</p></li>\n<li><p>For <a href=\"http://docs.oracle.com/javase/tutorial/2d/index.h... | {
"AcceptedAnswerId": "8713",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-04T05:30:32.783",
"Id": "8712",
"Score": "3",
"Tags": [
"java"
],
"Title": "Sliding-Puzzle Applet"
} | 8712 |
<p>I'm getting started with my first official jQuery plugin, and I'm just turning now looking for input. I want to know what I'm doing wrong or right so far and if everything is being developed in a manner that won't cause issue down the road. With no further adieu:</p>
<pre><code>$.fn.heftyBox = function(args) {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T20:06:48.187",
"Id": "13643",
"Score": "0",
"body": "Can you give us an use case, some HTML which one it will work. It'll be more easy to see how it works and what it is doing. I already can see some optimization but with an use cas... | [
{
"body": "<p>Well I forked it and will work on a refactoring but some comments:</p>\n\n<ul>\n<li>Cache variables so that you don't have to keep invoking <code>$()</code> - it is common to do <code>var $this = $(this);</code></li>\n<li>Don't use ids. They are a host of problems. What if there are 2 hefty boxes ... | {
"AcceptedAnswerId": "8724",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T19:52:24.300",
"Id": "8714",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"plugin"
],
"Title": "My first jQuery plugin -- Heftybox"
} | 8714 |
<p>After learning that <code>std::map</code> containers are not inherently atomic and therefore not thread-safe (check out <a href="https://stackoverflow.com/questions/9147258/object-of-shared-pointer-being-deleted-while-instances-of-shared-ptr-are-still-i">this</a> related Stack Overflow question and usage example), I... | [] | [
{
"body": "<p>Use boost::noncopyable instead of DISALLOW_COPY_AND_ASSIGN:</p>\n\n<pre><code> template <class K, class V>\n class map_guard: boost::noncopyable\n {\n</code></pre>\n\n<ol>\n<li><p>boost::noncopyable resides in the first line instead of deep internals</p></li>\n<li><p>DRY -- you do not ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T20:27:59.117",
"Id": "8715",
"Score": "9",
"Tags": [
"c++",
"multithreading",
"thread-safety",
"synchronization",
"stl"
],
"Title": "Thread-safe std::map accessor"
} | 8715 |
<p>After scouring the interweb, I am having trouble finding an efficient solution to the following issue (the biggest problem was knowing what to ask):</p>
<p>I'm trying to find a way to write a more efficient version of the jQuery script found on the <a href="http://redesign.mproven.com/sliding_example.html" rel="nof... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T21:37:38.727",
"Id": "13649",
"Score": "0",
"body": "[Please post the code in the question.](http://codereview.stackexchange.com/faq#questions)"
}
] | [
{
"body": "<p>`</p>\n\n<pre><code>$(function(){\n\n $('.logo').fadeTo(\"fast\", 0);\n\n $(\".logo\").hover(function() {\n $(this).stop().animate({\"opacity\": \"1\"}, \"500\");\n $('.sliding_titles div#content-'+this.id).stop().animate({opacity: 1, width: \"500px\", overflow: \"visible\" }, ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-06T21:25:09.293",
"Id": "8718",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Efficiently matching pairs of elements and applying specific hover trigger/animation to each p... | 8718 |
<p>I recently started working on a project that had been dropped by the previous dev. When looking through the existing code, I came across this singleton Database Class.</p>
<pre><code>class Database{
private static $instance;
private $PDOInstance;
// Customize when ready
private function __construct(){
try{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T15:25:24.597",
"Id": "13739",
"Score": "0",
"body": "Singletons are big trouble. I'd rethink your strategy if I were you. http://gooh.posterous.com/singletons-in-php"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDat... | [
{
"body": "<p>A simple workaround, assuming that you want to keep the class a Singleton:</p>\n\n<pre><code>class Database {\n private static $instance;\n private $PDOInstance;\n\n public static function getInstance(){\n if(!self::$instance){\n try{\n self::$instance = n... | {
"AcceptedAnswerId": "8725",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T00:12:22.523",
"Id": "8723",
"Score": "4",
"Tags": [
"php",
"pdo"
],
"Title": "Using PHP's __call() to emulate a Class instead of Extending"
} | 8723 |
<p>I have 2 validation groups, VG1 and VG2. I have a button <code>BtnInsert</code> that saves data into <code>Datasource</code>. Its Validation Group is VG2. Now, I want to validate both VG1 and VG2 when a user clicks the <code>BtnInsert</code>.</p>
<pre><code>protected void BtnInsert_click(object sender,EventArgs e)... | [] | [
{
"body": "<p>AFAIK, you won't get client-side validation of VG2, but otherwise I can't see that it shouldn't work. (There is probably a client-side event and a method you could call to duplicate the behavior for the client)</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"Conten... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T13:12:44.350",
"Id": "8738",
"Score": "1",
"Tags": [
"c#",
"asp.net",
"validation"
],
"Title": "Validate several validation groups"
} | 8738 |
<p>I debated long and hard before posting this question, and I did a lot of experimenting. I just can't seem to work out an 'elegant', concise way to get done what I want done in the manner I want it done. I found it very hard to research because of the difficulty in not knowing exactly what to search for.</p>
<p>Ag... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T09:57:40.833",
"Id": "13676",
"Score": "0",
"body": "Kill dead code and variables; `from_binary` arguments dec_bttn and hex_bttn are useless and should be removed."
}
] | [
{
"body": "<p>Use more python, e.g. instead of:</p>\n\n<pre><code>for i in hex_digits.keys():\n if i == tot:\n tot = hex_digits[i]\n else:\n tot = tot\n</code></pre>\n\n<p>Remove extraneous keys() and it becomes:</p>\n\n<pre><code>for i in hex_digits:\n if i == tot:\n tot = hex_dig... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T09:13:12.100",
"Id": "8740",
"Score": "3",
"Tags": [
"python",
"converting",
"tkinter"
],
"Title": "Binary/decimal/hex converter using Tkinter"
} | 8740 |
<p>Recently I had the idea to write a module for the transformation of the dictionary into valid CSS code. And I would like to hear your comments on my code.
License MIT, BSD etc.</p>
<p>The code is very simple:</p>
<pre><code>#pss.py
class PSS:
def __init__(self, obj):
self.obj = obj
self.__dat... | [] | [
{
"body": "<p>Two random remarks:</p>\n\n<ul>\n<li><p>\"__parse\" isn't a great method name since no actual parsing is going on.</p>\n\n<pre><code> for i in sorted(self.__data.keys()):\n</code></pre></li>\n<li><p>The variable name \"i\" is commonly used for (list) indexes. When iterating over a dict, it's mo... | {
"AcceptedAnswerId": "8750",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T16:07:04.260",
"Id": "8747",
"Score": "5",
"Tags": [
"python",
"css",
"hash-map"
],
"Title": "Transforming a Python dictionary into CSS"
} | 8747 |
<p>I have a category table (brands) and 2 other tables (<code>Pens</code> and <code>Pencils</code>) that have parent-child relation with this table through a field <code>CatID</code>. Now I want to get a list of <code>Brands</code>and number of records in child tables.</p>
<p>I use this query:</p>
<pre><code>Select ... | [] | [
{
"body": "<p>Did you try this query? Did it work? Unless ID and Title are the only columns in the Brands table this query would result in an error. </p>\n\n<p>I would use subqueries for this:</p>\n\n<pre><code>SELECT\n Brands.*,\n (SELECT COUNT(*) FROM Pens WHERE CatID = Brands.ID) AS PensCount,\n (SE... | {
"AcceptedAnswerId": "8755",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T16:44:52.700",
"Id": "8748",
"Score": "2",
"Tags": [
"sql",
"sql-server"
],
"Title": "Query to get number of related records in 2 child tables"
} | 8748 |
<p>I've been trying to learn how to develop jQuery plugins but have little guidance on the matter. I see lots of code on the web, of course, but am not sure what exactly constitutes best practices due to the level of variability in style.</p>
<ul>
<li><p><code>$.notify</code> - Displays a simple notification bar simil... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T19:29:26.557",
"Id": "13705",
"Score": "0",
"body": "C# techniques actually translate to js quite nicely if you are a big-time linq-over-collections user. Basically both languages support and encourage a partially functional paradig... | [
{
"body": "<p>OK, let's see.</p>\n\n<p>First of all by glancing on the code, you don't seem to know what <code>==</code> does.</p>\n\n<p>Especially by looking at <code>this.timer != undefined && this.timer != null</code> this does the <strong>exact same</strong> check twice as <em>type coercion</em> is ... | {
"AcceptedAnswerId": "8760",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T18:30:08.870",
"Id": "8754",
"Score": "4",
"Tags": [
"javascript",
"jquery"
],
"Title": "Am I on the right track with JavaScript/jQuery?"
} | 8754 |
<p>Does anyone have suggestions on how to refactor this?</p>
<pre><code>$(document).ready(function () {
$("td,select,th").css("min-width", "150px");
$("#cancel").button({
disabled: true
});
$(".group-32 input").datepicker();
$(".group-6 input").datepicker();
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T19:24:42.503",
"Id": "13703",
"Score": "2",
"body": "ID's can't start with a number."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T19:25:11.100",
"Id": "13704",
"Score": "0",
"body": "Th... | [
{
"body": "<p>Since your code is all the same, you can dynamically create your selector:</p>\n\n<pre><code>...\n\n$( '#0LevelId,#1LevelId,#3LevelId' ).change( function(){\n ...\n $( '#' + this.id.substr( 0, 1 ) + 'EffectiveDate' )...\n} );\n</code></pre>\n",
"comments": [
{
"ContentLicen... | {
"AcceptedAnswerId": "8757",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T19:20:14.540",
"Id": "8756",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"datetime",
"form"
],
"Title": "Setting some element widths, disabling a button, and initializin... | 8756 |
<p>My code has to download the source code of a page and parse it for URLs. I want it to ask for number which is increased inside the critical section. My problem happens on thread termination.</p>
<p>Main form code:</p>
<pre><code> unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Gra... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-10T16:30:23.413",
"Id": "13869",
"Score": "1",
"body": "It's been a while since I've done Delphi, but make sure the code between `EnterCriticalSection` and `LeaveCriticalSection` are within `try..finally` to clean up properly in the ev... | [
{
"body": "<p>I haven't looked closely at your code .. yet. But I did a similar project some months ago.\nFirst off ... </p>\n\n<pre><code> Exit;\n (*How can I terminate thread here if I get error*)\n</code></pre>\n\n<p>Should be simple enough. Change skinisors into a <code>function skinisors : boolean</c... | {
"AcceptedAnswerId": "8849",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T19:54:35.060",
"Id": "8759",
"Score": "2",
"Tags": [
"multithreading",
"http",
"delphi"
],
"Title": "Parsing a page's source code for URLs"
} | 8759 |
<p>I'm new to Ruby and trying to do a bit of metaprogramming. I want to declare some "properties" on a class, describing some field names and their access privileges:</p>
<pre><code>class Resource
# my_property(name, privilege => level)
my_property :id, :read => :admin # :write => :none
my_property :nam... | [] | [
{
"body": "<p>Rather than access the possibly uninitialized <code>@permissions</code> instance variable inside <code>my_property</code>, use your wrapper method <code>permissions</code> and put the initialization logic in there. Also use <a href=\"http://apidock.com/ruby/Hash/new/class\" rel=\"nofollow\"><code>... | {
"AcceptedAnswerId": "8766",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T20:43:34.840",
"Id": "8765",
"Score": "5",
"Tags": [
"ruby"
],
"Title": "Ruby metaprogramming - declaring \"properties\" on a class"
} | 8765 |
<p>I have reviewed the FAQ and I believed it was yes to all 5 q's of "What questions are on-topic for this site?"</p>
<p>Basically, the code below is used to perform the operation shown in the picture. I'm wondering what I can improve in the attached code to clean it up for future reference. Thanks in advance!
<img sr... | [] | [
{
"body": "<p>Some pointers off the top of my head:</p>\n\n<ol>\n<li><p>It's always good practice to have good variable names: <code>i</code>, <code>j</code>, and <code>k</code> aren't bad but they could be more explicit.\n(for example, <code>i</code> could be <code>currentRowIndex</code>)</p></li>\n<li><p><cod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T01:59:30.127",
"Id": "8767",
"Score": "3",
"Tags": [
"vba"
],
"Title": "VBA Data Conversion (random printout -> CSV file)"
} | 8767 |
<p>This is my first go at implementing the DAO pattern - let alone implementing it for MongoDB with Morphia - I was hoping someone could point out smells and answer questions from my below implementation.</p>
<pre><code>public interface GenericDAO<T, K extends Serializable>
{
public void insert(T entity);
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-13T15:46:51.363",
"Id": "14007",
"Score": "0",
"body": "What is exactly the question?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-14T22:42:04.087",
"Id": "14078",
"Score": "0",
"body": "@Geo... | [
{
"body": "<p>I disagree with <code>Generic DAO</code> design, reason of it is : </p>\n\n<p>You design generic dao with to generic type <code>T</code>, <code>K</code>, <code>T</code> for entity type and <code>K</code> for entity id. Now I say: </p>\n\n<ol>\n<li><p>What happen with this design if in a part of ap... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T04:28:07.737",
"Id": "8769",
"Score": "4",
"Tags": [
"java",
"design-patterns"
],
"Title": "Correct DAO implementation?"
} | 8769 |
<p>The background is my question is SO <a href="https://stackoverflow.com/questions/9131481/how-to-create-a-list-of-totals-for-durations">How to create a list of totals for durations?</a>
where I found a recursive solution that I want to review. I could not test it for higher levels than 1 but to the best of my knowled... | [] | [
{
"body": "<pre><code>def level(self):\n startdate = model.Order.all().filter('status =', 'PAID'\n ).filter('distributor_id =',\n self._key.id()).get().created.date()\n last_day_nextmonth = startdate + relativedelta(months=2) \\\n - timedelta(days=1)\n</code></pre>\n\... | {
"AcceptedAnswerId": "8787",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T05:27:12.273",
"Id": "8770",
"Score": "7",
"Tags": [
"python",
"recursion",
"datetime"
],
"Title": "Calculate highscores based on sales data"
} | 8770 |
<p>The code for the <code>LevelParser</code> is shown below. It is also documented using Java-doc; the docs are in the project directory.</p>
<p>Now by improving this piece of code, I do <strong>not</strong> mean optimizing it to incomprehension, or improving its performance. What I want is to make it a bit more reada... | [] | [
{
"body": "<pre><code>public class LevelParser {\n List<Sprite> tileArray = new ArrayList<Sprite>();\n Map<Character, String> tileMapping = new HashMap<Character, String>();\n Map<Character, String> messageMapping = new HashMap<Character, String>();\n\n Point offs... | {
"AcceptedAnswerId": "8795",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T07:18:09.707",
"Id": "8771",
"Score": "2",
"Tags": [
"java",
"game",
"parsing",
"graphics"
],
"Title": "Game level parser"
} | 8771 |
<p>This is my first OOP coding project and I would appreciate any constructive criticism as to how I could have used the benefits of Java and OOP to better effect. How would you have implemented this differently? I have been learning Java for less than a week but I hope to go on to make Android apps. See here for this ... | [] | [
{
"body": "<p>After a quick look:</p>\n\n<ul>\n<li>I would use anonymous inner classes for the listeners. One advantage is that you can inherit from Adapters</li>\n<li>in Swing, usually you should overwrite <code>paintComponent</code>, not <code>paint</code></li>\n<li><code>ArrayList locations</code> should be ... | {
"AcceptedAnswerId": "8890",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T08:36:32.930",
"Id": "8772",
"Score": "3",
"Tags": [
"java",
"object-oriented"
],
"Title": "My first OOP piece... how have I done?"
} | 8772 |
<p>The following piece of code is used to re-position controls on a form considering different options.</p>
<p>Once you have multiple controls this becomes quite messy. I would appreciate your improvement suggestions.</p>
<pre><code>private void dlgOptionsForm_Load(object sender, System.EventArgs e)
{
if... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-12T03:22:20.147",
"Id": "13936",
"Score": "0",
"body": "If you have to do this, then I think you are doing something wrong. When controls are not in one position but dance all over the screen, it confuses the user. Be nice to the user.... | [
{
"body": "<p>Solution 1:</p>\n\n<p>If all of your grp* inherits of the same object (say Control), what you can do is:</p>\n\n<pre><code>private List<Control> _groups = new List<Control>();\n\n.ctor()\n{\n // Populate _groups\n _groups.Add(grpPeriod);\n _groups.Add(grpPrintOptions);\n _group... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T10:17:22.683",
"Id": "8774",
"Score": "2",
"Tags": [
"c#"
],
"Title": "Re-positioning controls on a form"
} | 8774 |
<p>This is one of my first OOP programs in normal PHP, without any framework. This combines all .css files into one and all .js files into one, and it works. Are there any suggestion on what I can make better in terms of OOP or anything else?</p>
<p>This is how it works:</p>
<p>I run this: <code>http://localhost/fold... | [] | [
{
"body": "<p>The first thing I notice is private everything. Generally I avoid <code>private</code> unless the function is really, really, <em>really</em> specific to <strong>only, and ever only, that class.</strong> This class could be extended but wouldn't really provide the extending class with anything b... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T11:14:29.663",
"Id": "8775",
"Score": "3",
"Tags": [
"php",
"object-oriented"
],
"Title": "Combining .css and .js files"
} | 8775 |
<p><strong>Summary: Please let me know, what weaknesses do you see in the described workaround for event handlers preventing garbage collection of registered listener objects...</strong></p>
<p>I'm in the development of and API for a set of devices communicating with each other, and optionally with a PC trough a socke... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T10:51:06.573",
"Id": "13731",
"Score": "0",
"body": "This may be more suitable on StackOverflow (or CodeReview?). Please don't cross-post it though - it will get automigrated if enough people agree with this and votes to close here.... | [
{
"body": "<p>At first glance, <code>PacketEventHandler</code> is a rather confusing name for a class, but then looking at it more thoroughly I see that it's actually a <em>wrapper</em> around an event handler, so I see what made you call it that way, but I'd still try harder to find a better name... although I... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T09:25:29.233",
"Id": "8776",
"Score": "11",
"Tags": [
"vb.net"
],
"Title": "Another way to implement weak event handlers in vb.net"
} | 8776 |
<p>I'm relatively familiar to Ruby, but I'm brand-new to testing code. I've decided to use RSpec because as it seems like a popular option.</p>
<p>The game works perfectly, but the spec has a lot of repetition and I have a feeling it can be improved.</p>
<h3>The Spec</h3>
<pre><code>require 'rock_paper_scissors'
# ... | [] | [
{
"body": "<pre><code>let(:answers_snippet) { /valid answers/ }\n\nit \"fails when invalid\" do\n game = RockPaperScissors.new(0)\n game.result.should match(answers_snippet)\nend\n</code></pre>\n\n<p>When I read this spec code, I see that result should match <code>valid answers</code>, but from the spec name ... | {
"AcceptedAnswerId": "8989",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T17:17:46.307",
"Id": "8782",
"Score": "2",
"Tags": [
"beginner",
"ruby",
"rock-paper-scissors",
"rspec"
],
"Title": "My first RSpec test - Rock Paper Scissors"
} | 8782 |
<p>I've written a JavaScript table class to make it easy to display tabular data and allow the user to sort the data by clicking on the table headers.</p>
<p>However, when there are hundreds of rows, performance on the sorting is a bit sluggish. I would like to know what kind of improvements I can make. I suspect th... | [] | [
{
"body": "<p>This was originally a comment, but it got long.</p>\n\n<ul>\n<li><p>The jQuery/innerHTML stuff is probably slowing it down, as it looks like you guessed. Tables in IE + innerHTML is broken. Instead, I'd use the DOM.</p></li>\n<li><p>Reconstituting the entire table for each sort is bound to be slow... | {
"AcceptedAnswerId": "8789",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T19:30:40.727",
"Id": "8783",
"Score": "3",
"Tags": [
"javascript",
"strings"
],
"Title": "How can I improve performance for my JavaScript table class?"
} | 8783 |
<p>What my script does is:</p>
<ol>
<li>Append data to a file on a continuous basis.</li>
<li>If an error pattern is observed, then do something.</li>
</ol>
<p>I need feedback on the way I am grepping for patterns in the continuously appended file. For grep, I am creating a pattern file first and then using it with -... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-21T08:09:37.703",
"Id": "14431",
"Score": "0",
"body": "Any specific issue you're having? Security? Efficiency? Accuracy? Complexity?"
}
] | [
{
"body": "<p><a href=\"http://www.grymoire.com/Unix/Quote.html\" rel=\"nofollow\">Use more quotes</a>, as the saying goes.</p>\n\n<p>I find <code>while true</code> is more clear, but the idiomatic <code>while :</code> is also popular.</p>\n\n<p>You might want to use an array for the patterns, then you can simp... | {
"AcceptedAnswerId": "11049",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T19:50:58.720",
"Id": "8784",
"Score": "3",
"Tags": [
"optimization",
"bash",
"linux"
],
"Title": "How to improve the way I handle greping in this script"
} | 8784 |
<p>So in my current application, I was thinking to make a extended class for all the datatypes. For <code>int</code>, it will be something like <code>ExtendedInt</code>, for <code>bool</code> it will be something like <code>ExtendedBool</code>.</p>
<p>These individual extended classes will expose some special functona... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T23:25:13.073",
"Id": "13756",
"Score": "0",
"body": "You do realize that basic types are *already* an abstraction, right? Why complicate things unnecessarily? What value do your abstractions provide and what potential problems cou... | [
{
"body": "<p>Too much overhead - <a href=\"http://msdn.microsoft.com/en-us/library/1t3y8s4s.aspx\" rel=\"nofollow\">nullable types</a> and <a href=\"http://msdn.microsoft.com/en-us/library/bb383977.aspx\" rel=\"nofollow\">extension methods</a> seem to give you what you need. The checking you do on your setters... | {
"AcceptedAnswerId": "8791",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T20:52:09.233",
"Id": "8788",
"Score": "4",
"Tags": [
"c#",
"asp.net",
"classes"
],
"Title": "Is it a good practice to wrap datatypes in custom classes?"
} | 8788 |
<p>I've implemented two different versions of the <a href="http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle" rel="nofollow">Fisher-Yates shuffle</a> in javascript, and I'd like to know if I've made any mistakes.</p>
<p>I'm creating a deck of playing cards. I'm interested in these shuffle algorithms. </p>
<p>... | [] | [
{
"body": "<p>Unless you modify the inside out code to scale by <code>(index+1)</code></p>\n\n<pre><code> randomIndex = rand()*(index+1)|0;\n</code></pre>\n\n<p>You will not be covering all the possibilities.\nFor <code>index == 0</code>, you always generate 0 -- this is correct, but only by accident.</p>... | {
"AcceptedAnswerId": "8794",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-08T23:41:26.913",
"Id": "8793",
"Score": "5",
"Tags": [
"javascript",
"algorithm",
"shuffle"
],
"Title": "Fisher-Yates shuffle algorithm in javascript, modern and inside-out versio... | 8793 |
<p>This is not homework. I am trying to learn OOD principles and design patterns myself.</p>
<p>Suppose I have a problem like this:</p>
<blockquote>
<p>A book-shop buys and sells two types of books:</p>
<ol>
<li>Non-technical {Title, Author, Price}</li>
<li>Technical {Title, Author, Price, CD}</li>
</ol>... | [] | [
{
"body": "<p>I will not address the Open-Closed principle, as I do not know it.</p>\n\n<h2>How to separate Technical from NonTechnical books</h2>\n\n<p>This second question belongs in StackOverflow.<br>\nYet another reason to open a separate question for each real question you have...</p>\n\n<p>But you can do ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T07:31:42.317",
"Id": "8797",
"Score": "3",
"Tags": [
"c#"
],
"Title": "Bookstore classes design"
} | 8797 |
<p>I'm trying to build a JavaScript library that does basic financial calculations, such as NPV, IRR, PV, FV, etc. So far I've added the NPV functionality only, and it's passed my test cases. But I want to know if the code overall can be written better.</p>
<pre><code>(function () {
/*
This library depends on unde... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T07:57:42.477",
"Id": "13779",
"Score": "1",
"body": "That's not much of an introduction. What does it do? Are there specific things you want to improve? Please paste the code in your question (highlight it and hit ctrl+k to format).... | [
{
"body": "<ol>\n<li><p>Avoid getting a reference to the global object (\"window\") using <code>this</code>; it won't work in strict mode. If this is only meant to run in the browser, just use <code>window</code>; otherwise you can do <a href=\"https://stackoverflow.com/a/9647292/886931\">this</a>:</p>\n\n<pre>... | {
"AcceptedAnswerId": "8859",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T07:45:44.707",
"Id": "8798",
"Score": "6",
"Tags": [
"javascript",
"library",
"finance"
],
"Title": "Basic financial calculation library"
} | 8798 |
<p>For <a href="http://www.cs.rhul.ac.uk/home/joseph/teapot.html" rel="nofollow">this project</a>, I'm using a small piece of Python code to return an error 418 to any request. I'm interested in knowing if there is a much smaller piece of code that does the same thing.</p>
<pre><code>#Modfied from code provided by Co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-10T17:26:06.027",
"Id": "13874",
"Score": "0",
"body": "Why do you want a shorter version?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T09:42:22.263",
"Id": "13905",
"Score": "0",
"body": ... | [
{
"body": "<p>Not really <em>smaller</em> but it will respond to any request, not just GET:</p>\n\n<pre><code>class MyHandler(BaseHTTPRequestHandler):\n def handle_one_request(self):\n self.send_error(418, 'I am a Teapot')\n</code></pre>\n\n<p>Usually, <code>handle_one_request</code> delegates to the ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T08:52:33.457",
"Id": "8799",
"Score": "0",
"Tags": [
"python"
],
"Title": "Python server that only returns error 418"
} | 8799 |
<p>I want to get a map of all the fields in a class (aka value object) in a generic way. The following works fine for me:</p>
<pre><code>class Baz {
String foo = "foo2"
int bar = 2
public Map asMap() {
def map = [:] as HashMap
this.class.getDeclaredFields().each {
if (it.modifiers == java.lang.re... | [] | [
{
"body": "<p>Here's one alternative:</p>\n\n<pre><code>class Baz {\n String foo = 'foo2'\n int bar = 2\n\n public Map asMap() {\n this.class.declaredFields.findAll { it.modifiers == java.lang.reflect.Modifier.PRIVATE }.\n collectEntries { [it.name, this[it.name]] }\n }\n}\n</code></pre>\n\n<p>Basic... | {
"AcceptedAnswerId": "9353",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T09:55:14.453",
"Id": "8801",
"Score": "18",
"Tags": [
"object-oriented",
"reflection",
"groovy"
],
"Title": "Returning Groovy class fields as a map"
} | 8801 |
<p>I have a collection of radio buttons, and when I click on one, the label and text stay on the table.</p>
<p><strong>HTML - radio</strong></p>
<pre><code><div id="par01WraperAbsolute">
<div class="close"></div>
<div id="par01">
<form id=... | [] | [
{
"body": "<p>I'm not sure if this would work. If it works, it seems like a very good first improvement.</p>\n\n<p>But it would be much better to have a generic approach, rather than having to write all cases one by one.</p>\n\n<pre><code>function triggerDependency(trigger, target) {\n $(trigger).click(functio... | {
"AcceptedAnswerId": "8812",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T11:29:48.847",
"Id": "8805",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Keeping labels and text on a table"
} | 8805 |
<p>Here's my first attempt at creating a WeakAction using Expressions and Delegates. I would like it to be clear that this code was written after reading serveral blogs and taking snippets from various sources.</p>
<p>The Program class at the bottom shows a few examples of how to use it.</p>
<p>Does anyone have any p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T15:11:00.170",
"Id": "13791",
"Score": "0",
"body": "can you provide the links to blogs you sourced from?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T15:13:45.673",
"Id": "13792",
"Score":... | [
{
"body": "<p><strong>Design</strong></p>\n\n<p>Reading the code it looks to me as if there are two separate things mixed. Effectively you have two different code paths through your class - one for static method calls and one for instance method calls which do not have much in common. I'd consider to refactor t... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T13:08:39.907",
"Id": "8807",
"Score": "4",
"Tags": [
"c#",
"delegates"
],
"Title": "WeakAction Implementation"
} | 8807 |
<p>I wrote a simple program that takes the <code>enable1.txt</code> word list of scrabble/words with friends and searches it for an input. In order to search the massive list of 172,820 words I figured sorting it then using a binary search would be a good idea.</p>
<p>The sorting algorithm I used was <code>std::stable... | [] | [
{
"body": "<h3>Answer to generic questions</h3>\n<blockquote>\n<p>In order to search the massive list of 172,820 words</p>\n</blockquote>\n<p>That's relatively small (OK small->medium).</p>\n<blockquote>\n<p>I figured sorting it then using a binary search would be a good idea.</p>\n</blockquote>\n<p>Yes that... | {
"AcceptedAnswerId": "8811",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T13:17:27.830",
"Id": "8808",
"Score": "2",
"Tags": [
"c++",
"sorting"
],
"Title": "C++: Data sorting taking a long time"
} | 8808 |
<p>I'm starting to reuse this pattern, and was wondering if there was a more succinct/clear way to write it.</p>
<p>Given a function <code>foo</code> taking a callback argument:</p>
<pre><code>function foo(..., cb) { ... }
</code></pre>
<p>And function <code>bar</code> which calls <code>foo</code> with several diffe... | [] | [
{
"body": "<p>Well, first of all, your closure doesn't have to create a function. This will work just as well:</p>\n\n<pre><code>function createPromise() {\n var p = $.Deferred();\n promises.push(p);\n return p.resolve; // Doesn't create an anonymous function\n};\n</code></pre>\n\n<p>Second of all, ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T13:49:48.170",
"Id": "8809",
"Score": "6",
"Tags": [
"javascript",
"jquery",
"promise"
],
"Title": "Multiple jQuery promises"
} | 8809 |
<p>I've written a php function and some helper functions that checks for cookies when somebody lands on a page but it's not so fast. I want to know is there any way to make it faster or improve it i know it's possible to check for cookies client side using javascript but what if it is disabled also so i need a pure ser... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T03:36:56.327",
"Id": "13795",
"Score": "1",
"body": "How slow is it? How fast do you need it to be?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T03:38:45.257",
"Id": "13796",
"Score": "6",
... | [
{
"body": "<p>It could be slow from all of the location redirects. But I've never done anything like that so I can't be sure.</p>\n\n<p>Is it possible to lazily set the cookies. For instance, set a session and cookie on the first page load. And then, on the second page load check if the cookie is present.</p>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T03:35:18.100",
"Id": "8814",
"Score": "2",
"Tags": [
"php"
],
"Title": "A PHP function to check for cookies"
} | 8814 |
<p>I'm trying to create a <code>Bindable FlowLayoutPanel</code> that can take a <code>DataSource</code> and map it the specified generic parameter <code><T></code> controls. Only minimal requirements are to have a selectable index and to be able to change the background color of the selected and deselected contr... | [] | [
{
"body": "<p>Turns out I was going about this the wrong way. I updated this to use the <a href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.currencymanager.aspx\" rel=\"nofollow\"><code>CurrencyManager</code></a> class instead to manage the bindings for me. This was a much better solution.<... | {
"AcceptedAnswerId": "10621",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T16:14:55.057",
"Id": "8816",
"Score": "5",
"Tags": [
"c#",
"winforms"
],
"Title": "Binding FlowLayoutPanel"
} | 8816 |
<p>I need this kind of <code>ORDER BY</code> to list my curriculum vitae data: when <code>ep.data_termino</code> is <code>null</code> it means that the job is your current job (you can have multiple current jobs), then I must list them first. Then, I need to list all the others ordered by the <code>ep.data_termino ASC<... | [] | [
{
"body": "<p>Try:</p>\n\n<pre><code>ORDER BY ep.data_termino IS NOT NULL, ep.data_termino DESC, ep.data_inicio ASC\n</code></pre>\n\n<p>BTW,</p>\n\n<pre><code>IFNULL(ep.data_termino,NOW()) \n</code></pre>\n\n<p>is a cleaner way to express:</p>\n\n<pre><code>IF(ep.data_termino IS NULL,NOW(),ep.data_termino)\n</... | {
"AcceptedAnswerId": "8844",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T16:30:10.483",
"Id": "8817",
"Score": "1",
"Tags": [
"sql",
"mysql"
],
"Title": "Listing curriculum vitae data"
} | 8817 |
<p>I wanted to parse lines of text as tab-delimited items, and I had just been using a StringReader for something else and I came up with this:</p>
<pre><code>class TabDelimitedFieldReader : StringReader
{
private string _nextLine;
public TabDelimitedFieldReader(string s)
: base(s)
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T17:45:09.140",
"Id": "13800",
"Score": "0",
"body": "Not a bad idea. How do you use it, however? Say, I wanted to get text out of clipboard which got pasted in Excel. Then, I would want to make sure that row length is consistent - s... | [
{
"body": "<p>Conceptually, I do not see anything inherently wrong with subclassing a framework object, particularly since many of them provide <code>virtual</code>/<code>abstract</code> members specifically to allow it.</p>\n\n<p>In this case, it may be better to wrap a <code>TextReader</code> object instead o... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T17:16:23.547",
"Id": "8818",
"Score": "4",
"Tags": [
"c#",
"object-oriented",
"parsing",
"csv"
],
"Title": "Parser for tab-delimited data as a subclass of StringReader"
} | 8818 |
<p>This is really simple but I would like to improve the efficiency as it's run frequently on the client:</p>
<pre><code>function resizeSidebar() {
var h_tmp = 0;
if ($("#internal-holder").length > 0)
{ h_tmp = 250; }
else
{ h_tmp = 181; }
var h_var = $(window).height() - h_tmp;
var h... | [] | [
{
"body": "<p>If the items which you are selecting in the function are a part of the same container, you must avoid to do full lookups in DOM. Look at your html, select the parent container in which you do the manipulations, and store it's value. After that, just search for it's children for desired components.... | {
"AcceptedAnswerId": "8831",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T17:24:52.540",
"Id": "8819",
"Score": "4",
"Tags": [
"javascript",
"jquery"
],
"Title": "Resizing a sidebar"
} | 8819 |
<p>I am learning some OOP on PHP and I have developed some sample code to practise. </p>
<p>Ignoring the functionality, I just want to learn the "best" or "better" way to write OOP codes in PHP. </p>
<p>The following is my code and I hope anyone who has been doing PHP can help to review or comment for any improvement... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-10T04:59:29.223",
"Id": "13851",
"Score": "0",
"body": "Melvin the code in itself looks good. What you are doing, not so much. `Ignoring the functionality, I just want to learn the \"best\" or \"better\" way to write OOP codes in PHP` ... | [
{
"body": "<p>Just a few comments on the code as it stands so far: </p>\n\n<ol>\n<li>You're using pretty old-school file dependency management (which isn't the same as dependency management) by explicitly including things. I'd strongly suggest you look into the SPL autoload system, write an autoloader that can... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T18:15:36.843",
"Id": "8823",
"Score": "4",
"Tags": [
"php",
"object-oriented"
],
"Title": "User and Database classes in PHP"
} | 8823 |
<p>Does this snippet take too much memory? How can I let the connection opened with the function <code>connectTo</code> outside the forever loop?</p>
<pre><code>import Control.Concurrent
import Network
import System.IO
import Control.Monad
import System.Environment
main = do
[host,port]<-getArgs
let pn1 =... | [] | [
{
"body": "<p><a href=\"http://hackage.haskell.org/packages/archive/base/latest/doc/html/System-IO.html#v%3ahGetContents\" rel=\"nofollow\"><code>hGetContents</code></a> gets <em>all</em> remaining input, using lazy IO. The second call to <code>hGetContents</code> throws an error because the first call has alr... | {
"AcceptedAnswerId": "8842",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T21:28:18.367",
"Id": "8828",
"Score": "5",
"Tags": [
"haskell",
"memory-management",
"networking"
],
"Title": "Simple TCP client - memory issues"
} | 8828 |
<p>I'm wanting to create a Reusable class to work on Enumerations so that I can decorate various Enums with different attributes and I can use this class to get a particular attribute property to display.</p>
<p>An UnitTest example of how I would use the class is:</p>
<pre><code> internal enum TestEnum
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-12T03:08:13.227",
"Id": "13934",
"Score": "0",
"body": "Not having access to VS2010 at the moment, why not steal code from http://weblogs.asp.net/grantbarrington/archive/2009/01/19/enumhelper-getting-a-friendly-description-from-an-enum... | [
{
"body": "<p>I don't really see the point of XmlAttribute on a specific enumeration constant. I think that would go as a TypeConverter on the enum itself or on a property of the enum type. I can see some uses for DisplayName and Description. Unfortunately, DisplayName is not supported on Enums. The DynamicObje... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T23:39:17.200",
"Id": "8838",
"Score": "23",
"Tags": [
"c#",
"lookup"
],
"Title": "Create a re-usable class to get different values from enum attribute decorations"
} | 8838 |
<p>This is a C++ wrapper for the National Instruments ANSI C library for interfacing with NA-DAQmx devices such as the USB-6008. I wrote it for use in real-time data processing to test algorithms developed in my dissertation research.</p>
<p>I'm sure there's lots of room for improvement. Suggestions on style are wel... | [] | [
{
"body": "<p>A C header inside extern \"C\" inside a nested namespace?\nThis is a new one on me, so maybe I am missing something. \nApparent benefit of the namespace nesting:</p>\n\n<ul>\n<li>the origin of the definitions becomes apparent by the innards:: qualification in this header.</li>\n<li>a module includ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-09T23:50:26.673",
"Id": "8840",
"Score": "4",
"Tags": [
"c++"
],
"Title": "NI-DAQmx C++ wrapper code (for analog data acquisition using National Instruments measurement hardware)"
} | 8840 |
<p>I like this. Anyone want to rain on my parade here?</p>
<pre><code>public void LoadDatabasesTest()
{
string[] args = new[] { "LoadDatabases" };
ReportsService.Program_Accessor.Main(args);
With(GetModel(), m => m.Databases.ToList().ForEach(c => Console.WriteLine(c.Name)));
}
void With<T>(T ... | [] | [
{
"body": "<p>What is more clearer here?</p>\n<p>This:</p>\n<pre><code>using (Model model = GetModel())\n{\n foreach (var item in model.Databases)\n {\n Console.WriteLine(item.Name);\n }\n}\n</code></pre>\n<p>or this:</p>\n<pre><code>With(GetModel(), model =>\n model.Databases.ToList().For... | {
"AcceptedAnswerId": "8846",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-10T03:32:36.943",
"Id": "8845",
"Score": "3",
"Tags": [
"c#"
],
"Title": "Generic function With<T> to do a one-liner using block"
} | 8845 |
<p>I am writing some library code that is mostly templates and so is all contained in header files. I know that placing a using declaration in a header will pollute all the files that include it, but I'm also starting to be really annoyed by having to spell out all the namespaces..
After a bit of tinkering I came up w... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-10T05:37:42.937",
"Id": "13855",
"Score": "8",
"body": "Yes it is stupid. Stop it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-10T16:16:11.543",
"Id": "13867",
"Score": "1",
"body": "I agree... | [
{
"body": "<p>Make a private namespace to be used separately.Why are you trying to complicate things</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-10T07:00:17.003",
"Id": "8848",
"ParentId": "8847",
... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-10T05:01:21.917",
"Id": "8847",
"Score": "6",
"Tags": [
"c++",
"macros"
],
"Title": "Solving the problem of using directives in a header file with a macro. Is this stupid?"
} | 8847 |
<p>I'm currently in the process of clearing out the final parts of this question <a href="https://stackoverflow.com/questions/9192347/generics-polymorphism-interfaces-what-is-the-solution">here</a>.</p>
<p>Am I going about this the wrong way / could it be done smarter (interface perhaps) - or am I just plain silly, tr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-15T15:22:46.027",
"Id": "14115",
"Score": "0",
"body": "You spend *lots* of text describing what works, but your entire explanation of \"the problem\" is that something \"falls apart.\" That's probably why this question was closed on S... | [
{
"body": "<p>Your <code>RegisterConverters</code> functions are bad, and part of the reason is that they're not sure <em>what</em> they're registering anything for. The class methods actually receive <em>two</em> classes as arguments. The first is the obvious one in <code>aClass</code>, but then there's also <... | {
"AcceptedAnswerId": "8999",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-10T09:20:01.290",
"Id": "8850",
"Score": "2",
"Tags": [
"delphi"
],
"Title": "Is Marshalling converters/reverters via polymorphism realistic?"
} | 8850 |
<p>My JS looks like this:</p>
<pre><code>preLoadImages("/media/img/elements/frontpage/1.jpg","/media/img/elements/frontpage/2.jpg","/media/img/elements/frontpage/3.jpg","/media/img/elements/frontpage/4.jpg","/media/img/elements/frontpage/5.jpg","/media/img/elements/frontpage/6.jpg","/media/img/elements/frontpage/7.jpg... | [] | [
{
"body": "<p>perhaps you can try apply(), then you can pass in the image paths as an array:</p>\n\n<pre><code>preLoadIamges.apply(this, absoluteFileNames)\n</code></pre>\n\n<p>then you can build you array in a the way you like, perhaps looking at <a href=\"http://www.tutorialspoint.com/javascript/array_map.htm... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-10T09:32:09.623",
"Id": "8851",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Combining text in an array in JavaScript"
} | 8851 |
<p>I have a text file that uses the convention <code>#\d+</code> to mean ASCII character number <code>\d+</code>. I want to replace any such representations with the actual character. This is what I've come up with. It works but it feels kludgy. Suggestions to improve efficiency?</p>
<pre><code><?php
$line= 'stuf... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-10T18:54:04.857",
"Id": "13881",
"Score": "0",
"body": "You might want to check out the [`/e` modifier](http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php). It's usually disabled on hardened systems, though."
},
{
... | [
{
"body": "<p>Warning: The code below is intended to be compatible with the original post.\nIts main benefit is that it retains all of the useful detail discovered in the pattern match (unmatched substrings, relative position of matches), eliminating the need to rescan the line. I'd expect it to be faster for t... | {
"AcceptedAnswerId": "8986",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-10T18:35:39.033",
"Id": "8860",
"Score": "3",
"Tags": [
"php",
"performance",
"strings"
],
"Title": "Find ASCII codes and replace with characters"
} | 8860 |
<p>This code is for a problem in which I'm to find the total number of numbers that exist between A and B, of which sum of digits and sum of square of digits are prime.</p>
<p>How can I make this optimal?</p>
<pre><code>import java.util.Scanner;
public class LuckyNumbers {
static int T,ans[];
static long A,B;... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T19:21:25.503",
"Id": "13912",
"Score": "0",
"body": "You need to invest some time in profiling this code (whether by adding your own timers or by leveraging some sort of tools / frameworks / profilers. The run this (or improved) cod... | [
{
"body": "<p>Code optimization can be tricky. Make the code optimal can be something different.</p>\n\n<p>There's a lot of sub-question: Optimization, in term of speed / memory ? On which device? From a fresh start, or after a long running time ?</p>\n\n<p>But first, give variable a explicit name, because A,B,... | {
"AcceptedAnswerId": "8885",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-10T20:15:06.050",
"Id": "8863",
"Score": "2",
"Tags": [
"java",
"optimization",
"primes"
],
"Title": "Finding \"lucky numbers\""
} | 8863 |
<p>The code below has been a pet project of mine for some time. It allows simplified browsing of websites that have a predictable URL structure, namely TGP websites.</p>
<p>It has been greatly modified from it's original version to be effective on Android, and there is probably alot of room to improve on it. I'm not ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T00:33:55.817",
"Id": "13894",
"Score": "0",
"body": "Can you provide a not-NSFW url where I can pont this thing to test it? I made a [thing for it](http://jsfiddle.net/UW49J/)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [
{
"body": "<p>I will ignore the android specific parts. And i will fix/ignore the missing semicolons & unnecessary brackets </p>\n\n<p>Ok .. here it goes.</p>\n\n<ul>\n<li><p>it's 2012, please use HTML5 doctype.</p>\n\n<pre><code><!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\">\n</code></... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T00:02:37.090",
"Id": "8867",
"Score": "3",
"Tags": [
"javascript",
"html",
"android"
],
"Title": "Allowing simplified browsing of websites with a predictable URL structure"
} | 8867 |
<p>I want to put some text next to its label (both of which are text blocks - which are faster than labels as I understand it). The best way I've found for doing this is a stack panel.</p>
<p>I have (repeated 3 times in a control) code like:</p>
<pre><code> <StackPanel Grid.Column="1" Grid.Row="2" Grid.ColumnS... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2018-09-07T21:16:45.563",
"Id": "391906",
"Score": "0",
"body": "Should this be a stackoverflow question?"
}
] | [
{
"body": "<p>My opinion is that for simple tasks like in your situation, you should not complicate your XAML. Wrapping a StackPanel around two TextBlock-elements is still pretty clean.</p>\n\n<p>Extracting the code and wrapping it in your own control where you would set the Label and Content surely is an optio... | {
"AcceptedAnswerId": "21617",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T01:59:55.493",
"Id": "8869",
"Score": "4",
"Tags": [
"wpf",
"xaml",
"gui"
],
"Title": "Putting items next to each other"
} | 8869 |
<p>I just posted this code in SO and one person said my code sucked, and that I should post it here. So here it is (with fix I asked for included, so you don't have to worry about that).</p>
<p>The main concerns that I have with it myself is how I iterate through a sequence of objects that the object itself is in. App... | [] | [
{
"body": "<p>It is, as you say, slightly odd that a method in <code>Car</code> iterates over the container that <code>Car</code> is in. It really ought to be in <code>Company</code>, and take an argument for how many doors to match:</p>\n\n<pre><code>class Company:\n ...\n def searchByDoors(self, doors):... | {
"AcceptedAnswerId": "8882",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T04:53:28.637",
"Id": "8871",
"Score": "4",
"Tags": [
"python"
],
"Title": "Better way to refer to common elements in a sequence of objects?"
} | 8871 |
<p>How could this be improved style-wise (if this isn't good enough) when the need is just to have a console replacement for <code>PrintWriter.format()</code> with backwards compatibility?</p>
<pre><code>class CCConsole // not to be confused with any Java class with a similar name
{
static PrintWriter pw = new Pri... | [] | [
{
"body": "<p>I did not understand what exactly are you asking here. Anyway, I will review your code:</p>\n\n<p>First, make the fields private and provide getters when you need to access them. These that are set in constructors and are never re-setted, you may make them final.</p>\n\n<p>Second, the CCConsole cl... | {
"AcceptedAnswerId": "8888",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T05:24:28.940",
"Id": "8873",
"Score": "1",
"Tags": [
"java",
"console",
"swing"
],
"Title": "Swing / Terminal console drop-in"
} | 8873 |
<p>I would love some thoughts on this class that a wrote to extract user information from a logfile line.</p>
<p>I'm concerned about design patterns and the complexity of the code. The extract_user method feels especially awkward.</p>
<p>The class should be used as a public interface ala:</p>
<pre><code>parser = Use... | [] | [
{
"body": "<pre><code>class UserExtraction():\n</code></pre>\n\n<p>Either put <code>object</code> as an explicit base class, or don't have the parens.</p>\n\n<pre><code> def __init__(self, string):\n self.string = string\n\n def _string_identification(self):\n identifiers = {\n ... | {
"AcceptedAnswerId": "8887",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T07:52:52.263",
"Id": "8878",
"Score": "4",
"Tags": [
"python"
],
"Title": "Improve on python public interface data parser"
} | 8878 |
<p>I want to return the title of a record if one exists or the word 'invalid' if not:</p>
<pre><code> @ID int ,
@Title nvarchar(50) output
...
if exists(select * from MyTable where ID=@ID)
select @Title = (select Title from MyTable where ID=@ID);
else select @Title = 'invalid';
</code></pre>
<p>but I d... | [] | [
{
"body": "<p>Just do:</p>\n\n<pre><code>// Default value\nselect @Title = \"invalid\";\n\n// If a record is found, replace \"invalid\" by the Title value\nselect @Title = Title from MyTable where ID=@ID;\n</code></pre>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense"... | {
"AcceptedAnswerId": "8884",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T07:53:44.787",
"Id": "8879",
"Score": "4",
"Tags": [
"sql",
"sql-server",
"t-sql"
],
"Title": "Returning the title of a record"
} | 8879 |
<p>I'm looking to speed up this method. Ideally, I would like to cut the time in 1/2 or more. At the moment I have to draw the screen line-by-line as the font is 16 pixels high, but it is being drawn with an extra blank pixel on the bottom. If I could figure out how to set the line-height to 16 pixels I would imagine t... | [] | [
{
"body": "<p>You want to avoid as much work inside <code>drawRect:</code> as possible. Instead of recalculating the attributed string for each line here do it whenever <code>self.screen</code> changes. That way it's done once instead of every time the some portion of the view is redrawn (which will happen a lo... | {
"AcceptedAnswerId": "8886",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T08:09:57.640",
"Id": "8880",
"Score": "3",
"Tags": [
"performance",
"strings",
"objective-c",
"graphics"
],
"Title": "Optimizing text drawing on screen"
} | 8880 |
<p>I'm a rather novice programmer who recently came up with a solution that works for my project, however I'm always looking for ways to improve my code. </p>
<p>So essentially, I have a settings form that pop's up and I was looking for a way to put it next to my main form but not covering it nor appearing partially o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T22:40:06.723",
"Id": "13927",
"Score": "0",
"body": "@Leonid I tried to use enums but since the location of the m_parent form is *dynamic* it throws and error."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "201... | [
{
"body": "<p>My bad, I think see now what you wanted. I just did not feel like reading your logic fully (too many details). After I did read it, I saw that you got the details right. All you needed was to stick your points into a list or enumerate over them, as in this example. This way, if you feel like addin... | {
"AcceptedAnswerId": "8950",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T10:28:27.600",
"Id": "8881",
"Score": "4",
"Tags": [
"c#",
"winforms"
],
"Title": "Is there a more elegant way of arranging my forms?"
} | 8881 |
<p>Interested to hear any suggestions on object orientation and style for this simple spreadsheet implementation. The spreadsheet contains cells with equations in reverse polish notation and has a solver method to either determine the cell values or throw an exception if a circular reference exists.</p>
<pre><code>/**... | [] | [
{
"body": "<p>I did not go in great detail, but it looks pretty good.</p>\n\n<p>Just be careful with method names: <code>dump()</code> and <code>evaluateRpn()</code>. Usually abbreviations are avoided in Java.</p>\n\n<p>I don't know if you should have made cells a two-dimensional <code>List</code> of <code>List... | {
"AcceptedAnswerId": "11527",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T19:29:41.903",
"Id": "8889",
"Score": "8",
"Tags": [
"java",
"object-oriented"
],
"Title": "Spreadsheet with reverse Polish equation solving"
} | 8889 |
<p>This function is to return the size of the largest clique in a graph. When I run this code, I am running out of space at runtime. Also, it is insanely slow, so any speed tips would be appreciated.</p>
<pre><code>int cliqueSize(graph &g, std::vector<VertexID> nodes, std::vector<EdgeID> edges)
{
s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-22T21:58:50.063",
"Id": "20921",
"Score": "0",
"body": "IDK if you still care about this question, but if you do: you do know that max-clique is NP problem? So it is \"normal\" that you have problems solving it. Ofc you can improve per... | [
{
"body": "<ul>\n<li>First of all, start passing things by const reference more. You're passing both <code>nodes</code> and <code>edges</code> by value, which will make a copy.</li>\n<li>Instead of looping through the containers by index, you should use iterators.</li>\n<li>Pushing <code>tmp</code> into <code>... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T21:31:52.343",
"Id": "8893",
"Score": "4",
"Tags": [
"c++"
],
"Title": "Returning the size of the largest clique in a graph"
} | 8893 |
<p>BFS and DFS in Java. Please give suggestions!!</p>
<pre><code>Class Main {
public void bfs()
{
// BFS uses Queue data structure
Queue queue = new LinkedList();
queue.add(this.rootNode);
printNode(this.rootNode);
rootNode.visited = true;
while(!queue.isEmpty())... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T22:12:41.480",
"Id": "33935",
"Score": "0",
"body": "Can we count the distance as well?"
}
] | [
{
"body": "<p>There seem to be some inconsistencies here. What is <code>s</code>? I guess this is the stack? Also declaring a class Main is a little strange. You certainly want to have a main method, but a Main class?</p>\n\n<p>Also I'd suggest you not use raw collections e.g. replace</p>\n\n<pre><code>Queue qu... | {
"AcceptedAnswerId": "8898",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T22:57:20.543",
"Id": "8896",
"Score": "11",
"Tags": [
"java"
],
"Title": "Breadth and Depth First Search in Java"
} | 8896 |
<pre><code>int X = 1;
int Y = 0;
while (X != 99 - 1 || Y != 99 - 1)
{
Y++;
if (Y > 99 - 1)
{
X += 1;
Y = 1;
}
Layer1ID[X, Y].Update(X, Y);
Layer2ID[X, Y].Update(X, Y);
}
</code></pre>
<p>This must update a total of 19602 objects each tick. Is there any way to speed this up? T... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-12T00:33:15.563",
"Id": "13930",
"Score": "0",
"body": "Answered my own question, 1 in 60 ticks, I get a list of objects that need to be updated every tick, and update that list of objects."
},
{
"ContentLicense": "CC BY-SA 3.0... | [
{
"body": "<p>While not answering your question, I would like to point out problems with your loop conditions.</p>\n\n<p>First, the condition <code>X != 99 - 1</code> looks strange. It is the same as <code>X < 98</code> in this context. The same holds for <code>Y</code>. Since <code>Y < 98</code>, if you ... | {
"AcceptedAnswerId": "8900",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-11T23:35:01.860",
"Id": "8899",
"Score": "3",
"Tags": [
"c#",
".net",
"multithreading"
],
"Title": "Quickly updating a mass of objects"
} | 8899 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.