body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
JavaScript is primarily a language focused on web development. Being a monopoly on the front end and having Node on the back end. Use this tag for questions regarding vanilla JavaScript; optionally tagged with an ECMAScript version. If you are using a preprocessor such as TypeScript please tag with that too. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2011-05-20T14:35:58.953",
"Id": "2515",
"Score": "0",
"Tags": null,
"Title": null
} | 2515 |
<p>I have written a recursive function that I believe will return the 'maximum' row of the 4x4 matrix it is fed. By 'maximum' I mean that the maximum row of the matrix.</p>
<pre><code>1 2 3 4
2 3 4 1
3 4 1 2
4 1 2 3
</code></pre>
<p>is row 4 (on account of the first column's values); the maximum row of the matrix</p>... | [] | [
{
"body": "<p>You could use strcmp(char*, char*) to compare two strings. If you convert the matrix rows to the equivalent characters, then the strcmp() will do the hard work for you. </p>\n\n<pre><code>int isFirstGreater = strcmp(\"1234\", \"1232\");\n</code></pre>\n\n<p>This will return 1 to say that the first... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-21T06:36:32.983",
"Id": "2523",
"Score": "5",
"Tags": [
"c",
"matrix"
],
"Title": "Finding the maximum row of a 4x4 matrix"
} | 2523 |
<p>I just want to see if any part of one "rectangle" overlaps the other.
Is this the correct code?</p>
<pre><code> bool checkCollide(int x, int y, int oWidth, int oHeight, int x2, int y2, int o2Width, int o2Height){
bool collide;
collide = false;
if(x >= x2 && x <= x2+o2Width && y &g... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-21T15:42:22.710",
"Id": "4006",
"Score": "0",
"body": "Is it meant to work for x and y less than zero also?"
}
] | [
{
"body": "<p>No, this is not correct; it only verifies whether the vertices of one rectangle are inside the other, not the other way around. Try calling it with the following parameters:</p>\n\n<pre><code>checkCollide(2,2,4,4, 1,3,2,2);\ncheckCollide(1,3,2,2, 2,2,4,4);\n</code></pre>\n\n<p>They should print th... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-21T15:27:33.573",
"Id": "2533",
"Score": "4",
"Tags": [
"c++"
],
"Title": "Does my Rectangle intersect code work?"
} | 2533 |
<p>This is a plug-in which tracks your online activity aka a lifestream. You're currently able to use feeds like:</p>
<ul>
<li>Delicious</li>
<li>Flickr</li>
<li>Github</li>
<li>Google Reader</li>
<li>Last.fm</li>
<li>Stackoverflow</li>
<li>Twitter</li>
<li>Youtube</li>
</ul>
<p>At first I decided to load all the fee... | [] | [
{
"body": "<blockquote>\n <p>At first I decided to load all the feeds at the end of all the asynchronous requests. This only required one DOM request at the end. The problem with that approach is that it just takes too long to load. Some requests timed-out and others just took a while.</p>\n</blockquote>\n\n<p... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-21T17:52:11.107",
"Id": "2535",
"Score": "7",
"Tags": [
"javascript",
"jquery",
"ajax",
"performance"
],
"Title": "jQuery Lifestream Plug-in"
} | 2535 |
<p>I am a Java dev and trying to prepare for interviews in C++. Can someone please review the below solution for me?</p>
<blockquote>
<p>Assume that you are given the head and tail pointers of a doubly linked list where each node can also have a single child pointer to another similar doubly linked list. There are n... | [] | [
{
"body": "<p>You could write this code in Java first, it would not be much different from a C++ implementation. It seems that your problem is not the language, but rather the algorithm: E.g. you only update the next pointer, not the prev pointer. The following must be true for every link between two nodes: nod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-21T18:04:27.837",
"Id": "2536",
"Score": "6",
"Tags": [
"c++",
"algorithm",
"linked-list",
"interview-questions"
],
"Title": "Flattening a doubly linked list"
} | 2536 |
<p>Please suggest improvements in the following java program I've written for producer-consumer scenario. The program seems to be working fine. Does it suffer from possible deadlock scenarios? How better I could have done this? Since I am using Stack read/write (push/pop) already been synchronized? What if they do not?... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-20T13:07:44.620",
"Id": "4007",
"Score": "4",
"body": "I wouldn't use a Stack for Producer/Consumer. I would just use a Queue or even better an ExecutorService."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-... | [
{
"body": "<p>Your program is not thread-safe.</p>\n\n<p>For example, if two threads invoke <code>addToBuffer(Integer i)</code> at the <em>same</em> time, both can pass the <code>if(buffer.size() < MAX_SIZE)</code> check before one of them puts an item into the stack, therefore the stack can have more items ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-20T13:04:19.673",
"Id": "2538",
"Score": "5",
"Tags": [
"java"
],
"Title": "Producer Consumer scenario implementation in Java"
} | 2538 |
<p>Consider the following two code examples:</p>
<p><strong>1.</strong></p>
<pre><code>void foo(boolean cake) {
if (!cake)
return;
// TODO some work.
}
</code></pre>
<p><br/></p>
<p><strong>2.</strong></p>
<pre><code>void bar(boolean cake) {
if (cake)
//TODO some work.
}
</code></pre>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-03-24T02:11:48.803",
"Id": "37462",
"Score": "0",
"body": "Related: http://stackoverflow.com/questions/4887212/shall-i-use-guard-clause-and-try-to-avoid-else-clause"
}
] | [
{
"body": "<p>Usually you get the advice to avoid multiple exit points in a method. However the reasoning behind this rule is only valid if you have <strong>long</strong> methods - and then you have more to worry about than exit points.</p>\n\n<p>Make your methods <strong>short</strong>, then make them even <st... | {
"AcceptedAnswerId": "2542",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-21T21:37:10.963",
"Id": "2541",
"Score": "14",
"Tags": [
"java"
],
"Title": "Return explicitly or implicitly?"
} | 2541 |
<p>I'm making a simple text game using the pdCurses library and a few other minor things like a vertical scroller in which you avoid the randomly-generated walls.</p>
<p>There are two walls on left and right made out of 'X' characters and blank, black space in which you can move around and avoid the 'X's your characte... | [] | [
{
"body": "<pre><code>#include <iostream>\n#include <time.h> // or \"ctime\"\n#include <stdio.h> // for \n</code></pre>\n\n<p>Its best to avoid useless noise comments which contribute nothing</p>\n\n<pre><code>#include <cstdlib> \n// Windows stuff\n#include <Windows.h> // GOD DAMMN... | {
"AcceptedAnswerId": "2552",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-22T04:50:05.700",
"Id": "2546",
"Score": "4",
"Tags": [
"c++",
"performance",
"game",
"windows",
"curses"
],
"Title": "Text-based vertical scroller game"
} | 2546 |
<p>I need automatic dependency generation to be done in my <code>makefile</code>. So, I have tried to write one, after googling for similar ones. I have found some ways to do that, but the problem is that they are usually too complicated for me (because of usage of <code>sed</code> command etc. and I want a way for me ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-22T12:01:11.370",
"Id": "4011",
"Score": "5",
"body": "You may want to investigate the `-MP` option. \"This option instructs CPP to add a phony target for each dependency other than the main file, causing each to depend on nothing. Th... | [
{
"body": "<p>That will likely generate deps all the time, even if your target is 'clean'.\nPut the dep targets and includes in an ifeq block which checks the makefile target, then there wont be any dependency generation prior to cleaning (since those files should be removed by the clean, it is a waste to gener... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-22T10:07:24.577",
"Id": "2547",
"Score": "20",
"Tags": [
"c++",
"makefile"
],
"Title": "makefile dependency generation"
} | 2547 |
Erlang is a general-purpose programming language and runtime environment. It has built-in support for concurrency, distribution and fault tolerance. Erlang is used in several large telecommunication systems from Ericsson. Erlang is open source and available for download on GitHub. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-22T18:22:39.987",
"Id": "2550",
"Score": "0",
"Tags": null,
"Title": null
} | 2550 |
<p>This is a revisit to a <a href="https://stackoverflow.com/questions/1995418/python-generator-expression-vs-yield">question</a> already asked here about a year and a half ago. </p>
<p>Project Euler's <a href="http://projecteuler.net/index.php?section=problems&id=40" rel="nofollow noreferrer">Problem 40</a> invol... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-23T02:45:12.567",
"Id": "4031",
"Score": "4",
"body": "I think generator expressions are only useful when they are simple enough that they don't need explanation and you can use them inline in whatever your code is doing. The moment yo... | [
{
"body": "<p>The one where you return a generator is easier to read were it the case that there was only one <code>for</code>. Also, as OP pointed out, the associativity of nested for loops is not what you'd expect in Python.</p>\n\n<p>The top one may be slightly easier to read for some people; it would be MUC... | {
"AcceptedAnswerId": "2554",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-22T15:19:31.103",
"Id": "2553",
"Score": "11",
"Tags": [
"python",
"python-3.x",
"comparative-review",
"generator"
],
"Title": "Generating the sequence of the digits that appea... | 2553 |
<p>I'm fetching a string that is JSONP, and looking to convert it to JSON. </p>
<p>I'm using the following regular expression for matching (for removal) the padding on the JSON. </p>
<pre><code>([a-zA-Z_0-9\.]*\()|(\);?$)
</code></pre>
<p>In python, here's the line I'm using for converting the JSONP to JSON:</p>
<p... | [] | [
{
"body": "<p>The problem with the code is that it doesn't really express what you are trying to do:</p>\n\n<pre><code>apijson = re.sub(r'([a-zA-Z_0-9\\.]*\\()|(\\);?$)','',jsonp)\n</code></pre>\n\n<p>The code would seem to indicate that you are trying to find and replace many instances of some regular expressi... | {
"AcceptedAnswerId": "2562",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-23T00:30:33.330",
"Id": "2561",
"Score": "6",
"Tags": [
"python",
"json",
"regex"
],
"Title": "Converting JSONP to JSON: Is this Regex correct?"
} | 2561 |
<p>I'm pretty new to C so I decided to implement <a href="http://srfi.schemers.org/srfi-1/srfi-1.html" rel="nofollow">SRFI-1</a> (linked-list library) to help me learn.</p>
<p>What I have so far is working, but only handles integers.</p>
<pre><code>typedef struct pair {
int car;
struct pair *cdr;
} pair;
</code><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-23T02:46:49.057",
"Id": "4032",
"Score": "0",
"body": "This depends on what your goal is. Do you want to produce a linked list library that will be useful to users in C? Or do you want to produce something in the spirit of the SRFI-1? ... | [
{
"body": "<p>void* is the standard to implement such generics in C. The trouble with union is that the end-user cannot put their own types/structs in it. With void * a pointer to a user-defined struct can be used. However, be careful about memory leaks!</p>\n\n<p>The warnings you are getting is because you hav... | {
"AcceptedAnswerId": "2571",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-23T01:45:39.330",
"Id": "2564",
"Score": "5",
"Tags": [
"c"
],
"Title": "Generic linked-list library in C"
} | 2564 |
<p>I hate this code. What is the slickest way to write the following:</p>
<pre><code>MyFile = f;
SaveFolder = Server.MapPath("\\") + "returns\\";
if(!System.IO.Directory.Exists(SaveFolder) )
{
System.IO.Directory.CreateDirectory(SaveFolder);
}
MyFile.SaveAs(SaveFolder + "2011" + "000-00-0000" + ".xlsx");
</code><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-23T21:43:15.930",
"Id": "4053",
"Score": "4",
"body": "What exactly do you hate about this code? Are you looking for a 1-line version of it?"
}
] | [
{
"body": "<p>well, for starters, use Path.Combine... eg :-</p>\n\n<pre><code>SaveFolder = Path.Combine(Server.MapPath(@\"\\\"),\"returns\");\n</code></pre>\n\n<p>same kind of thing for building your file name.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "... | {
"AcceptedAnswerId": "2580",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2011-05-23T19:36:01.967",
"Id": "2573",
"Score": "4",
"Tags": [
"c#",
"strings",
"file-system"
],
"Title": "Streamline code for checking if a directory exists and saving a file"
} | 2573 |
<p>I'd really appreciate some harsh/constructive criticism of what I would consider as my first program in Haskell. The program should download all of the xkcd comics into a folder in the current directory.</p>
<p>I basically just threw the kitchen sink at it, using anything I found remotely interesting in RWH and on... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-23T04:04:59.947",
"Id": "4047",
"Score": "0",
"body": "simpleHttpE seems to be converting Either to an IO Exception, right after tryRequest converts the IO exception to Either. Is this not redundant?"
},
{
"ContentLicense": "CC... | [
{
"body": "<p>Looks pretty good. You're getting on top of stuff nicely. Some criticism:</p>\n\n<ul>\n<li>don't use package imports</li>\n<li>write type signatures for top level functions</li>\n<li>write comments!</li>\n<li>thread design looks good.</li>\n<li>don't use <code>if'</code>. Haskell has <code>if</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-23T01:58:32.413",
"Id": "2574",
"Score": "16",
"Tags": [
"haskell",
"json",
"http",
"web-scraping"
],
"Title": "Simple xkcd comic downloader"
} | 2574 |
<p>I'm looking for any comments or feedback on my database access class. Security and speed are two things I'm most concerned about.</p>
<p>One thing to note is this class has to work in a C# .NET 2 environment, so anything that's more modern would be interesting to me, but please note in the title of your answer if t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-24T09:40:53.533",
"Id": "4062",
"Score": "0",
"body": "In your summary, _\"neads\"_ should be _\"needs\"_ and _\"refering\"_ should be _\"referring\"_. ;p"
}
] | [
{
"body": "<p>A few quick ideas:</p>\n\n<ul>\n<li>Check spelling.</li>\n<li>Use <code>string.Empty</code> instead of \"\" for improved readability and performance.</li>\n<li>Always use visibility modifiers - For example your fields lack the typical \"private\" keyword. Example <code>private static Database data... | {
"AcceptedAnswerId": "2587",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-23T23:56:41.860",
"Id": "2578",
"Score": "6",
"Tags": [
"c#",
"sql",
".net",
"asp.net",
".net-2.0"
],
"Title": "Database access class"
} | 2578 |
<p>I am new to the world of coding as well as CSS. This is my first attempt to put together what I would consider a fully-pledged page less the content. I would appreciate if you could poke holes at it and let me know what I could have done better as well as what I should consider doing in the future. </p>
<p><strong>... | [] | [
{
"body": "<p>1- even for testing you should put the css in an external file, especially when it starts to have many lines.</p>\n\n<p>2- relative will position an element relatively to its parent. So you need to ask yourself what is the \"container\", parent of this element.\n<a href=\"http://www.w3schools.com/... | {
"AcceptedAnswerId": "2584",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-24T00:03:26.190",
"Id": "2579",
"Score": "2",
"Tags": [
"html",
"css"
],
"Title": "CSS Page Example Code Review"
} | 2579 |
<p>I've made a simple wrapper for <code>MySQLi_STMT</code>, allowing the usage of placeholders and spares you the need to manually bind variables. The full code is at the bottom of this question (it's quite large, with comments). Please give me feedback/criticisms on anything you want (readability and API design for st... | [] | [
{
"body": "<p><strong>Before reading the actually implementation:</strong></p>\n\n<p>What you doing is a <code>pdo</code>-like placeholder syntax with a <code>#</code> instead of a <code>:</code> and without the need to bind the parameters directly but only pass in a array.</p>\n\n<p>I can see the 'need' for so... | {
"AcceptedAnswerId": "2586",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-24T09:12:15.983",
"Id": "2583",
"Score": "2",
"Tags": [
"php",
"mysql",
"mysqli"
],
"Title": "MySQLi_STMT wrapper, allows placeholders"
} | 2583 |
<p>I am trying to create a web app (CMS) as part of my research project, and I use the code below to load modules into a page. Please review this code.</p>
<pre><code>public function LoadModule($module,$position){
if(file_exists('modules/'.$module.'.tpl'))
{
//todo: might have to get a better thing f... | [] | [
{
"body": "<p>I don't know if it's a paste-issue, but you should intent your code ;)</p>\n\n<p>You are building the file-path twice. You should move that line:</p>\n\n<pre><code>$mod = 'modules/'.$module.'.tpl';\n</code></pre>\n\n<p>To the begining of the function (and give it a better name):</p>\n\n<pre><code>... | {
"AcceptedAnswerId": "2589",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-24T13:09:14.573",
"Id": "2585",
"Score": "1",
"Tags": [
"php",
"php5"
],
"Title": "Loading module to a templated page"
} | 2585 |
<p>I've been learning to program in Java and I decided to implement a doubly linked list as practice and as a bridge project before going on to learn C++. I know Java includes a <code>LinkedList</code> implementation, but I wrote this for practice. I have finished the code and it works correctly. However, I'd appreciat... | [] | [
{
"body": "<p>Firstly, MyNode isn't going to be used by any class outside of MyLinkedList. It would be better if you implemented it as a private class inside the same file as MyLinkedList. Its only purpose is as data storage for MyLinkedList, its not really an object in its own right.</p>\n\n<p>As part of that,... | {
"AcceptedAnswerId": "2593",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-24T14:44:57.623",
"Id": "2588",
"Score": "10",
"Tags": [
"java",
"linked-list"
],
"Title": "Remake of Java's doubly LinkedList"
} | 2588 |
<p>Wondering if I could do this a little bit better. Currently, my DAL has a blank constructor that sets the connection string from the web.config.</p>
<pre><code>private string cnnString;
public DAL()
{
cnnString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString;
}
</code></pre>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-26T08:16:09.187",
"Id": "4117",
"Score": "0",
"body": "What language is this? Can you add a tag so it's obvious to people browsing the site?"
}
] | [
{
"body": "<p>You could move your try / catch / return logic to a private method that takes an SqlCommand as a parameter.</p>\n\n<p>Also, since you are only using your finally block to close the connection, you might consider a using block instead: </p>\n\n<pre><code>private bool runSpCommand (SqlCommand comman... | {
"AcceptedAnswerId": "2613",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-24T15:41:15.577",
"Id": "2590",
"Score": "5",
"Tags": [
"c#"
],
"Title": "Data Access Layer Code"
} | 2590 |
<p><strong>Overview</strong></p>
<p>I've written a class that will create C# code. The output is a single .cs file for each table in the default database (the database is defined inside a web.config file). I'm looking for a code review on this class alone, <em>not</em> on the generated code. This <code>DatabaseClassCr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T14:50:56.110",
"Id": "71597",
"Score": "0",
"body": "You probably want to be using T4 for this. http://msdn.microsoft.com/en-us/library/bb126445.aspx is a reasonable place to start."
}
] | [
{
"body": "<p><strong>1)</strong> As already mentioned <strong>T4</strong> might be a better solution though I'm not sure whether it is available for earlier VS versions. </p>\n\n<p><strong>2)</strong> I would avoid using <code>string OutputPath</code> parameters, <code>Streams</code> are usually more handy. ... | {
"AcceptedAnswerId": "2614",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-24T23:42:18.570",
"Id": "2595",
"Score": "9",
"Tags": [
"c#",
"sql",
".net",
"asp.net",
".net-2.0"
],
"Title": "Database Class Creator"
} | 2595 |
<p>Haskell is a purely functional programming language with strict static type checking and lazy evaluation. The combination of functional programming and static type checking allows rapid development of bug free and correct programs. The absence of side effects allows Haskell programs to be parallelized more easily th... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T04:05:14.110",
"Id": "2597",
"Score": "0",
"Tags": null,
"Title": null
} | 2597 |
Haskell is a purely functional programming language, featuring static typing, lazy evaluation, and monadic effects. The primary implementation is GHC, a high-performance compiler with a runtime supporting many forms of parallelism and concurrency. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T04:05:14.110",
"Id": "2598",
"Score": "1",
"Tags": null,
"Title": null
} | 2598 |
<p>I have two tables, one for jobs, and one for the names of industries (e.g. automotive, IT, etc).</p>
<p>In SQL I would just do:</p>
<pre><code>SELECT industryName, count(*)
FROM jobs
JOIN industry
ON jobs.industryId = industry.id
GROUP BY industryName
</code></pre>
<p>In LINQ I have the following, but it's three ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T10:16:45.540",
"Id": "4089",
"Score": "0",
"body": "R u using Entity Framework to Linq to SQL?"
}
] | [
{
"body": "<p>Your <code>j</code> and <code>i</code> variables are pretty plain and won't make this code fun to maintain (especially if it were a big block of code) </p>\n\n<p>You should use more descriptive variables.</p>\n\n<p>you should create a collection that groups the Jobs by their Industry and then sel... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T05:01:46.870",
"Id": "2599",
"Score": "20",
"Tags": [
"c#",
"linq"
],
"Title": "LINQ to SQL Joining Entities"
} | 2599 |
<p>I am trying to create some (I believe these are Integration not Unit) tests for code that interacts with a database and I am not sure this is the right approach.</p>
<p>I would appreciate any reviews and possible improvements.</p>
<p>Using: <strong>VS2010 Unit Testing Framework</strong></p>
<p>This is the functio... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-29T13:36:07.550",
"Id": "18150",
"Score": "0",
"body": "Integration tests are a scam ...\nvideo => http://www.infoq.com/presentations/integration-tests-scam\ntext => http://www.infoq.com/news/2009/04/jbrains-integration-test-scam"
}
... | [
{
"body": "<p>I don't claim to be an expert, but here's my experience.</p>\n\n<p>Apart from that i see you are using a constant string <em>\"MyProviderName\"</em> in your code and you would do well to move that to a const string for easy refactoring and future changes.</p>\n\n<p>Also i suggest you use the more ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T09:40:36.943",
"Id": "2601",
"Score": "6",
"Tags": [
"c#",
".net",
"unit-testing"
],
"Title": "Unit (Integration) Test for code that interacts with a database"
} | 2601 |
<p>I have a database that I need to query over and over as fast as possible. My queries execute pretty quickly, but there seems to be some additional lag. I have a feeling that this lag is due to the fact that I am initiating and de-initiating a connection the connection each time. Is there a way to avoid this?</p>
<p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-27T09:54:33.327",
"Id": "4154",
"Score": "1",
"body": "I don't know Pascal but it's for sure the best to keep the connection open, especially if you have many queries to execute. It adds much overhead to one query."
}
] | [
{
"body": "<p>The most important thing here is not to create and destroy the connection as part of executing your query. Force the calling code to create the connection first (or create it yourself if its not done) but dont destroy the connection until the library is unloaded. That should improve speed.</p>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T12:55:18.253",
"Id": "2604",
"Score": "6",
"Tags": [
"mysql",
"pascal"
],
"Title": "Querying MySQL from an external application"
} | 2604 |
<pre><code>long long combine(unsigned int high, unsigned int low) {
return ((unsigned long long) high) << 32 || low;
}
</code></pre>
<ol>
<li>Is there a better name for the operation?</li>
<li>Is the implicit cast from <code>unsigned long long</code> to <code>long long</code> a <code>reinterpret_cast</code>,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T18:15:20.607",
"Id": "4097",
"Score": "6",
"body": "Also, note that you should be using a bitwise or operator `|` rather than a logical or operator `||`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-2... | [
{
"body": "<p>You should return <code>unsigned long long</code> and let the user decide what they want to do with the cast, especially if you want this to be generic.</p>\n\n<p>I'd prefer a name such as <code>u32tou64</code>, <code>uinttoull</code>, or something more descriptive than combine. A lot of this wil... | {
"AcceptedAnswerId": "2608",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T16:24:31.347",
"Id": "2607",
"Score": "8",
"Tags": [
"c++",
"integer",
"bitwise"
],
"Title": "Combining two 32-bit integers into one 64-bit integer"
} | 2607 |
<p>I have a JSON object which holds some json_array like this: (with org.codehaus.jettison.json.*)</p>
<pre><code>json array:[{"C1":["S1","S2"]},{"C2":["S1","S2"]},{"C3":["S1","S2"]},{"C4":["S1","S2"]}]
</code></pre>
<p>I have to get two list,one for keys,another for the elements of each key.I have done like this:</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-26T10:19:46.057",
"Id": "4124",
"Score": "0",
"body": "Looks fine to me. The only thing I'd suggest is to move the declaration of the variable `key` into the loop: `String key = b.names().getString(0);`"
}
] | [
{
"body": "<p>This can be argued, but I think you can write directly <code>i < array.length();</code> without noticeable slowdown (if length() does the right thing and is just a getter of a field). Makes the loop slightly more readable, IMHO. Or at least add spaces: <code>int i = 0, length = array.length();<... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T19:10:31.110",
"Id": "2609",
"Score": "5",
"Tags": [
"java",
"json"
],
"Title": "Is there another way / proper way of parsing this JSON array ?"
} | 2609 |
<p>I'm writing a file I/O DLL in C++ which is going to be used from VB6. The interface is already fixed, and uses INT64/Currency as the general integer data type.</p>
<p>Now I have this function:</p>
<pre><code>extern "C" LPWIN32_FIND_DATAW ZFILEIO_API GetFileInfoByIndex(INT64 index) {
return total_size >= 0
... | [] | [
{
"body": "<pre><code>#pragma warning(disable:4xxx)\nyourcode();\n#pragma warning(default:4xxx)\n</code></pre>\n\n<p>Where 4xxx is the warning code. </p>\n\n<p>Have a look at the <a href=\"http://msdn.microsoft.com/en-us/library/2c8f766e%28v=vs.80%29.aspx\" rel=\"noreferrer\">msdn article</a></p>\n",
"comme... | {
"AcceptedAnswerId": "2622",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T19:53:37.683",
"Id": "2610",
"Score": "6",
"Tags": [
"c++",
"integer",
"vb6"
],
"Title": "Avoiding the 'possible loss of data' compiler warning"
} | 2610 |
<p>I'm trying to optimize a simple Euclidian distance function in C. It's for a DLL, and calculates distances from one point to many. I have:</p>
<p>Version 1:</p>
<pre><code>int CalcDistance (int y1, int x1, int *y2, int *x2, int nb , int *distances)
{
double dx,dy = 0;
for (int i = 0;i<nb;i++)
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-26T01:01:55.853",
"Id": "4111",
"Score": "0",
"body": "what kind of size is nb typically?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-26T08:24:17.167",
"Id": "4119",
"Score": "0",
"body": "W... | [
{
"body": "<pre><code>dstances[i]=(int)sqrt((dx*dx)+(dy*dy));\n</code></pre>\n\n<p>This only converts to double once. it will do all the math integer style and and then convert it to a double just before calling sqrt.</p>\n\n<pre><code> distances[i]=(int)sqrt((double)(dx*dx)+(dy*dy));\n</code></pre>\n\n<p>Th... | {
"AcceptedAnswerId": "2620",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T21:49:30.010",
"Id": "2615",
"Score": "4",
"Tags": [
"performance",
"c",
"casting"
],
"Title": "Euclidian distance - optimization and casting"
} | 2615 |
<p>F# is a succinct, expressive, and efficient functional and object-oriented language for .NET, which helps you write simple code to solve complex problems. It is a descendant from the <a href="https://en.wikipedia.org/wiki/ML_(programming_language)" rel="nofollow">ML family</a> of programming languages.</p>
<p>For m... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T21:55:00.947",
"Id": "2616",
"Score": "0",
"Tags": null,
"Title": null
} | 2616 |
F# is a succinct, expressive, and efficient functional and object-oriented language for .NET | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-25T21:55:00.947",
"Id": "2617",
"Score": "0",
"Tags": null,
"Title": null
} | 2617 |
<p>I have 3 questions, all of them are concerned with binary coded decimal (BCD) conversion. My coding snippets are listed as follows. But I don't like my algorithm because it takes too long when dealing with tons of data.</p>
<p>Any suggestions to improve the performance? Would you please show me an efficient and fas... | [] | [
{
"body": "<p>You can avoid pow by doing something like this:</p>\n\n<pre><code>unsigned int BCDn( unsigned int n, const unsigned char * data )\n{\n unsigned int uResult = 0;\n unsigned char ucTmp;\n int iTmp1,iTmp2;\n\n unsigned int factor = 1;\n for (unsigned int i=n-1;i>=0;i--)\n {\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-26T09:44:53.647",
"Id": "2623",
"Score": "5",
"Tags": [
"c++",
"optimization",
"performance",
"converting",
"bitwise"
],
"Title": "Decoding binary coded decimal (BCD) value"
... | 2623 |
<p>I'm new to coding, and especially to OOP PHP. I'll highly appreciate if you expert programmers could review following code and give me your opinion to make it better. Also, how you see this code, is it too horrible and ugly?</p>
<pre><code><?php
include_once("config.inc.php");
class user{
var $mysqli;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-28T07:22:12.253",
"Id": "4186",
"Score": "3",
"body": "This isn't enough for a full answer, but I'd recommend not adding `?>` to the end of files like this. If there is any extra whitespace after the closing PHP tag, it will be output ... | [
{
"body": "<p>Why not use the built-in PHP e-mail validation?</p>\n\n<pre><code>filter_var($email, FILTER_VALIDATE_EMAIL)\n</code></pre>\n\n<p>Why do</p>\n\n<pre><code>if (lol())\n return true;\nelse\n return false;\n</code></pre>\n\n<p>when you can do</p>\n\n<pre><code>return lol();\n</code></pre>\n\n<p>Same... | {
"AcceptedAnswerId": "2626",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-26T11:06:16.633",
"Id": "2624",
"Score": "5",
"Tags": [
"php",
"beginner",
"validation"
],
"Title": "Validating username fields and showing CAPTCHA"
} | 2624 |
<p>The Demo for what I have made is located <a href="http://jsfiddle.net/maniator/pajsR/145/" rel="nofollow noreferrer">here</a></p>
<p>Basically I am trying to make a self playing JavaScript baseball game with the use of no libraries.</p>
<p>Is there anything I could improve on in the code?</p>
<pre><code>var write... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-26T17:32:18.883",
"Id": "4135",
"Score": "2",
"body": "I'm strangely conflicted, the architect in me wants to say choosing to use zero frameworks is reinventing the wheel to the max and you don't get to leverage a hammer that's gone th... | [
{
"body": "<pre><code>var writeDown = {\n delay: 110,\n add: null,\n div: document.getElementById('playArea'),\n log: function() {\n var args = arguments;\n if (args.length == 0) {\n args = [''];\n }\n var div = this.div;\n setTimeout(function() {\n ... | {
"AcceptedAnswerId": "2637",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2011-05-26T15:51:19.963",
"Id": "2631",
"Score": "27",
"Tags": [
"javascript",
"game",
"dom"
],
"Title": "Self-playing Baseball game"
} | 2631 |
<p>I am new to the world of coding as well as CSS. This is my first attempt to put together a page that required a negative value. I am aware that it is recommended that paddings do not use negative values and it is acceptable for margins to use negative values however am unsure if my use of negative values is acceptab... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-26T21:05:41.333",
"Id": "4143",
"Score": "0",
"body": "http://jsbin.com/ufuze3/"
}
] | [
{
"body": "<p>Your use of negative values in this example is perfectly acceptable; you're locating a <code>relative</code> positioned element.</p>\n\n<p>You could improve the structure of the page with the addition of headers (e.g. change <code><div id=\"logo\">logo</div></code> to <code><h1>l... | {
"AcceptedAnswerId": "2648",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-26T18:26:21.780",
"Id": "2633",
"Score": "6",
"Tags": [
"html",
"css"
],
"Title": "CSS with negative values"
} | 2633 |
<p>This is a Perl program intended for my chemistry class. Since I am just learning to write in Perl, which is my first language, can you tell me if you think that this is well written? If not, could you tell me what is wrong with it or what could be improved?</p>
<pre><code>## Name:Titration
## Beginning of Program
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-26T23:37:53.773",
"Id": "4144",
"Score": "2",
"body": "Why are you dividing by one? Also, you don't need to clear the screen before and after calculating the answer because you don't output anything there."
},
{
"ContentLicense... | [
{
"body": "<p>One suggestion, use</p>\n\n<p><code>use warnings;</code></p>\n\n<p><code>use strict;</code></p>\n\n<p>Will force you to be a better perl programmer, by enforcing more rigidity to your scripts, and have the intepreter catch any nasty issues that might be otherwise hard to debug.</p>\n",
"commen... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-26T23:34:18.737",
"Id": "2638",
"Score": "14",
"Tags": [
"beginner",
"perl"
],
"Title": "Chemistry titration calculator"
} | 2638 |
<p>I am implementing RSA in java using BigInteger and I have a method to return a random relative prime number based on the modulus m. </p>
<p>The method looks like this:</p>
<pre><code>BigInteger prime = new BigInteger(m.bitLength(),rnd);
while (prime.compareTo(BigInteger.ZERO) <= 0 || !prime.gcd(m).equals(B... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-27T15:24:34.547",
"Id": "4166",
"Score": "0",
"body": "At least you can rewrite it as a do ... while loop. Could you be more precise about efficiency? What concrete problems do you have?"
}
] | [
{
"body": "<p>What is m.bitLength, and how often do you get a <= 0 or an gcd-1? </p>\n\n<p>Why do you think creating an object in the loop could be bad? Performance? Memory wise? </p>\n\n<p>An object is ready for garbage collection as soon as it is unreachable and out of scope. </p>\n\n<p>So the second objec... | {
"AcceptedAnswerId": "2642",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-27T01:45:46.960",
"Id": "2641",
"Score": "4",
"Tags": [
"java",
"performance",
"primes",
"cryptography"
],
"Title": "A random relative prime number based on the modulus"
} | 2641 |
<p>I would love some feedback on this little utility function:</p>
<pre><code>/**
* Copy $src to $dest, renaming it if the desired destination already exists. The
* string '.versionX' is inserted before the file extension if a file must be
* renamed, with X incremented as needed.
*
* @return boolean true if copy... | [] | [
{
"body": "<p><strong>Original Answer:</strong></p>\n\n<p>I'd put in some extra brackets in your while-loop for radability:</p>\n\n<pre><code>while ( file_exists($new_name) \n && (sha1_file($src) != sha1_file($new_name))\n );\n</code></pre>\n\n<p>And you shouldn't set file-permissions to <co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-27T04:42:44.190",
"Id": "2647",
"Score": "4",
"Tags": [
"php"
],
"Title": "Copy a file, renaming it if the destination already exists."
} | 2647 |
<blockquote>
<p><strong><em>There's a follow-up:</strong> <a href="https://codereview.stackexchange.com/questions/3197/waiting-for-a-lock-to-release-with-manualresetevent-and-quartz">Waiting for a lock to release with ManualResetEvent and Quartz.</a></em></p>
</blockquote>
<p>I've written a simple Lock-Mechanism whi... | [] | [
{
"body": "<p>The function might block up to one second too long (if the lock is released, just after it enters Sleep).</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-27T10:26:47.297",
"Id": "4155",
"Score": "0",
"body": "This... | {
"AcceptedAnswerId": "2657",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-27T08:08:14.483",
"Id": "2650",
"Score": "11",
"Tags": [
"c#",
"locking"
],
"Title": "Waiting for a lock to release with Thread.Sleep()?"
} | 2650 |
<p>I'm wondering if I could handle the following situation with a single function or regex call. Given the folowing input:</p>
<pre><code>Some text
> Foo
> Bar
>> Baz
> Foo
</code></pre>
<p>The output should be:</p>
<pre><code>Some text
<blockquote>
Foo
Bar
<blockquote>
Baz
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-30T03:35:45.920",
"Id": "4212",
"Score": "0",
"body": "Don't know if it's of any help, but Markdown does this; however, only with a newline after the inner quote."
}
] | [
{
"body": "<p>This isn't much more elegant, but maybe you like it:</p>\n\n<pre><code>$text = \"Some text\n\n> Foo\n> Bar\n>> Baz\n> Foo\n\";\n\nfunction clean($text) {\n $result = \"\";\n $lines = explode(\"\\n\", $text);\n foreach($lines as $key => $line) {\n $lines[$key] = preg_replace... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-27T11:42:45.450",
"Id": "2655",
"Score": "4",
"Tags": [
"php"
],
"Title": "Wrap email quotes with html element"
} | 2655 |
<p>I am learning C++ on my own and was hoping for some feedback on this simple text-to-binary converter. The program runs and I haven't encountered any errors with it yet. Any input is welcome. </p>
<pre><code>#include <iostream>
#include <string>
#include <bitset>
using namespace std;
int main()
{... | [] | [
{
"body": "<p>Your code looks good overall. Just a couple comments...</p>\n\n<p>When writing C++ code, you generally use \"endl\" instead of \"\\n\" to terminate lines.</p>\n\n<pre><code>cout << \"hi\" << endl;\n</code></pre>\n\n<p>Also, to print out the ascii value of the character you don't neces... | {
"AcceptedAnswerId": "2663",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-27T15:57:03.817",
"Id": "2661",
"Score": "14",
"Tags": [
"c++",
"converting",
"console"
],
"Title": "Simple text-to-binary converter written in C++"
} | 2661 |
<p>I am learning OOP and have written a class for Likes. There is a load, add, delete method and I think this code can be improved since there is a lot of duplication. Please let me know how I can improve on this code and secure this code:</p>
<p>fileA.php:</p>
<pre><code>include_once dirname(__FILE__) . "/like.class... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-28T18:04:04.493",
"Id": "4189",
"Score": "0",
"body": "You don't have to enclose your `array`s in `()`. `$like = array('unlike' => true);` is easier to read and type. You should also stick to a standard when writing your syntax, using ... | [
{
"body": "<p>Some suggestions:</p>\n\n<ol>\n<li>Keep your try-blocks small</li>\n<li>Always check if your request-parameters are valid</li>\n<li>If you have duplicated code, put it into a private function</li>\n<li>If you're returning data-structures with only some fields changing in your function, define a de... | {
"AcceptedAnswerId": "2687",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-27T19:18:31.413",
"Id": "2664",
"Score": "3",
"Tags": [
"php",
"classes",
"object-oriented"
],
"Title": "Improve OOP code"
} | 2664 |
<p>I have a very good grasp of the syntax and features of F# as well as some of the concepts that mesh well with the language. However, I do not have enough experience writing it to feel comfortable that the way I am handling the language is appropriate. </p>
<p>Ignoring the fact that I do not provide proper escaping ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-27T23:06:29.203",
"Id": "4173",
"Score": "2",
"body": "I don't know F#, but does it not have mapMaybe like haskell does? And what about list comprehensions for all those maps and filters?"
},
{
"ContentLicense": "CC BY-SA 3.0",... | [
{
"body": "<p>Look into <a href=\"http://msdn.microsoft.com/en-us/library/ee370619.aspx\"><code>Array.choose</code></a>. Using that function cuts the length of your code in half, because you have basically reinvented it. (I did the same at some point ;-)</p>\n",
"comments": [
{
"ContentLicense... | {
"AcceptedAnswerId": "2681",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-27T22:08:14.470",
"Id": "2665",
"Score": "6",
"Tags": [
"parsing",
"f#"
],
"Title": "Is there any way to improve (shorten) this F# code?"
} | 2665 |
<p>I have this code which looks for query words in a given text. I preprocess the give text and store it in an inverted-index (dictionary with word as key and position in text as value). Searching for a query words then becomes contant time operation. </p>
<p>The below code also prints the surrounding text which conta... | [] | [
{
"body": "<pre><code># -*- coding: cp1252 -*-\nfrom collections import defaultdict\n\nclass c_Highlight():\n</code></pre>\n\n<p>Prefixed like c_ and m_ are frowned upon as useless.</p>\n\n<pre><code>\"\"\"Highlight Class to find and print relevant snippet of a text\"\"\"\n\nGrammar_Suffix = ['ing' ,'ly', 'ed',... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-28T00:18:25.350",
"Id": "2668",
"Score": "3",
"Tags": [
"python",
"search"
],
"Title": "Review Request: Python code that searches query words in a given text"
} | 2668 |
<p>I'm looking for (and be as brutal as you like) ways to improve the code or the algorithm (I'm aware there should be comments) - I'm a recreational programmer and would like to be improving my skills. My next step is to get the <code>targetNumber</code> value from a nearby file without losing the current count.</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-28T00:02:09.870",
"Id": "4176",
"Score": "0",
"body": "Whoops - did not know there was such a thing *blush* - what's the protocal here, do I delete and repost or will it just get transfered by a passing admin?"
},
{
"ContentLi... | [
{
"body": "<pre><code>function count(from, to, targetElem) {\n targetElem.innerHTML = 'Total wordcount: ' + from;\n\n if (from == to) return;\n\n from < to ? from++ : from--; \n\n var changeTime = Math.max(20, 1000 - Math.abs(from - to)) / 2;\n\n setTimeout(function() {count(from, to, target);... | {
"AcceptedAnswerId": "2680",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-27T23:57:06.567",
"Id": "2669",
"Score": "5",
"Tags": [
"javascript"
],
"Title": "Count to target with JavaScript"
} | 2669 |
<p>I am trying to design a program that will read a XML file and based on the tag name will perform certain requirements checks. I feel that there is probably a better way of doing this and any comments or suggestions are welcomed.</p>
<p>Thank you.</p>
<pre><code>public enum AccountCheckType
{
UserIsMemberOfGrou... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-28T20:21:58.390",
"Id": "4192",
"Score": "0",
"body": "which version of C# do you use?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-29T03:56:47.577",
"Id": "4197",
"Score": "0",
"body": "I us... | [
{
"body": "<p>You program seem me a good design, it would be great and also increase the program readability, if you change the function name which perform checks.</p>\n\n<p>They should start with <strong>Is</strong> </p>\n\n<p><em><strong>for example</em></strong> ---> your function name <code>DomainGroupE... | {
"AcceptedAnswerId": "2686",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-28T07:49:39.877",
"Id": "2675",
"Score": "5",
"Tags": [
"c#",
"design-patterns"
],
"Title": "Improving the design of this program."
} | 2675 |
<p>I know it's a good idea to put all data-related logic in your models in CakePHP, but what would you say about keeping every Model::find() and its particular params in the model? Is this good practice, or just taking things too far?</p>
<p><strong>For example, is this:</strong></p>
<p>PostsController:</p>
<pre><co... | [] | [
{
"body": "<p>It's totally egilable to write shorthand-<code>find</code> functions. This way the controller is not depended of the model's parameters. I tend to go that far, that I don't use any fields directly in my controllers (and thus, not using <code>find</code> in controllers at all).<br>\nYou could save ... | {
"AcceptedAnswerId": "2690",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-28T09:29:07.003",
"Id": "2677",
"Score": "3",
"Tags": [
"php",
"mvc"
],
"Title": "How skinny should controllers be, how fat should models be in CakePHP?"
} | 2677 |
<p>I wrote a little Python script to replace some files in <code>usr/bin</code> with symlinks to files in a different location.</p>
<p>I wouldn't mind anyone telling me where I could do better.</p>
<pre><code>#!/usr/bin/env python -tt
"""Xcode4 installs and expects to find a git installation at /usr/bin.
This is a p... | [] | [
{
"body": "<pre><code>#!/usr/bin/env python -tt\n\n\"\"\"Xcode4 installs and expects to find a git installation at /usr/bin.\nThis is a pain if you want to control your own installation of git that\nmight be installed elsewhere. This script replaces the git files in\n/usr/bin with symlinks to the preferred inst... | {
"AcceptedAnswerId": "2683",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-28T09:31:08.380",
"Id": "2678",
"Score": "7",
"Tags": [
"python",
"file-system"
],
"Title": "Replacing files with symlinks to other files"
} | 2678 |
<p>My coding skill is pretty rusty and moreover, I have never paid much attention to writing elegant code. I want to start on this. Problem is to merge 2 sorted linked list. Algorithmically this is trivial, but looks a good problem to practice coding.</p>
<pre><code>struct node
{
char *data;
struct node *nextp;
}
t... | [] | [
{
"body": "<p><strong>You should have added error checking</strong>:</p>\n\n<pre><code> node * newp=(node *)malloc(sizeof(node));\n newp->data=(char *)malloc(sizeof(strlen(data));\n</code></pre>\n\n<p>malloc can return NULL if there wont be enough Virtual Adress Space. Would be great if function return error... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-29T12:35:24.617",
"Id": "2693",
"Score": "7",
"Tags": [
"optimization",
"c",
"algorithm"
],
"Title": "Merge sort 2 sorted linked list"
} | 2693 |
<p>Given an array which contains integers (may contain thousands of elements), you have to write a program to find the second largest element of the group.</p>
<pre><code>int secondmax(int array[],int n)
{
int max;
int secondmax;
assert(n>1);
max=array[0]>array[1] ? array[0] : array[1];
secondmax=array[0]&g... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-29T14:00:10.693",
"Id": "4205",
"Score": "0",
"body": "The working code is at http://ideone.com/ko0ID"
}
] | [
{
"body": "<p>There's no need to check if array[0] > array[1] twice.</p>\n\n<pre><code>if (array[0] > array[1]) {\n max = array[0];\n secondmax = array[1];\n} else {\n secondmax = array[0];\n max = array[1];\n}\n</code></pre>\n\n<p>But if you really want to use the ternary operator here (<code>? ... | {
"AcceptedAnswerId": "2704",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-29T13:16:34.300",
"Id": "2694",
"Score": "2",
"Tags": [
"c",
"algorithm"
],
"Title": "Second largest element of a large array"
} | 2694 |
<blockquote>
<p>Given two binary trees, you have to find whether the second is a sub tree of the first.</p>
</blockquote>
<p>First attempt (brute force):</p>
<pre><code>int issubtree(tree *tree1p, tree * tree2p)
{
if (tree2p == NULL)
return 1;
if (tree1p == NULL)
return 0;
if (tree1p-&... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-29T14:56:11.593",
"Id": "4206",
"Score": "1",
"body": "I'd come up with better (subjective, I know) names for the parameters: `int issubtree(const tree *haystack, const tree *needle)`"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>This algorithm requires the values to maintain the same structure in both trees which is probably okay for this assignment (homework?).</p>\n\n<p>If these are binary search trees, there's at least one optimization you can make right off the bat: inside the <code>else</code> block you don't have to... | {
"AcceptedAnswerId": "2703",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-29T14:13:04.833",
"Id": "2696",
"Score": "5",
"Tags": [
"performance",
"algorithm",
"c"
],
"Title": "Given two Binary trees, find whether the second is a sub tree of the first"
} | 2696 |
<p>I'm starting to dive into <strong>TDD</strong> with <strong>NUnit</strong> and despite I've enjoyed checking some resources I've found here at stackoverflow, I often find myself not gaining good traction.</p>
<p>So what I'm really trying to achieve is to acquire some sort of checklist/workflow —and here's where I n... | [] | [
{
"body": "<p>sometimes you make new ones, sometimes you extend the current test you are working on. There's no real rules. You are trying to keep your tests well factored like your code. So sometimes you DELETE a test also.</p>\n\n<p>Just treat your test code like production code. Remove duplication. Kee... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-29T17:42:27.250",
"Id": "2699",
"Score": "7",
"Tags": [
"c#",
"unit-testing"
],
"Title": "TDD workflow best-practices for .NET using NUnit"
} | 2699 |
<p>I'm new to this page I want to ask you to critique my code on jInternalFrame. Basically the problem is that there is no complete example on using this, so I wrote this "template" but I don't know if it lacks of something.</p>
<p>So here is the code(It does 'nothing' just calling, positioning and basic stuff):</p>
... | [] | [
{
"body": "<p>Your class names don't follow the normal standard of starting with a capital letter. Also they are not very specific so it is hard to understand what their purpose might be. Your variable names suffer from similar problems of not being </p>\n",
"comments": [],
"meta_data": {
"Comme... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-29T18:10:57.603",
"Id": "2700",
"Score": "5",
"Tags": [
"java",
"swing"
],
"Title": "jInternalFrames code"
} | 2700 |
<p>Problem:</p>
<blockquote>
<p><em>n</em> students have marks and names. Rank students based on their marks and print their names.</p>
</blockquote>
<hr>
<pre><code>#include <stdio.h>
#include <assert.h>
struct student
{
int marks;
char name[50];
};
struct listnode
{
struct student * dat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-30T16:42:01.010",
"Id": "4220",
"Score": "8",
"body": "Two things: (1) please indent your code properly. (2) please describe the actual problem. At the moment you’re only offering a dense wall of code and a semi-intelligible title."
... | [
{
"body": "<p>First, make sure the code compiles. You should include <code>stdlib.h</code> for <code>malloc</code>. Depending on which compiler and libraries you use, this may still work on your system but always include the proper headers for the api's you're using.</p>\n\n<p>Then your initialization of the st... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-30T11:41:26.110",
"Id": "2708",
"Score": "8",
"Tags": [
"algorithm",
"c",
"sorting"
],
"Title": "Using bucket sort to rank students based on their marks"
} | 2708 |
<p>I know that this is very very basic, but now I am starting from group up after getting frustrated with my coding practices and knowledge of standard idioms out there and elegant way of coding corner cases. The problem is to insert into tail of a linked list.</p>
<pre><code>void insertattail (struct node *head, int ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-30T13:36:37.487",
"Id": "4217",
"Score": "0",
"body": "More linked list code is at https://ideone.com/UrtaO"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-30T21:21:57.683",
"Id": "4228",
"Score": "... | [
{
"body": "<pre><code>if(head == NULL) // is there more elegant way of dealing with this? any idiom?\n{\nhead=newp;\nreturn;\n}\n</code></pre>\n\n<p><code>head</code> is a local variable in this function. Modifying it will not change the variable that was passed into the function. As a result, the new node you... | {
"AcceptedAnswerId": "2712",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-30T12:58:05.090",
"Id": "2710",
"Score": "6",
"Tags": [
"c",
"algorithm",
"linked-list"
],
"Title": "Inserting into a linked list"
} | 2710 |
<p>A schoolmate is going through the interview process, and was given the question of detecting if a linked list data structure has an infinite loop in it. I wrote this example, and wanted to see what experience programmers thought of it.</p>
<pre><code>/*
* detecting loops in a linked list, java
*
* This linked list ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-30T18:01:06.813",
"Id": "4222",
"Score": "2",
"body": "It is possible solve it with O(1) memory consumption."
}
] | [
{
"body": "<pre><code> void setNext(Node n)\n {\n this.n = n;\n }\n boolean hasNext()\n {\n return n!=null;\n }\n Node next()\n {\n return n;\n }\n</code></pre>\n\n<p>I think the getters and setters are misplaced here. Such methods should be used to hide the internal details of an implementati... | {
"AcceptedAnswerId": "2713",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-30T15:35:55.187",
"Id": "2711",
"Score": "10",
"Tags": [
"java",
"interview-questions"
],
"Title": "Linked list loop detection in Java"
} | 2711 |
<p>I've written a fairly small library that <em>abstracts cookie functionality in a way that mimics working with a database model</em>. The repository is on <a href="https://bitbucket.org/yrizos/simplecookie/overview" rel="nofollow">bitbucket</a> and the code is small enough to embed here: </p>
<pre><code>class Simple... | [] | [
{
"body": "<p><em>Code quality</em></p>\n\n<p>Well, I did not try your code, but at a first glance it seems to be very robust code. But for further development I would recomend you to set up a test case for your class. See <a href=\"http://www.phpunit.de\" rel=\"nofollow\">http://www.phpunit.de</a>.</p>\n\n<p><... | {
"AcceptedAnswerId": "2727",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-30T20:01:19.937",
"Id": "2715",
"Score": "8",
"Tags": [
"php"
],
"Title": "Critique request: PHP cookie library"
} | 2715 |
<p>The method must search <code>Product</code>s found by criteria and store them in <code>@products</code>.</p>
<p>The criteria are as follows:</p>
<ul>
<li>If the user enters something in <code>text_field</code> (<code>:search_keywords</code>) then the product's name needs to be matched with that word</li>
<li>If th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-03T14:13:52.547",
"Id": "4338",
"Score": "7",
"body": "Note that the way you build your queries is extremely vulnerable to SQL injection. Please see http://api.rubyonrails.org/classes/ActiveRecord/Base.html under the conditions section... | [
{
"body": "<ol>\n<li><p>You can use blank? </p></li>\n<li><p>You need user parameters in SQL query.</p></li>\n<li><p>Maybe you need escaping character <code>%</code> in <code>search_keywords</code>.</p></li>\n</ol>\n\n<p></p>\n\n<pre><code>def search\n keywords_blank = params[:search_keywords].blank?\n ty... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-30T20:05:46.223",
"Id": "2716",
"Score": "6",
"Tags": [
"ruby",
"ruby-on-rails",
"search"
],
"Title": "Search for products based on criteria"
} | 2716 |
<p>This is a social share widget for guubo.com. The live widget can be seen <a href="http://guy.lt/" rel="nofollow">here</a> (though you need to be signed in guubo.com, otherwise you will see a logged-out user interface). JS is not my first language, therefore some reviews are welcome.</p>
<pre><code>// create iframe
... | [] | [
{
"body": "<p>Your code sets a lot of global variables, and you should always <a href=\"http://dev.opera.com/articles/view/javascript-best-practices/#avoidglobals\" rel=\"nofollow noreferrer\">avoid them</a>. The easiest way to do that is \"<a href=\"https://stackoverflow.com/questions/1841916/how-to-avoid-glob... | {
"AcceptedAnswerId": "3191",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-30T22:03:18.047",
"Id": "2718",
"Score": "4",
"Tags": [
"javascript"
],
"Title": "Social share widget for guubo.com"
} | 2718 |
<p>This is my first attempt at a jQuery plugin. Any tips or comments in regards the the plugin setup would be appreciated. I'm also looking for a general review over the code itself. I'm wondering if there is a better way to encode the font. The way I'm doing it now makes it easy to see, read and create the characte... | [] | [
{
"body": "<p>You could use a bit more concise syntax. For example, when filling the <code>data</code> object in ìnit()`, you could use literal object notation:</p>\n\n<pre><code>data = {\n target: $this,\n fontheight: 16,\n fontwidth: 8,\n canvas: $('<canvas width=\"' + (data.fontwidth * 80) + 'px\" hei... | {
"AcceptedAnswerId": "2733",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-30T22:44:18.747",
"Id": "2719",
"Score": "6",
"Tags": [
"javascript",
"jquery",
"plugin",
"graphics"
],
"Title": "jQuery to display ANSI graphics"
} | 2719 |
<p>I commonly run into the need to implement IDisposable in my code. To correctly dispose of both managed and unmanaged resources requires a reasonable amount of boilerplate code. Based on the documentation found <a href="http://msdn.microsoft.com/en-us/library/system.idisposable.dispose%28v=VS.100%29.aspx">here</a> I ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T12:22:01.517",
"Id": "4241",
"Score": "4",
"body": "One problem I see is you'll quickly run into multiple inheritance issues (or rather the lack of). I've often seen similar implementations however, and in some scenarios where you c... | [
{
"body": "<p>Personally I would have made <code>Dispose(bool disposing)</code> protected virtual rather than have 2 abstract methods ... for consistency with most unsealed disposable objects in the framework. Also, I recall FxCop was quite pedantic about the implementation of IDisposable.</p>\n\n<p>If you stil... | {
"AcceptedAnswerId": "2728",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T00:28:22.327",
"Id": "2720",
"Score": "36",
"Tags": [
"c#",
".net"
],
"Title": "DisposableObject base class for C#"
} | 2720 |
<p>This code comes straight out from the example code in a Django book. I find it quite bad, mainly because the use of flags (<code>if ajax</code> then again <code>if ajax</code>) and unnecessarily bigger variable scope (set <code>title=''</code>, <code>tags=''</code> and then use these variables in different flows). T... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T15:24:19.487",
"Id": "4250",
"Score": "0",
"body": "Seems okay-ish to me, but I would absolutely split it up into into functions/methods instead of the slightly silly \"if ajax\" check. There are also too many hardcoded values. I'd ... | [
{
"body": "<p>In my opinion it's little bit hard to read. You have to split it up into POST/GET methods.\nThen you have to clean up code in POST/GET methods.\nSomething like this, for example.</p>\n\n<pre><code>@login_required\ndef bookmark_save(request):\n form = BookmarkSaveForm()\n if request.method ==... | {
"AcceptedAnswerId": "2737",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T01:23:22.153",
"Id": "2721",
"Score": "5",
"Tags": [
"python",
"django",
"ajax"
],
"Title": "How would you rate this python code? (Django AJAX)"
} | 2721 |
<p>This is the first PDF class I have made for the iOS using code from Apple's samples. There could easily be stuff here wrong that I am missing. </p>
<p>I intend this to get images out of for a layer, for example:</p>
<pre><code>image.contents = (id)[self.test imageForPage: 3 size: CGSizeMake(4*dpc, 2*dpc)].CGImage... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T05:35:34.823",
"Id": "4233",
"Score": "1",
"body": "I have encountered PDF files where the text is written in landscape but the page width and height will tell you that the page is in portrait. When opened in a PDF viewer, the file ... | [
{
"body": "<p>One immediate change I'd make is how you're handling errors. While <code>try-catch</code> blocks are extremely common in other programming languages, I actually don't see them all that very often in Objective-C.</p>\n\n<p>That doesn't mean we won't have errors. It just means error handling is ty... | {
"AcceptedAnswerId": "42247",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T00:24:22.510",
"Id": "2722",
"Score": "8",
"Tags": [
"objective-c",
"ios",
"pdf"
],
"Title": "What can I improve on my iOS PDF class?"
} | 2722 |
<p>I want to write some basic code on graph like DFS, BFS but before that I am coding graph representation in adjacency list, and some basic functions like <code>readgraphfrommatrix</code>. (This will initialize graph from adjacency matrix which is easier to supply as input to test the program.)</p>
<p>A vertex can ha... | [] | [
{
"body": "<p>Code style: Use <code>typedef struct</code> instead of <code>struct</code> for cleanliness.</p>\n\n<p>This looks generally OK, but is not strictly speaking an adjacency list representation. In an adjacency list representation you store a list of verticies, and each of those verticies store a list ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T11:08:06.420",
"Id": "2732",
"Score": "5",
"Tags": [
"optimization",
"c",
"graph"
],
"Title": "Coding adjacency list representing graph"
} | 2732 |
<p>I'm working on a few JavaScript functions for myself that I hope come in handy sometime. The first I wrote was a Capitalization function (yeah i know, <em>real</em> original. whatever)
I was just wondering if </p>
<ol>
<li>I'm doing anything incredibly stupid</li>
<li>There's anyway to make the code below more co... | [] | [
{
"body": "<p><a href=\"http://jsfiddle.net/a8h3a/3/\" rel=\"nofollow\">Live example</a></p>\n\n<pre><code>String.capitalize = function(str, everyWord) {\n return _.map(_.words(str), function(val, key) {\n return key === 0 || everyWord ? _.capitalize(val) : val;\n }).join(\" \");\n};\n</code></pre>... | {
"AcceptedAnswerId": "2759",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T13:32:23.167",
"Id": "2734",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "Code Concision - String Capitalization"
} | 2734 |
<p>I have this "pretty" date string generator in C# - pass it a date and it returns a string with "5 minutes ago" or "2 weeks, 3 days ago", etc.</p>
<p>It's a little verbose and hogs 61 lines, and I'm wondering if I'm missing out on some nice C# features or something. What (if any) is the best way to clean up this cod... | [] | [
{
"body": "<p>Some things are repeated:</p>\n\n<pre><code>days - weeks * 7\nhours - days * 24\nminutes - hours * 60\n</code></pre>\n\n<p>These can and should be made into their own variables - but what you are really after seems to be </p>\n\n<pre><code>days % 7\nhours % 24\nminutes % 60\n</code></pre>\n\n<p>Yo... | {
"AcceptedAnswerId": "2746",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T16:51:57.523",
"Id": "2738",
"Score": "9",
"Tags": [
"c#",
"datetime"
],
"Title": "\"Pretty\" date generator"
} | 2738 |
<p>I have a loop structure, that I really don't like. It's the initialisation I find appalingly ugly. Is there a nicer way to do the following?</p>
<pre><code>Queue<Integer> queue = getMyQueue();
Integer element = queue.poll();
while (element != null){
calculate_smart_stuff(element);
element = queue.poll();
... | [] | [
{
"body": "<p>Can you not do:</p>\n\n<pre><code>while ((element = queue.poll) != null) {\n..\n} \n</code></pre>\n\n<p>?</p>\n\n<p>It requires more knowledge of the language but that might be a trade-off you like.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate":... | {
"AcceptedAnswerId": "2747",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T18:19:38.077",
"Id": "2741",
"Score": "8",
"Tags": [
"java",
"queue"
],
"Title": "fix ugly initialisation in while loop over queue"
} | 2741 |
<p>I would like to improve this function to reduce the run time and optimize it.</p>
<pre><code>function [Pl,Plm] = funlegendre(gamma)
Plm = zeros(70,71);
Pl = zeros(70,1);
P0 = 1;
Pl(1) = gamma;
Plm(1,1) = sqrt(1-gamma^2);
for L=2:70
for M=0:L
if(M==0)
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-10-03T16:38:10.650",
"Id": "7689",
"Score": "0",
"body": "Have you considered turning this into a mex function? That will significantly reduce run time"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-10-24T18:26:... | [
{
"body": "<p>At first glance I can see a few points where you can start to optimize your polynom generation.\nFirst thing I would refactor is the \"heavy\" use of conditional cases. There are only two well defined situation in which M==0 or M==L. Therefore you could extract both cases and implement them within... | {
"AcceptedAnswerId": "13564",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T19:14:06.863",
"Id": "2743",
"Score": "3",
"Tags": [
"optimization",
"matlab"
],
"Title": "Legendre's polynomials and functions"
} | 2743 |
<p>I need to classify each line as "announce, whisper or chat" once I have that sorted out I need to extract certain values to be processed.</p>
<p>Right now my regex is as follow:</p>
<pre><code>var regex = new Regex(@"^\[(\d{2}:\d{2}:\d{2})\]\s*(?:(\[System Message\])?\s*<([^>]*)>|((.+) Whisper You :))\s*(... | [] | [
{
"body": "<p>You can always break it down in multiple lines to make it more readable. You can also use named groups which take the \"magic\" out of the group numbers (4 == whisper, 3 == normal, etc).</p>\n\n<pre><code> var regex = new Regex(@\"^\\[(?<TimeStamp>\\d{2}:\\d{2}:\\d{2})\\]\\s*\" +\n ... | {
"AcceptedAnswerId": "2750",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T22:27:38.257",
"Id": "2749",
"Score": "4",
"Tags": [
"c#",
"parsing",
"regex"
],
"Title": "Using Regex to parse a chat transcript"
} | 2749 |
<p>Last weekend I was writing a short PHP function that accepts a starting move and returns valid knight squares for that move.</p>
<pre><code><?php
/* get's starting move and returns valid knight moves */
echo GetValidKnightSquares('e4');
function GetValidKnightSquares($strStartingMove) {
$cb_rows = array('a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T00:06:49.400",
"Id": "4271",
"Score": "0",
"body": "what is the question? :O"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T00:07:43.730",
"Id": "4272",
"Score": "0",
"body": "Erm, what's... | [
{
"body": "<p>what about this? </p>\n\n<pre><code>function GetValidKnightSquares($strStartingMove){\n $rowvals='abcdefgh';\n $row_assoc=array_flip(str_split($rowvals));\n $row = $strStartingMove[0]-1;\n if(!strstr($rowvals,$row)){\n die('invalid row');\n }\n $col = $strStartingMove[1];\n if($col<1... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T00:04:54.980",
"Id": "2751",
"Score": "4",
"Tags": [
"php"
],
"Title": "Need help with valid knight moves in Chess"
} | 2751 |
<p>Can this code be improved? I'm avoiding using the QueryString collection because the query string may contain eg: <code>OrderBy=Column1&OrderBy=Column2</code> and it didn't seem helpful to start with those switched into QueryString["OrderBy"]=="Column1,Column2";</p>
<pre><code> var query = "";
if (urlHe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T16:39:15.880",
"Id": "4291",
"Score": "0",
"body": "Why do you think it won't be helpful to switch to `QueryString[\"OrderBy\"]==\"Column1,Column2\"`. It seems to be more regular structure than several parameters with the same name.... | [
{
"body": "<p>I think that yes this code can be improved.</p>\n\n<p>use a regular expression:</p>\n\n<pre><code> var newQuery = Regex.Replace(currentQuery, @\"(?i)(page=\\d*&?)\", \"\").TrimEnd('&');\n if (newQuery.Length > 0)\n newQuery += string.Format(\"&Pa... | {
"AcceptedAnswerId": "2996",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T15:18:50.920",
"Id": "2762",
"Score": "1",
"Tags": [
"c#",
"asp.net-mvc-2"
],
"Title": "Adding or Replacing a Page item in a QueryString in C#."
} | 2762 |
<p>How can I write the following T-SQL query part in a shorter way without using <a href="http://www.sqlteam.com/article/introduction-to-dynamic-sql-part-1" rel="nofollow">dynamic SQL</a>?</p>
<pre><code>WHERE
( (@Max IS NULL OR @Type <> 'Products')
OR (@Max IS NOT NULL AND @Type = 'Products'
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T06:13:35.507",
"Id": "4295",
"Score": "3",
"body": "By \"shorter\", do you mean \"shorter\" in terms of text length, or in terms of efficiency? The first really doesn't matter-long queries can be efficient and short ones inefficient... | [
{
"body": "<p>You will have to test this carefully, but the following query should work:</p>\n\n<pre><code>WHERE \n( \n @Max IS NULL \n OR @Type = 'Products' AND ProductCount > @Max\n OR @Type = 'Vendors' AND VendorCount > @Max\n OR @Type = 'Order' AND OrderCount > @Max\n)\nAND\n(\n @Min IS... | {
"AcceptedAnswerId": "2764",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T06:07:49.150",
"Id": "2763",
"Score": "5",
"Tags": [
"sql",
"sql-server",
"t-sql"
],
"Title": "Reduce the code in a WHERE clause without using dynamic SQL"
} | 2763 |
<p><a href="http://www.microsoft.com/sqlserver" rel="nofollow">Microsoft's SQL Server</a> is a suite of relational database management system (RDBMS) products providing multi-user database access functionality. It originated from Sybase SQL Server 4.x codebase and Transact-SQL dialect (T-SQL), but forked significantly... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T18:08:57.643",
"Id": "2766",
"Score": "0",
"Tags": null,
"Title": null
} | 2766 |
Microsoft's SQL Server is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases. It originated from the Sybase SQL Server codebase, which is why both products use the extension of SQL called Transact-SQL (T-SQL). | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T18:08:57.643",
"Id": "2767",
"Score": "0",
"Tags": null,
"Title": null
} | 2767 |
<pre><code>Email<input type="text" id="email" /><br />
Re-enter Email<input type="text" id="confirm-email" />
</code></pre>
<p>I'm thinking that I want a model so that I can have this partial page strongly typed. But what a lame model....</p>
<p>It would look like this, and if this is a good Idea, ... | [] | [
{
"body": "<p>call it a \"view model\" as its not really a model, its just a model for the view you are showing.</p>\n\n<p>ConfirmEmailViewModel :)</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-02T03:20:48.260"... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T19:22:08.910",
"Id": "2768",
"Score": "4",
"Tags": [
"c#",
"mvc",
"email",
"asp.net-mvc-3"
],
"Title": "Email confirmation model"
} | 2768 |
<p><strong>Windows Presentation Foundation</strong> (WPF, previously known as “Avalon”) is part of the Microsoft <a href="/questions/tagged/.net" class="post-tag" title="show questions tagged '.net'" rel="tag">.net</a> <a href="/questions/tagged/framework" class="post-tag" title="show questions tagged 'fram... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T20:39:50.917",
"Id": "2770",
"Score": "0",
"Tags": null,
"Title": null
} | 2770 |
Windows Presentation Foundation (WPF) is part of the Microsoft .NET framework used to create rich client user experiences for Windows application. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T20:39:50.917",
"Id": "2771",
"Score": "0",
"Tags": null,
"Title": null
} | 2771 |
<p>I have a T4 Templates project that generates methods to "convert" one Type (class, struct, enum) from a source Assembly its corresponding Type in another. The two types have the identical names and property names, just different namespaces and different types. This may be a re-invented a wheel. Nonetheless, I didn't... | [] | [
{
"body": "<p>I don't think is either \"Fair use\" nor \"Abuse\" of dynamic; I think for your purpose, dynamic may be \"Misused\". </p>\n\n<p>If all you want to accomplish is to map \"two types have the identical names and property names, just different namespaces and different types\", then you should probab... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T21:44:36.503",
"Id": "2772",
"Score": "3",
"Tags": [
"c#"
],
"Title": "Fair use or Abuse of the dynamic (System.Dynamic.DynamicObject)?"
} | 2772 |
<p>I'm going through the CoffeeScript book by Trevor Burnham, and I was curious as to what the best style is for a function I was writing.</p>
<p>In the book the author writes the function like so:</p>
<blockquote>
<pre><code>strToCoordinates = (input) ->
halves = input.split(',')
if halves.length is 2
... | [] | [
{
"body": "<p>Well I don't now coffeescript, but guess I can read it anyway :D</p>\n\n<p>I think both are good and readable.<br>\nI don't know if you can add empty lines to the code. If you can:</p>\n\n<pre><code>strToCoordinates = (input) ->\n halves = input.split(',')\n if halves.length isnt 2\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-01T23:02:32.150",
"Id": "2773",
"Score": "4",
"Tags": [
"converting",
"coffeescript"
],
"Title": "Converting a string to coordinates"
} | 2773 |
<p>I've never done anything like this before so I'd like someone else to look at this before I get too carried away :)</p>
<p>Am I making this more complicated than it needs to be? I'm trying to make it EASY for other modules/scripts on this system to store and retrieve their settings. Hence why I trap the <code>Conf... | [] | [
{
"body": "<p>One problem I see is that returning None from your modified get() method conflicts with the normal case of a valueless option (from the bottom of the module docs for ConfigParser):</p>\n\n<pre><code>>>> import ConfigParser\n>>> import io\n\n>>> sample_config = \"\"\"\n..... | {
"AcceptedAnswerId": "2804",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-02T02:20:10.937",
"Id": "2775",
"Score": "3",
"Tags": [
"python"
],
"Title": "Python subclassing ConfigParser"
} | 2775 |
<pre><code><p style="background-color:#<%= debate.bg_color %>;" >
</code></pre>
<p><code>be_color</code> is a method of <code>Debate</code> that returns a string like <code>45FFFF</code>.</p>
<p>Although it does what I want, this seems like a tremendously bad idea. What would be a better way to accomplish... | [] | [
{
"body": "<p>inline styles are bad practice</p>\n\n<p>more elegant way would be assigning class to your <p> element based on debate properties, maybe creating a helper if this line is used frequently</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-02... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-02T03:41:36.967",
"Id": "2777",
"Score": "4",
"Tags": [
"ruby",
"html",
"ruby-on-rails",
"css"
],
"Title": "Setting bgcolor in Ruby. What's the proper way to do it?"
} | 2777 |
<p>Following the normal pattern of adding inline scripts to gridview row/s is a <strong>bad practice</strong> it used to work like below</p>
<pre><code> protected void CustomersGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
switch (e.Row.RowType)
{
case DataControlRowType.Da... | [] | [
{
"body": "<p>Would it not be better to build a generic script to handle all row scripting requirements, and include once per page? You'll end up with a cleaner end script, and your page footprint will be a lot smaller. You'll also benefit from the browser's resource caching.</p>\n\n<p>Using jQuery, you could a... | {
"AcceptedAnswerId": "2787",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-02T09:42:49.717",
"Id": "2780",
"Score": "0",
"Tags": [
"c#",
"javascript",
"asp.net",
"design-patterns"
],
"Title": "How to re register dynamic scripts registered with ClientS... | 2780 |
<p>I made this PHP class that loads any image you specify and resizes it to any size you want.</p>
<p><strong>Features</strong></p>
<p>If the size you specify is greater than the original, it will not stretch the image but use padding instead. Or if the size you requested is not the original aspect ratio, it will not... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-11T03:44:04.563",
"Id": "76193",
"Score": "0",
"body": "See also: http://codereview.stackexchange.com/questions/44025/security-scale-and-cache-images"
}
] | [
{
"body": "<p>I take it you are using GD for image manipulation. You could look at ImageMagick as an alternative, as its been shown to be faster at manipulating images. There is a related <a href=\"https://stackoverflow.com/questions/12661/efficient-jpeg-image-resizing-in-php\">SO question here</a>.</p>\n",
... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-02T16:25:50.047",
"Id": "2786",
"Score": "2",
"Tags": [
"php",
"performance",
"image"
],
"Title": "Class for loading and resizing images on the fly performs slowly on large images"
} | 2786 |
<p>I've been asked to keep track of how long a user has been connected to a site without interruption.</p>
<p>So far the solution I've come up with is to use ajax to poll the site every now and then to check how much time has elapsed since the last call.</p>
<p>Any suggestions for possible improvements would be appre... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-10T03:17:05.487",
"Id": "4458",
"Score": "1",
"body": "Don't know how you define \"connected\", but I would suggest you look at this answer on StackOverflow - http://stackoverflow.com/questions/1760250/how-to-tell-if-browser-tab-is-act... | [
{
"body": "<p>Structure of your Javascript is tightly coupled with your logic, decoupling will allow change without major changes.</p>\n\n<p>a) Move you Ajax initialization [xmlHttp] to a usable function.</p>\n\n<p>b) UnIntended display of UserId <code>req.send(\"data=<?php echo $user->id; ?>\");</code... | {
"AcceptedAnswerId": "2796",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-03T09:12:49.763",
"Id": "2795",
"Score": "2",
"Tags": [
"php",
"javascript",
"mysql",
"sql",
"ajax"
],
"Title": "Polling script to determine the continuous time a user has ... | 2795 |
<p>In my particular usage here, I'm using two functions to deal with one thing.</p>
<p>Lets say the user request comes in to select "ALL" the records, in which case I would pass on some code such as:</p>
<pre><code>function getRecords() {
return some_sql("Select * from whatever WHERE id > 0;");
}
</code></pre>... | [] | [
{
"body": "<p>Why would you want a single method to do three logically different things? Each method you make should really only perform one task. What's the problem in just having the consumer choose the method of selection based upon their need, instead of having a one method fits all sort of thing? If having... | {
"AcceptedAnswerId": "2801",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-03T17:48:35.267",
"Id": "2800",
"Score": "4",
"Tags": [
"design-patterns",
"sql"
],
"Title": "I want a nice design pattern for \"All\", \"many\" or \"one\""
} | 2800 |
<p>I've been working on putting a new app up against Zend. In my admin section, I want the nav links to only show if the user has rights to see the page. So I set up some Acls. But this doesn't seem like the right way to do things. What's the "right" way to do this stuff?</p>
<p><strong>Bootstrap.php</strong></p>
<pr... | [] | [
{
"body": "<p>You should use the <a href=\"http://framework.zend.com/manual/en/zend.application.available-resources.html\" rel=\"nofollow\">available bootstrap resources</a> where possible:</p>\n\n<pre><code>protected function _initPlugins() {\n // First, set up the Cache\n $frontendOptions = array(\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-03T20:58:00.300",
"Id": "2805",
"Score": "3",
"Tags": [
"php",
"zend-framework"
],
"Title": "Zend Bootstrap code review"
} | 2805 |
<p>I've come up with this small function to make user submitted strings safe for MySQL. I'd be grateful if someone could point out any security holes in this. I've tested it out, and it happily replaces quotes and the like. The only issue I can see is the lack of escaping ampersands, but this shouldn't matter right?</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-04T11:18:26.570",
"Id": "4348",
"Score": "1",
"body": "If your string is in quotes, why do you need to remove the dangerous words? Doesn't [mysql_real_escape_string](http://php.net/manual/en/function.mysql-real-escape-string.php) do ev... | [
{
"body": "<p>Also check PHP's filtering manual: \n<a href=\"http://php.net/manual/en/book.filter.php\" rel=\"nofollow\">http://php.net/manual/en/book.filter.php</a></p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-1... | {
"AcceptedAnswerId": "3020",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-04T11:10:04.610",
"Id": "2809",
"Score": "2",
"Tags": [
"php",
"mysql",
"security"
],
"Title": "Sanitisation function: any holes?"
} | 2809 |
<p>I have implemented a simple iterator. Just want to check if I have missed anything.</p>
<pre><code>interface iterator<E>
{
boolean hasNext();
E next();
}
class Iterator<E> implements iterator
{
E[] arr;
int curPos = 0;
@Override
public ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-05T00:58:14.080",
"Id": "4354",
"Score": "0",
"body": "It is not very clear what is asked in the second question. Could you clarify it or (what probably would be better) move it to a separate question?"
}
] | [
{
"body": "<p>Because then the consumer of that code could write something like:</p>\n\n<pre><code>Iterator<Foo> iterator = new Iterator<Foo>();\n\n//...\n\nFoo theFoo = iterator.next();\n</code></pre>\n\n<p>instead of having to cast the object of type Object to type Foo like</p>\n\n<pre><code>Foo t... | {
"AcceptedAnswerId": "2825",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-04T20:43:27.530",
"Id": "2811",
"Score": "3",
"Tags": [
"java",
"design-patterns",
"iterator"
],
"Title": "Iterator pattern/iterator class"
} | 2811 |
<p>The basic idea is this:</p>
<p>There are two buttons: a <code>DoWork</code> button and a <code>Cancel</code> button.</p>
<p>The <code>DoWork</code> button should launch a thread to do some work, unless that thread was already launched and not canceled.</p>
<p>The <code>Cancel</code> button should cancel the worke... | [] | [
{
"body": "<p>Trying to use shared variables is generally a <strong>Bad Thing(TM)</strong>. The usual way to do cross-thread locking / resource checking is via a mutex.</p>\n\n<p>Something like this, though I haven't compiled or checked it:</p>\n\n<pre><code>private Thread m_WorkingThread;\nprivate static Mute... | {
"AcceptedAnswerId": "2845",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-05T03:29:49.893",
"Id": "2816",
"Score": "1",
"Tags": [
"c#",
"multithreading",
"form"
],
"Title": "Is my multithreaded form code correct?"
} | 2816 |
<ul>
<li><code>Ax, Ay, Az: [N-by-N]</code></li>
<li><code>B=AA</code> (dyadic product) </li>
</ul>
<p>means </p>
<pre><code>B(i,j)= [Ax(i,j);Ay(i,j);Az(i,j)]*[Ax(i,j) Ay(i,j) Az(i,j)]
</code></pre>
<p><code>B(I,j)</code>: a 3x3 matrix.</p>
<p>One way to construct <code>B</code> is:</p>
<pre><code>N=2;
Ax=rand(N... | [] | [
{
"body": "<p>There is a problem with vector multiplication in the second loop. You should transpose the second vector before doing multiplication.</p>\n\n<pre><code>F(:,:,t)= [Ax(i,j);Ay(i,j);Az(i,j)]*[Ax(i,j) Ay(i,j) Az(i,j)]';\n</code></pre>\n\n<p>One of the ways to speed things up is to apply vectorization ... | {
"AcceptedAnswerId": "7040",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-05T04:22:15.007",
"Id": "2817",
"Score": "3",
"Tags": [
"performance",
"algorithm",
"matrix",
"matlab"
],
"Title": "Creating a matrix from a dyadic product"
} | 2817 |
<p>The C in CRUD Silverlight:</p>
<ul>
<li>Create new Silverlight business application "CRUD"</li>
<li>Add ADO.NET Entity Data Model to CRUD.web</li>
<li>Select the db, the tables, build the project</li>
<li>Add Domain Service Class to CRUD.web</li>
<li>Select the tables and also select the allow editing option for th... | [] | [
{
"body": "<p>I don't think it's best-practice to put any logic that isn't strictly presentation-specific directly into a code-behind event handler like this, let alone that a <code>UserControl</code> knows anything about any <code>DomainService1</code> object.</p>\n\n<p>If you're shooting for best-practices, y... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-05T17:17:17.643",
"Id": "2824",
"Score": "3",
"Tags": [
".net",
"vb.net",
"silverlight",
"crud"
],
"Title": "C in CRUD for Silverlight"
} | 2824 |
<p>This is the way I'm currently getting data from XML, but it seems to be really inefficient, checking every localname in every iteration. How should I be doing it?</p>
<p>Here is a sample of the XML I am trying to parse, followed by my code.</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<hash>
... | [] | [
{
"body": "<p>You could try using <a href=\"http://msdn.microsoft.com/en-us/library/system.xml.linq.xdocument.aspx\" rel=\"noreferrer\"><code>XDocument</code></a> instead. </p>\n\n<p>It would also help to see an example of the <code>xml</code> you're trying to parse in order to properly suggest a refactoring o... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-05T23:52:26.673",
"Id": "2826",
"Score": "4",
"Tags": [
"c#",
"xml"
],
"Title": "There has to be a better way of parsing XML in C# than what I'm doing"
} | 2826 |
<p>I know that getopts is available but I wanted to write my own as a way of improving my bash. Below I show two function definitions and an example of the use of them in a bash script. Finally I show the output of the script.</p>
<p>Please comment.</p>
<pre><code>#!/bin/bash
# Produce a string variable which can b... | [] | [
{
"body": "<p>The bash code all looks reasonably fine to me.</p>\n\n<p>The -h and --help output doesn't look right (it will print the actual parameters passed, but should print the list of allowable options/parameters?)</p>\n\n<p>Options like --this-will-break won't work with --will or --break.</p>\n\n<p>I'm no... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-05T23:54:20.767",
"Id": "2827",
"Score": "3",
"Tags": [
"bash"
],
"Title": "Functions for scanning command line options"
} | 2827 |
<p>Is there anything wrong with this implementation of Queue with array?</p>
<p>I have started front = rear = -1. </p>
<p>Some references tend to start front = 0 like this:<a href="http://hamilton.bell.ac.uk/swdev2/notes/notes_13.pdf" rel="nofollow">enter link description here</a></p>
<p>I think if front starts with... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-06T09:05:19.977",
"Id": "4369",
"Score": "1",
"body": "**Enqueue** and **Dequeue**"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-06T13:54:42.250",
"Id": "4370",
"Score": "0",
"body": "COULD NO... | [
{
"body": "<p>Most implementations of a Queue use <code>front</code> to point to the head element of the queue and <code>rear</code> to point to the first empty element at the rear of the queue:</p>\n\n<pre><code>front rear\nv v\n[1][2][3][4][ ][ ]\n</code></pre>\n\n<p>Your implementation has t... | {
"AcceptedAnswerId": "2832",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-06T07:13:41.457",
"Id": "2831",
"Score": "2",
"Tags": [
"c",
"array",
"queue"
],
"Title": "What value the rear and front counter of an Array implementation of Queue start with? -1 ... | 2831 |
<p>Please make some comment about this code of QuickSort.</p>
<p>My code is based on the example shown in <a href="http://rads.stackoverflow.com/amzn/click/0070380015" rel="nofollow">this book</a>.</p>
<pre><code>#include <stdio.h>
#include <conio.h>
#include <math.h>
#define SIZE 12
struct StackI... | [] | [
{
"body": "<p>You've implemented your own stack. C has a perfectly good stack, so don't make your own. Use recursive functions.</p>\n\n<p>\"Scan\" means to look for something, but you modify the list while scanning. Its not a good name for the function</p>\n\n<p>\"GetFinalPosition\" begins with Get which usuall... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-06T16:48:55.543",
"Id": "2834",
"Score": "1",
"Tags": [
"c",
"quick-sort"
],
"Title": "C: QuickSort following the book \"Schaum's Outlines\""
} | 2834 |
<p>I have over 300 questions that I plan to include in the program. The flow is pretty much like this:</p>
<ul>
<li>Create a window with the question</li>
<li>Store answer in variable</li>
<li>Create NEW window with question</li>
<li>Store NEW answer</li>
</ul>
<p>(This continues on for over 300 questions.)</p>
<p>I... | [] | [
{
"body": "<pre><code>import wx\n\na1 = ['Apples', 'Bananas', 'Strawberries', 'Watermelon',\n \"Don't remember\", 'None of the above']\n\na2 = ['No', 'Yes']\n\na4 = ['No', 'Yes']\n</code></pre>\n\n<p>The Python style guide recommend ALL_CAPS for global constants.</p>\n\n<pre><code>class Fruit(wx.Frame):\n\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-06T22:36:17.373",
"Id": "2837",
"Score": "2",
"Tags": [
"python",
"wxpython"
],
"Title": "Questionnaire program using many wxPython windows"
} | 2837 |
<p>I was thinking of building a F/OSS project as a cPanel for Ubuntu Server, since Ubuntu doesn't have this, and yet making it easy for a hosting company to use this, where users will find it just as intuitive as cPanel.</p>
<p>Trouble is, PHP web pages on Ubuntu run as <code>www-data</code>, and lots of senior PHP gu... | [] | [
{
"body": "<p>I'd say: go run a <a href=\"http://www.php.net/gearman\" rel=\"nofollow\">gearman</a> daemon as the correct user, and set some gearman workers as priviliged users up with something like <a href=\"http://www.supervisord.org\" rel=\"nofollow\">supervisord</a>. Both are in the Debian packages, so I a... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-07T05:01:48.173",
"Id": "2841",
"Score": "2",
"Tags": [
"php",
"security",
"bash",
"shell"
],
"Title": "Concept for PHP Controlled, Privileged Execution (for a cPanel knockoff on... | 2841 |
<p>I found a example of Java PostMethod <a href="http://www.java2s.com/Code/Java/Apache-Common/HttppostmethodExample.htm">here</a>.</p>
<p>But I want to post several times by using for loop. I made it like this.</p>
<pre><code>
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.Http... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-07T18:19:46.767",
"Id": "4398",
"Score": "4",
"body": "for (String s in parameters)? Is it supposed to compile? And don't swallow exceptions, report them."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T... | [
{
"body": "<p>I think this pattern of creating an instance, running it through the loop, and at the end of the loop re-initializing it, is a bad one. This case is a good example of what can go wrong... because you have introduced a bug as a result</p>\n\n<p>The first time through the loop your <code>method</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-06-07T09:07:22.910",
"Id": "2842",
"Score": "5",
"Tags": [
"java"
],
"Title": "Java using PostMethod multiple times"
} | 2842 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.