body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I've written some code to do the job for me. The final results seems to work fine, but I would like to know if this is how I should Handle classes. And where I can improve or things which are just plain stupid.</p>
<pre><code>class CInit
{
public:
CInit();
~CInit();
void Check(bool);
virtual bool ... | [] | [
{
"body": "<p>I am sorry but at the moment it is not really clear what are you trying to achieve with this code. Why do you need such confusing initialization scheme? What is CRaPE class and what it's got to do with the rest of the code?</p>\n\n<p>Also, according to C++ rules identifiers beginning with an under... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-21T21:24:11.303",
"Id": "4294",
"Score": "7",
"Tags": [
"c++"
],
"Title": "C++ Class wrapper on top of WinMain/DllMain"
} | 4294 |
<p>Any idea on how to run application continuously? I tried follow suggestions from <a href="https://stackoverflow.com/questions/593273/run-application-continuously">this link</a>, but to no avail. It might be because of my coding but I don't know how to amend it. Someone suggested that I use Windows Service, but I don... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-22T02:51:36.697",
"Id": "6427",
"Score": "0",
"body": "\"I tried follow suggestion from this link Run Application Continuously but unsuccessfully...\" what is 'unsuccessful'? Is it exiting early or not doing what you intended?"
},
... | [
{
"body": "<p>Your loop doesn't work because the initial value for <code>exitFlag</code> variable (which is used as condition for the loop) is zero, and it is only being set to 1 under a special set of circumstances which apparently doesn't happen when you run an application.</p>\n\n<p>If you really want to loo... | {
"AcceptedAnswerId": "4300",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-22T01:59:36.433",
"Id": "4296",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Running an application continuously"
} | 4296 |
<p>Is there any way to refactor this?</p>
<pre><code>objLeadTimeReportResult =
(from prop in propList
join book in booking on prop.PropertyId equals book.PropertyId into j
from book in j.DefaultIfEmpty()
group book by new { prop.PropertyId, prop.PropertyName } into groupedLeadTime
select n... | [] | [
{
"body": "<p>(1). You can create an exntession method to check that item is within the range.</p>\n\n<p>(2). I'd use Count instead of Sum because you just count the number of days in specified interval. It's more natural.</p>\n\n<p>(3). I'd check performance of this query and try to cache result of this join a... | {
"AcceptedAnswerId": "4303",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-22T08:35:09.543",
"Id": "4302",
"Score": "4",
"Tags": [
"c#",
"linq"
],
"Title": "Refactoring after grouped in Linq"
} | 4302 |
<p>This is from a flex app that is for quizzing. It calls the database for the question and then checks to see if it has been tagged (bookmarked) by a user already. "Question" is a value object and "Tag" is also a value object.</p>
<p>I just wanted to post it to see how it could be better. It works fine, but I feel th... | [] | [
{
"body": "<p>You could combine your two SQL queries so you don't have to hit the database twice.</p>\n\n<p>The new SQL statement would be something like this:</p>\n\n<pre><code>SELECT\n q.id, q.question_number, q.chapter_id, q.section_id, \n q.question_txt, q.answers, q.feedbacks, q.correct_answer, \n ... | {
"AcceptedAnswerId": "4318",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-22T10:21:35.807",
"Id": "4304",
"Score": "3",
"Tags": [
"php",
"mysqli",
"quiz"
],
"Title": "Flex app for quizzing"
} | 4304 |
<p>I have 3 objects and 3 models. The note, have many tags, and every tags must have one note. So, I have a <code>note_tag_list</code> to store the tags and notes relationship. </p>
<p>The program creates a note, with some tags. </p>
<p>First, I create a note object, and put it into the model. And I get back the obje... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-22T12:21:44.197",
"Id": "6443",
"Score": "0",
"body": "I started to give it a try, but not knowing your objects and return types/values, its pretty much impossible. There are a few things I can spot straight away (like setting a var to... | [
{
"body": "<p><strong>This:</strong></p>\n\n<pre><code>//set the object information\n$user_id =get_current_user_id();\n$title =$this->input->post('ui_title_input');\n$content_url =$this->input->post('ui_url_input');\n$content =$this->input->post('ui_textarea');\n$... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-22T11:29:54.613",
"Id": "4306",
"Score": "3",
"Tags": [
"php",
"codeigniter"
],
"Title": "Relationship between notes and tags"
} | 4306 |
<p>I'm a hobby programmer and have started 2 month ago with C++. I had some knowledge of Python, and I learned it all through Internet tutorials.</p>
<p>I'm looking for your help, since I don't have a tutor I would like to have a comment about my programming style. I used this small "library" to create the Snake4D g... | [] | [
{
"body": "<p>Very good.</p>\n\n<p>Couple of points:</p>\n\n<p>I would remove the set() method, and allow its work to be done by the operator[]. To do this you need return the value you want by reference.</p>\n\n<pre><code>double & operator[](unsigned int i);\n // ^^^ Return double by reference.\n</code... | {
"AcceptedAnswerId": "4333",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-22T17:34:23.390",
"Id": "4311",
"Score": "4",
"Tags": [
"c++",
"beginner",
"computational-geometry"
],
"Title": "Small 3D and 4D vector utilities"
} | 4311 |
<p>I've got this working JavaScript (example is [here][1]), which should work the same as on the Stack Exchange network.</p>
<p>How can I simplify it a bit? </p>
<pre><code>function yellow() {
return 'rgb(255, 255, 0)';
}
$(function() {
$(".post-upvote").click(function() {
// ajax(url + "upvote/" + $... | [] | [
{
"body": "<p>Get rid of antipatterns like</p>\n\n<pre><code>parseInt(1)\n</code></pre>\n\n<p>Just say <code>1</code> instead.</p>\n\n<p>Factor out common code like</p>\n\n<pre><code>$(this).parent().children('.post-votes')\n</code></pre>\n\n<p>and</p>\n\n<pre><code>$(this).css('background-color')\n</code></pre... | {
"AcceptedAnswerId": "4313",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-22T17:40:47.387",
"Id": "4312",
"Score": "4",
"Tags": [
"javascript",
"jquery"
],
"Title": "Simplifying up/down vote code"
} | 4312 |
<p>i'm currently writing a generic data access object for the persistent entities I have to handle in my JavaEE application. What this codeReview is about is a findByExample method that is used to find database entries on the basis of a given example object. This may already be implemented for openJPA but I'm bound to ... | [] | [
{
"body": "<p>I found the code an interesting read and quite a pleasant one at that. Nothing really critical jumped out thought there are some precondition checking, logging, style and other violations in respect to what I might do. </p>\n\n<p>1) I like to abstract trivial things away. For example, when you cre... | {
"AcceptedAnswerId": "4323",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-22T19:16:38.180",
"Id": "4314",
"Score": "3",
"Tags": [
"java",
"reflection",
"lookup"
],
"Title": "Method to lookup persistent entities by an example object"
} | 4314 |
<p>This is my first script in object-oriented JavaScript (jQuery 1.5.2). Its purpose is to simply validate a form (nothing fancy at the moment just checks if any value is present on required fields) and if validation is passed it submits the form via Ajax and alerts the server's response.</p>
<p>It would be great if m... | [] | [
{
"body": "<p>Its only a small Quibble with your code but I find the naming of <code>formObj</code> a little odd. For me I see this as a <code>FormValidator</code> or <code>FormExtender</code> or some such.</p>\n\n<p>Another point would be the <code>for(i in ....)</code> should be <code>for(var i in ...)</code>... | {
"AcceptedAnswerId": "4332",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-23T04:32:03.053",
"Id": "4321",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"object-oriented",
"ajax"
],
"Title": "Validating a form and alerting the server if passed"
} | 4321 |
<p>Question: What are peoples preferences between the two methods of creating an object (in C# in particular) and setting other fields (that may not be given values during construction)? Are either of them considered best practice? or is it down to the programmer and any styling conventions in place at the company?</p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-23T10:27:50.090",
"Id": "6460",
"Score": "0",
"body": "As a mostly java developer I find it confusing that lazy and standard is considered as styles. I figure that this is because there's something C# provides that I'm not familiar wit... | [
{
"body": "<p>The method you call here \"constructor\" is not the proper \"constructor way\" to initialize an object. That said, by my experience, most if not all people prefer initialization by constructor, but I mean not the one shown by you. The constructor should take the values for initialization as parame... | {
"AcceptedAnswerId": "4330",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-23T09:38:14.163",
"Id": "4325",
"Score": "14",
"Tags": [
"c#",
"constructor"
],
"Title": "Styles: \"object initializer\" vs \"constructor\" object creation"
} | 4325 |
<p>I've been practicing using BSP trees as I hear they are a good start to create procedural spaces such as houses.</p>
<p>For ease-of-deployment purposes, I've tested this code in Lua and it seems to work. However, I want to confirm if I did what I needed to do instead of something else. When I am sure this works I ... | [] | [
{
"body": "<p>Your principal algorithm is a correctly implemented BSP, so yes. You are creating a Binary Space Partitioning tree.</p>\n\n<p>Also, FWIW: You only need two points on opposing corners to define an axis aligned rectangle which you seem to be using here. So you could simplify. </p>\n\n<p><strong>Edit... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-23T15:14:34.863",
"Id": "4334",
"Score": "13",
"Tags": [
"tree",
"lua",
"computational-geometry",
"clustering"
],
"Title": "Is this a BSP tree? Am I missing something?"
} | 4334 |
<p>I'm new to python but not to programming in general. This is my <a href="https://github.com/hemmer/pyDLA" rel="nofollow">first project</a> beyond the basics.</p>
<p>I was wondering if I could get some feedback on the code in general, in particular on any bad Java/C++ habits I might be dragging along.</p>
<p>I have... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-23T16:30:22.693",
"Id": "6483",
"Score": "1",
"body": "Welcome to the Code Review stack. You are asking the kind of question this stack was designed for, but you need to include a reasonable amount of the code in your question. Pleas... | [
{
"body": "<ol>\n<li>Use of global variables is frowned upon. You should probably define a class, and hold the data as attributes on it.</li>\n<li>Don't put logic at the module level, i.e. your main for loop. That is better placed inside of a main() function</li>\n<li>In your diff, you use python's sum rather t... | {
"AcceptedAnswerId": "4338",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-23T16:23:12.167",
"Id": "4336",
"Score": "7",
"Tags": [
"python",
"numpy"
],
"Title": "Code Review of small scientific project, particuarly array vs. list perform"
} | 4336 |
<p>I've written this bit of JavaScript to just learn basics of drawing on/interacting with the HTML5 canvas element.</p>
<p>Just want to make sure I'm doing things "correctly" in case I have any glaring code gaffs or there's a more efficient way.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-conso... | [] | [
{
"body": "<p>This looks pretty good. In your <code>start</code> function, the <code>canvas</code> variable should be declared with a var; implicit globals are one of the Worst Parts.</p>\n\n<pre><code>function start()\n{\n var canvas = document.getElementById(\"area\");\n\n // ...\n}\n</code></pre>\n\n<p... | {
"AcceptedAnswerId": "4356",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-23T20:25:24.207",
"Id": "4341",
"Score": "1",
"Tags": [
"javascript",
"html",
"html5",
"canvas"
],
"Title": "Basic HTML5 Canvas/Javascript testing"
} | 4341 |
<p><strong>Example 1</strong></p>
<pre><code>if (myList.ContainsKey(myKey))
{
myList[myKey]++;
}
else
{
myList.Add(myKey,1);
}
</code></pre>
<p><strong>Example 2</strong></p>
<pre><code>Where(x =>
(myList.ContainsKey(x.Key) ? x.Value - myList[x.Key] : x.Value) >
</code></pre>
<p><code>myList</code> ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-23T23:18:13.593",
"Id": "6501",
"Score": "1",
"body": "Are these two snippets supposed to be doing the same thing?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-24T22:48:29.267",
"Id": "6545",
"Sc... | [
{
"body": "<p>For example, you can write your own extenession method for this operation and use it everywhere. Something like this</p>\n\n<pre><code>public static void SetOrIncrement<K>(this Dictionary<K, int> dictionary, K key)\n {\n int value;\n if (dictionary.TryGetValue(key, out... | {
"AcceptedAnswerId": "4348",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-23T22:19:10.663",
"Id": "4342",
"Score": "8",
"Tags": [
"c#",
"hash-map"
],
"Title": "Any way of simplifying the following two short snippets regarding Dictionary?"
} | 4342 |
<p>This seems like rather too much nesting:</p>
<pre><code>using (XmlReader reader = XmlReader.Create(filename))
{
while (reader.Read())
{
if (reader.IsStartElement())
{
switch (reader.Name)
{
case "Width":
map.Width = ParseXMLValue(re... | [] | [
{
"body": "<p>Yes, much. <code>XDocument</code> is the easier way. Though it does not perform as well if your documents are of significant size or performance is absolutely imperative:\n<a href=\"http://www.nearinfinity.com/blogs/joe_ferner/performance_linq_to_sql_vs.html\">http://www.nearinfinity.com/blogs/joe... | {
"AcceptedAnswerId": "4345",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-23T22:21:55.730",
"Id": "4343",
"Score": "3",
"Tags": [
"c#",
"xml"
],
"Title": "Reading XML in C#"
} | 4343 |
<p>Running the same test 10,000 times with cProfile tells me that most of the damage happens in the count() function. This is my attempt at a solution to the Quadrant Queries challenge from InterviewStreet (the problem statement can be found <a href="http://pastie.org/2420315" rel="nofollow">here</a>). </p>
<p>Accordi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-24T05:09:12.513",
"Id": "6508",
"Score": "0",
"body": "Add the code from pastie here that is relevant and also be specific about what you need help with. http://codereview.stackexchange.com/questions/how-to-ask"
},
{
"ContentLi... | [
{
"body": "<p>to optimise your count try:</p>\n\n<pre><code>def count(i, j, coordinates):\n quad_one, quad_two, quad_three, quad_four = 0, 0, 0, 0\n current_coordinates = coordsinates[i-1:j]\n\n for pair in current_coordinates:\n x, y = pair[0], pair[1]\n ...\n</code></pre>\n\n<p>And see ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-24T03:42:45.227",
"Id": "4347",
"Score": "2",
"Tags": [
"python",
"optimization",
"performance",
"programming-challenge"
],
"Title": "Quadrant Queries challenge"
} | 4347 |
<p>I have an abstract class which holds a hook method for a template method. Not all classes which extend this class will need to implement this method (in fact most will not, but a few will). As such I declared the method this way:</p>
<pre><code>protected void applyExtraCriteria(Object extraCriteria) {
}
</code><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T00:51:19.130",
"Id": "6558",
"Score": "3",
"body": "As a rule you really should never implement an empty method in any class. If you want the method available to consumers of the abstract classes inheritors, declare it abstract. If ... | [
{
"body": "<p>I would declare as required by all classes. It is easy enough to leave an empty method stub in the sub class.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-24T18:32:49.100",
"Id": "4363",
... | {
"AcceptedAnswerId": "4379",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-24T18:18:18.313",
"Id": "4362",
"Score": "8",
"Tags": [
"java",
"object-oriented"
],
"Title": "Empty method in abstract class"
} | 4362 |
<p>I recently discovered/came across <a href="/questions/tagged/linq" class="post-tag" title="show questions tagged 'linq'" rel="tag">linq</a> and have been trying to learn and utilize its features. Here's my first function <code>UpdateTransactionsData()</code>. This method is for a <code>PurchaseDocument</code... | [] | [
{
"body": "<p>I don't see any problem with the LINQ you have.</p>\n\n<p>If you wanted, you could use a little bit of LINQ to get rid of that foreach loop you have. You can create two LINQ queries to query the Items collection, group accounts/items together, and return the sum of the Amounts/Quantities as a Dic... | {
"AcceptedAnswerId": "4367",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-24T18:35:32.790",
"Id": "4364",
"Score": "6",
"Tags": [
"c#",
"linq",
"finance"
],
"Title": "Determining which accounts are to be credited/debited"
} | 4364 |
<p>Sometimes, I need to map from a Domain entity to a ViewModel - to display information.</p>
<p>Other times, I need to map from a ViewModel to a Domain entity - for persistance of data.</p>
<p>Is this kosher or does this code smell?</p>
<pre><code>protected void Application_Start()
{
AreaRegistration.RegisterA... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T01:01:23.343",
"Id": "6560",
"Score": "1",
"body": "I am thoroughly unfamiliar with this mapper stuff, I'm guessing based on the route things I see this is a part of the asp.net mvc which I haven't worked with. That said, even to my... | [
{
"body": "<p>Mapping to and from domain models and view models is exactly what automapper is designed for.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-14T14:25:31.213",
"Id": "4816",
"ParentId": "43... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2011-08-24T20:44:39.673",
"Id": "4369",
"Score": "4",
"Tags": [
"c#",
"automapper"
],
"Title": "Using AutoMapper to map to and from"
} | 4369 |
<p>I've written the following small helper class for use in my WPF applications. It comes up from time to time that I need to display message boxes, or otherwise interact with the UI from a non UI thread.</p>
<pre><code>public static class ThreadContext
{
public static InvokeOnUiThread(Action action)
{
... | [] | [
{
"body": "<p>anonymous methods to the rescue! I saw somebody griping about this syntax recently on a blog and found it unfortunate they were dissimenating this. The cleaner new and happy way to define a delegate, is quite simply:</p>\n\n<p>The method signature without a name or types, so for example:</p>\n\n<p... | {
"AcceptedAnswerId": "4375",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-24T21:25:15.223",
"Id": "4371",
"Score": "3",
"Tags": [
"c#",
"multithreading",
"wpf"
],
"Title": "Helper methods for working with the WPF Dispatcher"
} | 4371 |
<p>Does my code contain anything invalid?</p>
<pre><code><form name="myForm" id="myForm">
<table id="myTab">
<tr>
<td>
<label for="id">User ID:</label>
<input type="text" id="id" />
</td>
</tr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T05:25:52.130",
"Id": "6566",
"Score": "2",
"body": "Put your [URL here](http://validator.w3.org/). It will validate the page."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T06:37:58.693",
"Id": "... | [
{
"body": "<p>Mostly. According to <a href=\"http://validator.nu/\" rel=\"nofollow\">http://validator.nu/</a>:</p>\n\n\n\n<blockquote>\n<pre class=\"lang-none prettyprint-override\"><code>Warning: A table row was 2 columns wide and exceeded the column count established by the first row (1).\nFrom line 16, colu... | {
"AcceptedAnswerId": "4378",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-24T21:43:23.930",
"Id": "4372",
"Score": "5",
"Tags": [
"html",
"html5",
"form"
],
"Title": "Is this password-submission form valid?"
} | 4372 |
<p>In order to secure my page SESSIONS I have the following pages.</p>
<p>My questions are</p>
<ol>
<li>Am I over-reacting with this?</li>
<li>Should I place the token in login.php instead of the loginForm.php ? </li>
<li>When a user logins, I save his IP in the DB. Should I make use of this in authentication ?</li>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T19:19:01.297",
"Id": "6587",
"Score": "0",
"body": "It is not good to base your logins on IP. They change often for a large group of users. It's better to watch for **user patterns** and if the IP doesn't change for 6 requests - the... | [
{
"body": "<p>1) Overreacting is a question of how valueable your protected information is. My personal oppinion is that by the nature of digital computers and of the internet there is no such thing as overreacting in security. You either want something to be public or you do not, and in the latter case there i... | {
"AcceptedAnswerId": "4381",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T03:11:22.450",
"Id": "4376",
"Score": "2",
"Tags": [
"php",
"security"
],
"Title": "Am I over-reacting with my page SESSIONS security?"
} | 4376 |
<p>I'm currently making a manga (read: comic) viewer in Python. This project has been a code-as-you-learn project, because I have been trying to code this as I learned about Tkinter. Python I have known for some time, but not too long.</p>
<p>Performance-wise, I'm worried about the image loading and resizing time; it ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-13T10:57:16.363",
"Id": "7170",
"Score": "1",
"body": "I think you post to the wrong community. This community concentrates on \"code quality\" issues, rather than on a \"functional issues\" of the code. Try to find more appropriate pl... | [
{
"body": "<p>As Moisei pointed out, Code Review isn't about functional issues. I guess performance can be discuted, but I don't know how to make resizing fast.</p>\n\n<p>Your code looks good overall, but I don't know about Tkinter idioms. Here are a few comments:</p>\n\n<ol>\n<li><p>You should check <code>if _... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T04:59:26.760",
"Id": "4377",
"Score": "16",
"Tags": [
"python",
"performance",
"image",
"tkinter"
],
"Title": "Python Manga Image Viewer"
} | 4377 |
<p>If you were given the following:</p>
<pre><code>#include <cassert>
struct vec {
float x,y,z;
vec(float x, float y, float z) : x(x), y(y), z(z) {}
};
int main() {
float verts[] = {1,2,3,4,5,6,7,8,9}; // length guaranteed to be a multiple of 3
assert(sizeof(vec) == sizeof(float) * 3);
// ... | [] | [
{
"body": "<p>I'd say, use the last one until this prooves to by a performance problem (which I highly doubt). \nAlso, be aware that the first two solution would modify the array, should the following code modify <code>a</code>.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
... | {
"AcceptedAnswerId": "4402",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T13:12:40.593",
"Id": "4384",
"Score": "4",
"Tags": [
"c++",
"casting"
],
"Title": "Coding Practice - Float* -> Vector3* cast"
} | 4384 |
<p>I was looking for advice, feedback and information on best practices when designing ASP.NET Web Forms in a .NET web application. </p>
<p>Allow me to post a sample of how I currently do things. I am omitting the ASPX page as it only has 2 textboxes and a button. PersonEntity validates, loads, and saves in this examp... | [] | [
{
"body": "<p>This is my feedback, Please let me know if I am misinterpreting :</p>\n\n<p>1) Storing the entire PersonEntity object in viewstate will have following problems</p>\n\n<ul>\n<li>It will make viewstate heavy and thus make page load slower.</li>\n<li>It may not represent the current state of the obje... | {
"AcceptedAnswerId": "5139",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-23T15:28:56.890",
"Id": "4386",
"Score": "7",
"Tags": [
"c#",
"asp.net"
],
"Title": "Workflow and Design Feedback on an Add / Edit Form"
} | 4386 |
<p>There's things I know about JavaScript and jQuery, and things I don't. I know that this works, gets and stores what I want so that, when I need to do stuff, I don't have to wait for it. Functionally, I like this. But I'm the only JavaScript guy in my shop, and so I don't see JavaScript I didn't write all that often.... | [] | [
{
"body": "<p>Let me start with few common observations.</p>\n\n<p>It's better to generate a complete DOM element before you attach it to DOM tree (add to page) if you can, because it tends to be faster. For example setting its text after can trigger another reflow. Do it often enough and it start to matter. No... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T15:35:04.210",
"Id": "4388",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"ajax",
"jquery-ui"
],
"Title": "Addition of accession analysis stubs to new requests and accessio... | 4388 |
<p>My colleague did some code Optimise work.</p>
<p>Code below is from a public method of a public class (NOT STATIC CLASS OR METHOD)</p>
<p>code before:</p>
<pre><code> Bitmap btMap = new Bitmap(Convert.ToInt32(WebConfig.StatsOpenEmailImageWidth), Convert.ToInt32(WebConfig.StatsOpenEmailImageHeight),... | [] | [
{
"body": "<p>Absolutely, the 2nd example is the way to ensure disposable objects/resources are released for the GC. The <code>using</code> clause does this by enforcing the rule that the object being created must inherit from <code>IDisposable</code>. At the closing '}' of each using block, the object is dispo... | {
"AcceptedAnswerId": "4390",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T15:48:18.723",
"Id": "4389",
"Score": "3",
"Tags": [
"c#",
"memory-management"
],
"Title": "Does this I/O operation caused a memory leak"
} | 4389 |
<p>I'm developing a log-on page where users either select or create an associated organization when they sign up. There can be either 1 user per organization or many users per organization, this is specified at runtime via web.config. </p>
<p>I have a separate project that handles all user account creation. I don't ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T18:26:08.543",
"Id": "6585",
"Score": "0",
"body": "+1 Perfect question for the site, which will help inform future developers about where boundaries between modules should be."
}
] | [
{
"body": "<p>Since you actually have a business layer, that's where I'd put it. You should let the business layer handle the finding/creating of an organization, so all the WebForms code needs to do is ask for an <code>IpasLogOnManagement.IpasOrganization</code> object based on the name the user selected (<co... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T16:34:05.733",
"Id": "4392",
"Score": "4",
"Tags": [
"c#",
"asp.net"
],
"Title": "Should this code be in the code behind or separate class?"
} | 4392 |
<p>I have a few different classes in my application, but this specific class is the one I'm interested about. Please review for good practices and potential problems.</p>
<pre><code>using ExactEarth.Utilities.Jaguar.Properties;
using System;
using System.Data;
using System.Data.SqlClient;
using System.IO;
public clas... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T16:59:52.403",
"Id": "6580",
"Score": "1",
"body": "If youd like us to analyse the classes, maybe dont post all the irrelevant code. Just represent the objects as such."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDa... | [
{
"body": "<p>First off, might I suggest some reading material? <a href=\"http://en.wikipedia.org/wiki/SOLID\">SOLID OOP Design Principles</a></p>\n\n<p>Now, onto your code. Two things jump out at me. Your class is easy to misuse, and you're attempting to do too many things with a single class.</p>\n\n<p>1 Easy... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T16:52:23.657",
"Id": "4394",
"Score": "7",
"Tags": [
"c#",
"object-oriented",
"classes"
],
"Title": "New to OOP; is this a good class design?"
} | 4394 |
<p>Profiling shows <code>MoveNext</code> takes most time, which I guess is true as it is lazy. But I don't know in what direction I could improve the code. (Open pic in new tab would allow u see bigger chart.)</p>
<p><img src="https://i.stack.imgur.com/YjUsA.jpg" alt="enter image description here"></p>
<pre><code> ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T20:57:53.490",
"Id": "6589",
"Score": "0",
"body": "and who knows how does the 50.54-20.32=30.2% come from? weird"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-26T01:44:40.700",
"Id": "6598",
"... | [
{
"body": "<p>I believe there is the the problem with MoveNext() from enumerator which is returned from MixedBlock(). Its MoveNext() just does a lot of lazy processing but doesn't cache results at all.</p>\n\n<p>(1). When you iterare over the result from the <code>MixedBlock()</code> your iterate with help of t... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T19:35:23.720",
"Id": "4400",
"Score": "6",
"Tags": [
"c#"
],
"Title": "plz help optimize the small code snippet, VS2010 profiling chart provided"
} | 4400 |
<p>I created this class that connects to Gmail contacts, and enables you to add/edit/delete the contact. </p>
<p>I'm curious to see what others think of my code. If you see any areas for improvement, that would be awesome!</p>
<ol>
<li>The <code>contact[]</code> is purely for testing.</li>
<li>I also realize that it... | [] | [
{
"body": "<p>A few things to point out:</p>\n\n<hr>\n\n<blockquote>\n<pre><code> $feed = $this->gdata->getFeed($query);\n return $feed;\n</code></pre>\n</blockquote>\n\n<p>You can just <code>return</code> feed directly without initialising it.</p>\n\n<hr>\n\n<blockquote>\n<pre><code>public ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-25T21:31:05.760",
"Id": "4404",
"Score": "7",
"Tags": [
"php",
"email",
"zend-framework",
"google-contacts-api"
],
"Title": "Gmail contacts API connection"
} | 4404 |
<p>This may be a naive question, but what are the dangers of the following code (allocate more memory in the new operator for the info struct)?</p>
<pre><code>struct Info
{
Info():nLineNo(0){memset(cFile, 0, 256);}
~Info(){}
char cFile[256];
unsigned int nLineNo;
};
void *operator new... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-26T12:30:59.720",
"Id": "6610",
"Score": "0",
"body": "Yes. Put that code in a constructor."
}
] | [
{
"body": "<p>You are not overloading the new operator correctly.</p>\n<p>See: <a href=\"https://stackoverflow.com/q/7194127/14065\">How should I write ISO C++ Standard conformant custom new and delete operators?</a></p>\n<p>But you should not be overloading new at all.\nAll the work you are doing here is stuff... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-26T12:25:00.517",
"Id": "4412",
"Score": "5",
"Tags": [
"c++",
"memory-management"
],
"Title": "Overloading the new operator"
} | 4412 |
<p>I have this JavaScript function which gets prices from a table, adds them up, and outputs the total cost. I want to refactor this to make it as small as possible. </p>
<pre><code>function getTotalPrice(do_request)
{
console.log('Get total price');
var prices_array = new Array(); // Where our prices are held
// Fo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-26T23:47:57.123",
"Id": "6626",
"Score": "1",
"body": "Guard statement anytime you have a statement block (anything in `{}`) where the entire body is an if, reverse the condition of the if and return inside of it, then you don't need t... | [
{
"body": "<p>First, I would switch from using eval to parseFloat, since it appears that eval provides no extra features and allows arbitrary code to be executed unless you just happen to have values other then numbers in total_item_price tds. </p>\n\n<p>Second, since you are performing no extra processing with... | {
"AcceptedAnswerId": "4416",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-26T15:27:39.033",
"Id": "4415",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Displaying total cost of prices from a table"
} | 4415 |
<p>I'm using this little macro a lot:</p>
<pre><code>#define RUN_ONCE(runcode) \
{ \
static bool code_ran = 0; \
if(!code_ran){ \
code_ran = 1; \
runcode; \
} \
}
</code></pre>
<p>I find it useful when I want to initialize stuff just once when I don't really care about performance (for ex... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-12-21T15:53:56.380",
"Id": "283236",
"Score": "2",
"body": "Note that since C++11 `magic statics` guarantees that a static value in function scope will be initialised exactly once even in the presence of multiple threads. `static int resu... | [
{
"body": "<p>It is not thread safe. You can use <a href=\"http://www.boost.org/doc/libs/1_47_0/doc/html/thread/synchronization.html#thread.synchronization.once\" rel=\"noreferrer\">Boost</a>, or standard C++11 <a href=\"http://en.cppreference.com/w/cpp/thread/call_once\" rel=\"noreferrer\"><code>std::call_onc... | {
"AcceptedAnswerId": "4423",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-27T00:13:27.237",
"Id": "4422",
"Score": "12",
"Tags": [
"c++",
"macros"
],
"Title": "Macro to run code once during the lifetime of the program"
} | 4422 |
<p>This is a page that allow user to do register:</p>
<pre><code><?php echo form_open('user/valid_register_page', 'autocomplete="off"');?>
<?php $this->table->set_template(array('table_open'=>'<table class="table_form_register">'));
$this->table->add_row(form_label($label_email.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-31T15:32:43.890",
"Id": "6745",
"Score": "0",
"body": "Try to avoid mixing PHP and HTML. See this for some advice: http://stackoverflow.com/questions/62617#95027"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011... | [
{
"body": "<p>You could start by removing dynamic HTML generation where there is no benefit in it. You would be much better of writing something like this :</p>\n\n<pre><code><?php\n $form = $this->form;\n?>\n<form action=\"<?php echo $form->get_destination(); ?>\" method=\"post\">\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-27T04:17:26.480",
"Id": "4424",
"Score": "4",
"Tags": [
"php",
"html",
"codeigniter",
"layout"
],
"Title": "Web register form"
} | 4424 |
<p>I wrote this program which finds the definite integral of a function. Where in the program could I optimize this code:</p>
<pre><code>def trapezium(f,n,a,b):
h=(b-a)/float(n)
area = (0.5)*h
sum_y = (f(0)+f(b))
i=a
while i<b:
print i
sum_y += 2*f(i)
i += h
area *... | [] | [
{
"body": "<p>First, there is an error where you have:</p>\n\n<pre><code>sum_y = (f(0)+f(b))\n</code></pre>\n\n<p>f(0) should be f(a). It doesn't matter on your example, because you start with 0, but would otherwise.</p>\n\n<p>Another error is that you add f(a) 3x instead of just once. i=a+h should be the line ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-27T07:46:22.863",
"Id": "4426",
"Score": "2",
"Tags": [
"python"
],
"Title": "finding definite integrals in Python using Trapezium rule"
} | 4426 |
<p>Imagine a UTF-8 decoder that takes a list of bytes and returns human-readable code points like: </p>
<pre><code>> (utf-8->human-readable-code-points '(32 32 195 160 160))
("u+0020" "u+0020" "u+00E0" ("Error: trailing byte without preceding start byte" 160))
</code></pre>
<p>This list builder functionality is... | [] | [
{
"body": "<p>Wow, so sorry I missed seeing this question! (Normally I get emails when someone posts something tagged with <a href=\"/questions/tagged/scheme\" class=\"post-tag\" title=\"show questions tagged 'scheme'\" rel=\"tag\">scheme</a>, but didn't see this one till now. :-()</p>\n\n<p>So, the idiomatic w... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-27T08:56:10.660",
"Id": "4428",
"Score": "3",
"Tags": [
"scheme"
],
"Title": "A list builder or list accumulator"
} | 4428 |
<p>For a messenger program I am writing a <code>Server</code> class that will run a non-blocking server in one thread. A messenger thread will use this server thread to communicate with other clients.</p>
<h3>What the server should do</h3>
<ul>
<li>Accept connections from / connect to other instances of the server an... | [] | [
{
"body": "<p>I have little experience with networking, so I cannot criticize the logic itself, alas. I have some minor remarks on the form, though:</p>\n\n<ul>\n<li>It is controversial because you will find some people proponent of this style, but I personally (and it is shared by many people!) avoid to use <c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-27T11:23:55.213",
"Id": "4432",
"Score": "2",
"Tags": [
"java"
],
"Title": "Simple Server for messenger"
} | 4432 |
<p>So the way I understand this code I wrote, it is thread safe, as long as the retrievers and depositors are thread safe. The only bad state I could see occurring is that a thread is using a retriever as a method local while another thread calls RefreshDependencies(), which would mean the thread with it as a method lo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-27T17:28:00.680",
"Id": "6632",
"Score": "1",
"body": "*'it is thread safe, as long as the retrievers and depositors are thread safe.'* ...the class is either thread-safe or it isn't, IMO ;)"
},
{
"ContentLicense": "CC BY-SA 3.... | [
{
"body": "<p>First item I see is:</p>\n\n<pre><code>private static object _lockDependenciesManagement;\n</code></pre>\n\n<p>...should be: </p>\n\n<pre><code>private static readonly object _lockDependenciesManagement; \n</code></pre>\n\n<p>I don't see any reason this should/would change.</p>\n\n<p>With the po... | {
"AcceptedAnswerId": "4436",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-27T17:20:57.820",
"Id": "4435",
"Score": "5",
"Tags": [
"c#",
"thread-safety"
],
"Title": "How thread safe is this class?"
} | 4435 |
<p>In this project I've taken my first shot at OO JavaScript, and I'm not sure how it turned out. The script dynamically makes a tooltip with different text if you so choose. As of now it takes <em>a lot</em> to create the tooltip and show it, is there a way to make this smaller?</p>
<p><a href="http://jsfiddle.net/za... | [] | [
{
"body": "<p>Woahhhh, that is a LOT of repetition. You have a lot of similar functionality, all your functions do basically the same stuff:</p>\n\n<ul>\n<li>Create an element</li>\n<li>Set the ID</li>\n<li>Apply styles</li>\n<li>Maybe do something else</li>\n</ul>\n\n<p>You should look into DRYing your code by... | {
"AcceptedAnswerId": "4438",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-27T21:07:45.330",
"Id": "4437",
"Score": "3",
"Tags": [
"javascript",
"dom"
],
"Title": "Dynamic Tooltip Generator"
} | 4437 |
<p><em>FileBro</em> is a basic GUI based File Browser. </p>
<p><img src="https://i.stack.imgur.com/yswnE.png" width="677" height="398"></p>
<h2>FileBro Functionality</h2>
<ul>
<li>Directory tree - shows the file system roots at start-up, but is otherwise built lazily as the user browses around the file system. <em>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T02:02:59.423",
"Id": "6649",
"Score": "0",
"body": "I so far have not been able to reproduce your error. Are there any actions which usually precipitates the problem?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | [
{
"body": "<p>Mac OS X 10.5 and Ubuntu 10.04: Repeated non-fatal NPE on delete.</p>\n\n<p>Addendum: In line 441, <code>findTreePath()</code> always returns <code>null</code>, because <code>currentFile.getParentFile()</code> returns the path to the file, not the file itself. In effect, the path cannot match itse... | {
"AcceptedAnswerId": "4448",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-05-31T01:28:07.810",
"Id": "4446",
"Score": "93",
"Tags": [
"swing",
"java"
],
"Title": "File Browser GUI"
} | 4446 |
<p>Is this a good method to optionally run some code on a background thread depending on a configuration setting? This will primarily be called from an ASP.NET front-end (although others are possible) under Framework 3.5. I'm attempting to keep this as DRY as possible.</p>
<pre><code>Dim sendEmails = Sub()
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-28T17:03:46.373",
"Id": "6678",
"Score": "3",
"body": "In a nutshell.. yes. This is basically spot on, any style points aside, the only other thing I can think is frequently in the context of IIS people tend to use the threadpool inste... | [
{
"body": "<p>Maybe.</p>\n\n<p>Depends, as always, what happens if you get multiple threads running.</p>\n\n<p>So you start this thread going, your code will move on, and if you start this again, and it hasn't finished the previous round of sending emails. What happens?</p>\n\n<p>If its all thread safe, then ... | {
"AcceptedAnswerId": "4467",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-28T16:10:54.817",
"Id": "4452",
"Score": "1",
"Tags": [
"asp.net",
"multithreading",
"vb.net"
],
"Title": "Optionally running some code on a background thread"
} | 4452 |
<p>I'm seeking review comments (design, performance, etc.) based on the problem statement:</p>
<blockquote>
<p>Write a CashWithDrawal function from an ATM which based on user
specified amount dispenses bank notes. Ensure that the following is
taken care of</p>
<ul>
<li>Minimum number of bank notes are dis... | [] | [
{
"body": "<p>(1) API is a bit odd. Why do I need to call some static methods after I instatiated an object and want to use it already? <code>ATM atm = new ATM(amount); ATM.calcTotalCorpus();</code></p>\n\n<p>(2) There is a slight mess with access modifiers. For example, Why protected ? <code>protected int am... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-28T17:30:55.223",
"Id": "4453",
"Score": "5",
"Tags": [
"java",
"performance",
"multithreading",
"homework",
"finance"
],
"Title": "Cash-withdrawal from an ATM"
} | 4453 |
<p>For practice, I am working through some Google Code Jam problems. The code below is for the Milkshakes problem, which is located <a href="http://code.google.com/codejam/contest/dashboard?c=32016#s=p1" rel="nofollow">here</a>.</p>
<blockquote>
<p><strong>Problem</strong></p>
<p>You own a milkshake shop. Ther... | [] | [
{
"body": "<p>Your <code>go()</code> method is <strong>waaaaaaaayyyyyyyyyyyyyy</strong> to long, break it up in digestible parts. Try to think in different abstraction levels, and don't mix them in one method (e.g. you deal with file input directly, but have a separate method for writing into a file). Follow th... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-29T00:37:40.227",
"Id": "4463",
"Score": "3",
"Tags": [
"java",
"programming-challenge"
],
"Title": "Google Code Jam (Milkshakes) solution"
} | 4463 |
<p>What are your thoughts on using an <code>IDisposable</code> to stripe an HTML table like so? It's a blatant abuse of <code>IDisposable</code> but this allows you to use the counter in a <code>using(){}</code> block which gives you a clear block in the markup.</p>
<pre><code>public class StripeCounter : IDisposable
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-30T17:52:41.037",
"Id": "6720",
"Score": "3",
"body": "Why are you striping in custom code instead of using jquery (which comes with MVC3)? It is server side work that you can push down to the client."
},
{
"ContentLicense": "... | [
{
"body": "<p>Don't do the striping on the server. Don't do the striping with JavaScript. Since it's styling, <a href=\"http://dev.opera.com/articles/view/zebra-striping-tables-with-css3/\" rel=\"nofollow\">do the striping with CSS</a>.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-29T08:12:13.843",
"Id": "4470",
"Score": "2",
"Tags": [
"c#",
"asp.net-mvc-3"
],
"Title": "Using IDisposable to stripe a table"
} | 4470 |
<p>Im running a photocontest and making a list of winners with one winner each day. My loop is running very slow. It seams to be the toList() that is time consuming. Any suggestions on how to make it run faster?</p>
<pre><code>foreach (var date in dates)
{
var voteList = _images.Select(image =>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-29T09:39:15.293",
"Id": "6688",
"Score": "0",
"body": "What does `GetFriendlyUrl(image.ID)` do ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-29T12:14:10.137",
"Id": "6691",
"Score": "2",
"bo... | [
{
"body": "<p>The toList() executes everything in the select-clause.\nMy guess is that the votes-collection that you are quering against, without knowing how it operates, is the performance thief. </p>\n\n<p>Try running the example again without setting the Votes-variable. If it runs smoothly, then you know wha... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-29T09:25:26.867",
"Id": "4473",
"Score": "9",
"Tags": [
"c#",
"linq"
],
"Title": "Linq in foreach with c#"
} | 4473 |
<p>I suspect there is a simpler way to find if a <code>select</code> has a certain <code>option</code>, but don't know what. The objective of the following is to check if the desired option exists or not, and if it does, set it as the selected option:</p>
<p><strong>Markup</strong></p>
<pre><code><input type="text... | [] | [
{
"body": "<p>You could try and force the option to be selected. Because jQuery doesn't throw errors when it doesn't have a set of elements, you can use this to your advantage inside an <code>if</code> statement. Couple this with jQuery's chaining and you can do something like:</p>\n\n<pre><code>function setSe... | {
"AcceptedAnswerId": "4477",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-29T11:07:16.700",
"Id": "4476",
"Score": "8",
"Tags": [
"javascript",
"jquery"
],
"Title": "Check if select has a certain option"
} | 4476 |
<p>I've been trying to implement a fast Huffman decoder in order to encode/decode video. However, I'm barely able to decode a 1080p50 video using my decoder. On the other hand, there are lots of codecs in ffmpeg that entropy decode 4-8 times faster.</p>
<p>I have been trying to optimize and profile my code, but I don'... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-29T12:05:25.150",
"Id": "6693",
"Score": "0",
"body": "Have a look at ffmpeg and their solution for inspiration..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-29T12:09:11.720",
"Id": "6694",
"Sc... | [
{
"body": "<p>You seem to work on single bit basis. This is very slow. You have to combine several bits together, look up the appropriate pattern in the table and then continue from there (if necessary) in the tree.</p>\n\n<p>You can see an outline to this solution presented here <a href=\"http://www.gzip.org/a... | {
"AcceptedAnswerId": "4480",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-29T11:51:39.123",
"Id": "4479",
"Score": "12",
"Tags": [
"c++",
"performance",
"compression",
"video"
],
"Title": "Huffman decoding for video"
} | 4479 |
<p>I have been playing around with tables and random colors to generate some mosaic.</p>
<p>As I find it rather slow, tell me how it can be improved in terms of speed.</p>
<pre><code>function generate_mosaic(cols, rows) {
var i, ncol, trans, colspan, style, html;
html += "<table>";
for (i = 0; i &l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-29T23:33:39.397",
"Id": "6710",
"Score": "0",
"body": "I think you're better off using a html5 canvas. $0.02"
}
] | [
{
"body": "<p>I suggest using <code>document.body.innerHTML</code> instead of <code>document.write()</code></p>\n\n<pre><code>document.body.innerHTML = generateMosaic();\n</code></pre>\n\n<p>also put <code>Math.random</code> in a variable so it doesn't have to go back to the math object each time:</p>\n\n<pre><... | {
"AcceptedAnswerId": "4490",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-29T21:45:33.313",
"Id": "4488",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "Generating a mosaic"
} | 4488 |
<p>In our hg workflow we use <code>default</code> as testing branch and <code>stable</code> as the one that contains stable code. All changes are made in feature-branches that are started from latest <code>stable</code>. This hook checks if there is a "direct" commit to <code>default</code> or <code>stable</code> (they... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-30T12:06:23.923",
"Id": "6715",
"Score": "0",
"body": "The correct word is pythonic not pythonish."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-30T12:08:13.743",
"Id": "6716",
"Score": "0",
"... | [
{
"body": "<pre><code> for rev in xrange(repo[node].rev(), len(repo)):\n ctx = context.changectx(repo, rev)\n</code></pre>\n\n<p>In Python, I generally try to avoid iterating using xrange. I prefer to iterate over what I'm interested in.</p>\n\n<pre><code>def revisions(repo, start, end):\n for revi... | {
"AcceptedAnswerId": "4498",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-30T06:57:18.353",
"Id": "4494",
"Score": "5",
"Tags": [
"python"
],
"Title": "My python hook for mercurial"
} | 4494 |
<p>There can be some errors in the script, if u find them thanks, but the main thing is to get useful suggestions about how can I do this better and secure.</p>
<pre><code>ini_set('session.use_only_cookies', true);
session_start();
//Create a random salt value
$salt = 'Hjkhkjh9089&j98098';
$tokenstr = (str) date(... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-30T14:16:03.407",
"Id": "6717",
"Score": "2",
"body": "This is not something you should write yourself. Find an appropriate module OS project where this is already implemented and use it. It is way to easy to add security leaks."
},
... | [
{
"body": "<p>Let's start with the SQL injection vulnerability in your code in </p>\n\n<pre><code>mysql_query(\"SELECT * FROM users WHERE username='$login_username' AND password=SHA1('$login_password')\") or die(\"unable to connect to msql server: \" . msql_error()) ;\n</code></pre>\n\n<p>In this piece of co... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-30T10:29:57.440",
"Id": "4495",
"Score": "1",
"Tags": [
"php"
],
"Title": "please check my user session login system and tell me what can be done to make it better"
} | 4495 |
<p>I currently have this encoding function which simply subtracts one from each character code:</p>
<pre><code>String.fromCharCode.apply(null, text.split("").map(function(v) {
return v.charCodeAt() - 1;
}));
</code></pre>
<p>E.g. <code>test</code> becomes <code>sdrs</code>.</p>
<p>I know that this function is si... | [] | [
{
"body": "<p>Try looping through it with a simple for loop:</p>\n\n<pre><code>var b = '';\nfor (var i = 0; i < a.length; i++)\n{\n b += String.fromCharCode(a.charCodeAt(i) - 1)\n}\nreturn b;\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "201... | {
"AcceptedAnswerId": "4500",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2011-08-30T15:03:33.253",
"Id": "4499",
"Score": "1",
"Tags": [
"javascript",
"performance",
"strings",
"comparative-review",
"caesar-cipher"
],
"Title": "Encode strings by subtrac... | 4499 |
<p>I came up with the following class that I can use as an XNA service to manage rendering to things other than the screen as I didn't want to be passing <code>Game</code>s/<code>GraphicsDevice</code>s around all over the place for testing reasons. I can't see anything wrong with it, but I'm curious what other people t... | [] | [
{
"body": "<p>An approach itself is fine IMO, but the API is misleading. Why would <code>SetXXX</code> method ever return something, let alone return an <code>IDisposable</code>? Maybe come up with a better name.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate":... | {
"AcceptedAnswerId": "4545",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-31T03:27:41.620",
"Id": "4507",
"Score": "2",
"Tags": [
"c#"
],
"Title": "Managing rendering targets in XNA using IDisposable"
} | 4507 |
<p>I hope this is not a really bad question for a first time here beginner.</p>
<p>This piece of code selects from the left table and will list the content in the right hand table. This is a working code but I would like to see how a professional would protect and make it faster. </p>
<p>Any suggestion (with some cod... | [] | [
{
"body": "<p>You are using prepared SQL statements, but not using parameterised queries in them, so you're still wide open to SQL injections. This is how you should be doing it:</p>\n\n<pre><code>$gid = $_GET['gid']; \n$queryr = $pdo->prepare('SELECT test3.name FROM test1, test2, test3 WHERE test1.id = t... | {
"AcceptedAnswerId": "4510",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-31T08:11:06.653",
"Id": "4509",
"Score": "2",
"Tags": [
"php",
"mysql"
],
"Title": "SQL Injection and php performance checking"
} | 4509 |
<p>I'm attempting to implement a simple long-polling/comet/reverse AJAX solution, and came across the concept of delegates, specifically with the <code>BeginInvoke</code> and <code>EndInvoke</code> methods. I've built a Web Service that uses these concepts, but, having never used these, they make me a little nervous, a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-22T02:48:39.670",
"Id": "58515",
"Score": "1",
"body": "You've never used an event handler? `EventHandler` is just a delegate with a `(Object, EventArgs)` signature and no return value. You know delegates more than you think you do."
... | [
{
"body": "<p><a href=\"https://stackoverflow.com/a/7050854/1188513\">This Stack Overflow answer</a> to the question \"Is there a VB.NET equivalent of C# out parameters\" is pretty clear:</p>\n\n<blockquote>\n <p><em>No, there is no equivalent construct that allows a non-initialised variable to be passed to a ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-31T15:54:14.770",
"Id": "4516",
"Score": "8",
"Tags": [
".net",
"ajax",
"vb.net",
"asynchronous"
],
"Title": "Using Delegates and BeginInvoke with .NET 2.0 WebServices"
} | 4516 |
<p>I've been working on implementing a fast Huffman decoder for video decoding. With some <a href="https://codereview.stackexchange.com/questions/4479/faster-huffman-decoding">help from you</a>, I have been able to produce a decent implementation. However I am still not satisfied with the results. I have done some rese... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-02T08:08:04.677",
"Id": "6781",
"Score": "0",
"body": "do you really need to rebuild the table every time?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-02T10:06:16.853",
"Id": "6782",
"Score": "0... | [
{
"body": "<p>Do you have some control over the input encoder?\nIf so it should be providing you with a Huffman tree delta, rather than a whole new tree for every frame. In the same way that the HT algorithm applies similarity rules to encoded data, from frame to frame the HT will have also have a very high deg... | {
"AcceptedAnswerId": "4722",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-31T20:43:44.760",
"Id": "4518",
"Score": "7",
"Tags": [
"c++",
"optimization",
"lookup",
"compression",
"video"
],
"Title": "Optimizing Huffman Decoding"
} | 4518 |
<p>I am trying to create a new website, and i am using a class that has many functions on it.
First i want to say that my class has about 5000 rows , is this a problem ?</p>
<p>The main function i have used on my class is this one : </p>
<pre><code>function f3($id = '') {
$id = mysql_real_escape_string ($id);
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-01T04:18:28.257",
"Id": "6761",
"Score": "0",
"body": "what exactly is the problem, does it not work, does it run slow?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-01T04:20:36.267",
"Id": "6762",
... | [
{
"body": "<p>The code looks fine to me, can't see anything obvious that i would improve on</p>\n\n<p>Normally I don't ever explicitly close a database connection on my scripts.\nwhen the script ends, the database connection is closed automatically</p>\n\n<p>5,000 lines of code for one class is quite a lot, but... | {
"AcceptedAnswerId": "4523",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-01T04:14:55.943",
"Id": "4522",
"Score": "-1",
"Tags": [
"php",
"performance"
],
"Title": "Displaying posts"
} | 4522 |
<p>I have written this PHP function which will flip an image (horizontally, like looking in a mirror). It reads the file, flips it, and writes it to a new filed called filename"_flipped".ext. I would like to refactor this to the smallest possible size, but maintaining human readability. </p>
<p>Here is the function: ... | [] | [
{
"body": "<p>You could use call_user_func to check the extension only once. Something like this (I haven't got the time even to read the code now) </p>\n\n<pre><code>function flip_image($filepath)\n{\nif(file_exists($filepath)):\n\n //Array ( [dirname] => images \n // [basename] => pig.png \... | {
"AcceptedAnswerId": "4527",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-01T12:43:03.917",
"Id": "4526",
"Score": "0",
"Tags": [
"php"
],
"Title": "Help to Refactor PHP Flip Image Code to smallest size as possible"
} | 4526 |
<p>I have this code:</p>
<pre><code>private void numWidth_ValueChanged(object sender, EventArgs e)
{
if (ignoreChange) return; // Sometimes I only want to change the value without the event firing (like when undo-ing)
PushUndoStack();
int width = (int)numWidth.Value;
foreach (Layer layer in doc.Tile... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-31T22:53:10.603",
"Id": "6772",
"Score": "3",
"body": "There is a site for code-reviews on SE, check it out ;) Apart from that, you could in that case (adapt where necessary) create a dimensionChanged method that takes sender, e and a ... | [
{
"body": "<p>You can try the idea below. </p>\n\n<pre><code> private void numWidth_ValueChanged(object sender, EventArgs e)\n {\n if (OnValueChanged((layer, value) => layer.Width = value, (int)numWidth.Value))\n {\n // Can be refactored in a similar\n // hscDoc.Maxi... | {
"AcceptedAnswerId": "4530",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-08-31T22:50:03.123",
"Id": "4528",
"Score": "5",
"Tags": [
"c#"
],
"Title": "How to shorten two methods with the same theme?"
} | 4528 |
<p>Example code:</p>
<pre><code><?php
class MyClass {
public $bar = array('a', 'b', 'c');
public function getBar() {return $this->bar;}
public function execute(array $fooArray) {
foreach ($fooArray as $foo) {
echo $foo.":".$this->checkBar($foo, $this->getBar())." ";// PASSE... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-11-12T03:47:59.777",
"Id": "9208",
"Score": "0",
"body": "Nope, it's all good."
}
] | [
{
"body": "<p>Having (1)</p>\n\n<pre><code>public function execute(array $fooArray)\n{\n foreach ($fooArray as $foo) {\n echo $foo . \":\" . $this->checkBar($foo, $this->getBar()) . \" \";\n }\n}\n\npublic function checkBar($foo, array $fooCheck)\n{\n return in_array($foo, $fooCheck);\n}\n... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-01T15:36:46.053",
"Id": "4532",
"Score": "2",
"Tags": [
"php",
"performance"
],
"Title": "PHP performance considerations of passing variable into a function"
} | 4532 |
<p><code>BudgetCode</code> is in the format <code>'xxxx-yyyyy-zzzzz'</code>. This splits it correctly but I think that there has to be a more efficient way.</p>
<pre><code>Select
substring(pc.BudgetCode,1, CHARINDEX('-',pc.BudgetCode)-1) as Cost_Center,
substring(Substring(pc.BudgetCode,Charindex('-',pc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-01T17:19:10.293",
"Id": "6774",
"Score": "1",
"body": "What RDBMS are you on? Some 'better' solutions don't work on all products. Also, I recommend storing the code separated, if at all possible, so you don't have to do the split; if... | [
{
"body": "<p>Hmm... Not sure how much <em>faster</em> this will be, but it may be easier to wrap your head around.<br>\nYou can use a recursive CTE: </p>\n\n<pre><code>WITH Splitter (id, start, e, section, original, num) as (\n SELECT id, 1, CHARINDEX('-', budgetCode), CAST('' AS VARCHAR(20)), b... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-01T16:43:38.603",
"Id": "4533",
"Score": "3",
"Tags": [
"sql",
"strings",
"sql-server"
],
"Title": "Splitting a string in an SQL query"
} | 4533 |
<p>I have recently become annoyed enough with something about the linux command line experience to take action.</p>
<p>I welcome all comments, but specific things I'd like input on are:</p>
<ul>
<li>Is there something already available that does this?</li>
<li>How would you do the same thing in Perl or Python?</li>
<... | [] | [
{
"body": "<p>\"Take 2\" looks much nicer than the initial version.\nOne bug seems to be <code>\"unrar\" => \"unrar\"</code>, which should be <code>\"rar\" => \"unrar\"</code>.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-04T03:16:33.180"... | {
"AcceptedAnswerId": "4575",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-01T20:19:37.783",
"Id": "4534",
"Score": "2",
"Tags": [
"ruby"
],
"Title": "Fixing Archive Annoyances with Ruby"
} | 4534 |
<p>The following code is a quick implementation since I only needed 3 random images sorted by category (a random eyes image, a random nose image and a random mouth image and then combine them):</p>
<pre><code> fileinfos = FileInfo.all().filter("category =", "eyes")
fileinfo = fileinfos[random.randint(0, fileinf... | [] | [
{
"body": "<p>Regarding image caching, <a href=\"https://stackoverflow.com/questions/1380431/caching-images-in-memcached\">this seems relevant</a>.</p>\n\n<p>Secondly, <a href=\"http://en.wikipedia.org/wiki/Don%27t_repeat_yourself\" rel=\"nofollow noreferrer\">DRY</a> this code up, it'll make your code more mai... | {
"AcceptedAnswerId": "4540",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-01T23:09:04.013",
"Id": "4538",
"Score": "0",
"Tags": [
"python",
"image",
"cache",
"google-app-engine"
],
"Title": "Iteration and memcache for selected categorized random elem... | 4538 |
<p>I have been working on a maze generator in C++ in an effort to learn the language and brush up on some long lost knowledge. I want to ensure that I am using best practices, and really doing things the way that they should be done. </p>
<p>My code is safely tucked into a GitHub repository. I would like to have two s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-02T17:37:04.147",
"Id": "6788",
"Score": "1",
"body": "Go look up the difference between size() and capacity()!!!"
}
] | [
{
"body": "<ol>\n<li><p>If you overload an operator, make sure that the corresponding operators behave accordingly - in your case: yes, overload <code>!=</code>. Make sure not to copy paste code but call operator <code>==</code> instead (or its implementation).</p></li>\n<li><p>Always provide copy and assignmen... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-02T05:02:19.110",
"Id": "4541",
"Score": "11",
"Tags": [
"c++",
"pathfinding"
],
"Title": "Maze generation"
} | 4541 |
<p>Often I find myself setting various fields in a Javabean and then passing that Javabean to some method.</p>
<pre><code>customerEntity.setName("Foo");
customerEntity.setAge(45);
customerEntity.setAddress(address);
em.merge(customerEntity);
</code></pre>
<p>Or </p>
<pre><code>requestPayload.setCustomerId(2343);
re... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-03T01:08:19.093",
"Id": "6810",
"Score": "1",
"body": "I like 'populate' personally"
}
] | [
{
"body": "<p>I agree you should not use setXXX() as this sounds like a classic setter. I would say go with what you think sounds nice and conveys the meaning well. prepareXXX() sound nice to me. If it is default values you are setting, you could use something along populateWithDefaultValues().</p>\n\n<p>Just m... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-02T19:30:41.500",
"Id": "4549",
"Score": "0",
"Tags": [
"java"
],
"Title": "How to name a method that sets some values in a javabean?"
} | 4549 |
<p>I've written a linked-list version of something like <code>shared_ptr</code>, which gets destroyed when the last copy of a pointer is destroyed.</p>
<p>Aside from the thread-unsafety, is it a fine implementation? Anything I could improve?</p>
<p>Also, what's the best way to extend it to make it work with <code>HAN... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-02T22:18:59.907",
"Id": "6796",
"Score": "0",
"body": "Why a linked list? Instead of a reference counter which would be more effective and simpler?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-02T22:36:0... | [
{
"body": "<p>Implementing your own smart pointer is very hard please don't try.</p>\n\n<p>If it is just to try and learn then fine you may learn something but after practicing go back to one that has been tested and is know to work.</p>\n\n<p>20 seconds into looking Bug 1:</p>\n\n<pre><code>int main()\n{\n ... | {
"AcceptedAnswerId": "4556",
"CommentCount": "27",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-02T19:54:05.247",
"Id": "4550",
"Score": "6",
"Tags": [
"c++",
"pointers"
],
"Title": "shared_ptr implementation"
} | 4550 |
<p>I am trying to get a row if it has the desired specific value, otherwise get the first or default:</p>
<pre><code>dr =
(from avTable in DAL.DataStore.DSet.Tables["Values1"].AsEnumerable()
join pavTable in DAL.DataStore.DSet.Tables["Values2"].AsEnumerable()
on avTable.Field<int>("PK") equals pav... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-02T20:50:40.680",
"Id": "6792",
"Score": "0",
"body": "This is the way `FirstOrDefault` is supposed to work ...? I don't see anything that 'smells' ...unless there is some optimization to the query. But nothing I can really see ..."
... | [
{
"body": "<p>Will this work?</p>\n\n<pre><code>var dr= (from avTable in DAL.DataStore.DSet.Tables[\"Values1\"].AsEnumerable()\n join pavTable in DAL.DataStore.DSet.Tables[\"Values2\"].AsEnumerable()\n on avTable.Field<int>(\"PK\") equals pavTable.Field<int>(\"FK_Value\");\n ... | {
"AcceptedAnswerId": "4555",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-02T20:13:44.690",
"Id": "4552",
"Score": "3",
"Tags": [
"c#",
".net",
"linq"
],
"Title": "Selecting a specific row with a desired value"
} | 4552 |
<p>I have been making this FSM today. However, as this is probably the biggest practical program I have ever written in CL, I don't know if there are some things that could be improved, or if using a closure is the best thing here.</p>
<p>Any feedback is appreciated.</p>
<pre><code>;;; States: -- EnterMineAndDigForNu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-03T00:41:41.477",
"Id": "6809",
"Score": "0",
"body": "The code tag doesn't keep all the formatting, but in my real code it is a good one"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-03T07:49:29.760",
... | [
{
"body": "<p>Can you comment on what the goal/output of this program is supposed to be? How you're supposed to use it? It looks like <code>make-miner</code> just returns a list of functions, which doesn't sound useful on its own.</p>\n\n<p>Some preliminary comments:</p>\n\n<hr>\n\n<p>You can cut the <code>whil... | {
"AcceptedAnswerId": "4576",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-03T00:40:30.013",
"Id": "4557",
"Score": "6",
"Tags": [
"lisp",
"common-lisp"
],
"Title": "Finite State Machine code"
} | 4557 |
<p>I am trying to learn graphs and implement in code. Can you please review my code and give me feedback?</p>
<p><a href="https://code.google.com/p/medicine-cpp/source/browse/trunk/cpp/graphs/graph.cpp" rel="nofollow">Source code</a></p>
<pre><code>#include <iostream>
using namespace std;
#include <list>... | [] | [
{
"body": "<p>Don't put using namespace std<br>\nbefore including other header files<br>\nIf you must do it then put it after all the includes. But preferably don't use it at all.</p>\n\n<pre><code>#include <iostream>\nusing namespace std;\n\n#include <list>\n#include <queue>\n#include <map... | {
"AcceptedAnswerId": "4563",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-03T18:05:59.717",
"Id": "4561",
"Score": "3",
"Tags": [
"c++",
"algorithm",
"graph"
],
"Title": "BFT/DFT/Topological graph implementation"
} | 4561 |
<p>I'm drawing rectangular ROI region by darkening the area outside of it as in this image:</p>
<p><img src="https://i.stack.imgur.com/24OlL.jpg" alt="enter image description here"></p>
<p>But <code>image.MakeTransparent</code> takes too much time. What is the best way to increase drawing speed?</p>
<pre><code>void ... | [] | [
{
"body": "<p>Well, you could try literally darkening the outside of the image by 25%, not by creating a 25%-opaque black area but just by calculating the pixel color values of the same color 25% darker, without the need to create a new 32bbp bitmap.</p>\n\n<p>This might help: <a href=\"https://stackoverflow.co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-03T19:03:22.100",
"Id": "4564",
"Score": "2",
"Tags": [
"c#",
"performance",
".net",
"image"
],
"Title": "Optimization of region of interest (ROI) drawing in the image"
} | 4564 |
<p>I started implementing a graph drawing application in javascript and < canvas > element, and i just wanted to hear your thought on the progress so far. I'm very open to suggestions and i'm very interested to hear what you have to say.<br>
So you can see the progress so far in the present code, if you have any que... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-04T18:33:29.187",
"Id": "6850",
"Score": "0",
"body": "Maybe you can provide an example of using it?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-04T18:53:21.060",
"Id": "6854",
"Score": "0",
... | [
{
"body": "<p>I like the code on the whole, I could work with this.\nMy 2 cents:</p>\n\n<ul>\n<li><code>graph.hookes_test</code> , please use lowerCaseCamel, so <code>graph.hookTest</code></li>\n<li><code>graph.oDuljina</code> , please use English</li>\n<li><code>document.getElementById('platno');</code> , if y... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-03T21:20:42.640",
"Id": "4568",
"Score": "4",
"Tags": [
"javascript",
"graph"
],
"Title": "Javascript graph skeleton implementation"
} | 4568 |
<p>I'm learning to implement linked list. I've implemented sorting with merge sort, reversing etc...</p>
<p><a href="https://code.google.com/p/medicine-cpp/source/browse/trunk/cpp/ds/LinkedList.cpp" rel="nofollow">LinkedList.cpp</a></p>
<pre><code>#include <iostream>
template <class T>
struct Node
{
T ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-04T03:32:41.663",
"Id": "6824",
"Score": "6",
"body": "Welcome to code review! Please post the code you want reviewed as part of your post rather then a link to elsewhere."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDa... | [
{
"body": "<pre><code>#include <iostream>\n\ntemplate <class T>\nstruct Node\n{\n T data;\n Node * next;\n};\n\ntemplate <class T>\nclass LinkedList\n{\npublic:\n LinkedList() : head(NULL), size(0) {};\n ~LinkedList() { destroyList(); };\n</code></pre>\n\n<p>Why did you make destroyList a ... | {
"AcceptedAnswerId": "4581",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-04T02:43:47.297",
"Id": "4569",
"Score": "4",
"Tags": [
"c++",
"linked-list"
],
"Title": "Linked List implementation in C++"
} | 4569 |
<p>I have been solving a set of online Clojure problems. One of them involves the <a href="http://en.wikipedia.org/wiki/Look-and-say_sequence" rel="nofollow">look and say sequence</a>.</p>
<pre><code>(defn look-and-say [s]
(let [las (loop [item (first s) coll s counts [] count 0]
(cond
(nil? (seq co... | [] | [
{
"body": "<p>one of the great things about Clojure is the ability to seperate code into concerns and then compose them. This really helps spot reusable parts and lets you build code in smaller independently testable parts.</p>\n\n<p>the parts I see are:</p>\n\n<ul>\n<li>given a sequence of number produce the n... | {
"AcceptedAnswerId": "4572",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-02T21:43:21.737",
"Id": "4571",
"Score": "4",
"Tags": [
"homework",
"clojure",
"lazy"
],
"Title": "Lazy look and say sequence"
} | 4571 |
<p>I've written this small class in Python that wraps bound methods but does not prevent the deletion of self.</p>
<ol>
<li>Do you have any thoughts on my code?</li>
<li>Do you think I handle errors appropriately?</li>
<li>Is it missing anything?</li>
<li>What should be done to make it more robust?</li>
<li>Is the doc... | [] | [
{
"body": "<pre><code>class WeakBoundMethod:\n</code></pre>\n\n<p>I suggest making it a new-style class by inheriting from object.</p>\n\n<pre><code> assert (hasattr(meth, '__func__') and hasattr(meth, '__self__')),\\\n 'Object is not a bound method.'\n</code></pre>\n\n<p>Don't do this. Just let th... | {
"AcceptedAnswerId": "4579",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-04T06:32:31.290",
"Id": "4574",
"Score": "4",
"Tags": [
"python",
"classes",
"weak-references"
],
"Title": "Wrapping bound methods"
} | 4574 |
<p>Implemented
Bubble Sort, Insertion Sort, Selection Sort,
Quick Sort, Merge Sort and
Radix Sort</p>
<p><a href="https://code.google.com/p/medicine-cpp/source/browse/trunk/cpp/sorting/SortingAlgorithms.cpp" rel="nofollow">https://code.google.com/p/medicine-cpp/source/browse/trunk/cpp/sorting/SortingAlgorithms.cpp</a>... | [] | [
{
"body": "<h3>Standard functions</h3>\n\n<p>There is already a standard swap.<br>\nNo need o pollute your code with one.</p>\n\n<pre><code>void swap(std::vector<int> & data, int i, int j)\n\ntemplate<typename T>\nvoid std::swap(T& lhs, T& rhs) // Implements optimal swap for T\n</code></... | {
"AcceptedAnswerId": "4595",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-04T14:01:21.553",
"Id": "4582",
"Score": "8",
"Tags": [
"c++",
"algorithm",
"sorting"
],
"Title": "Sorting algorithms implemented in C++"
} | 4582 |
<p>I'm processing about 3.5gb/15minutes, and I was wondering if I could get this down to a better time... </p>
<p>Note that this is for a very specific CSV file, so I am not concerned about generality - only speed of implementation and optimization.</p>
<pre><code>int main(int argc, char *argv[]) {
std::string fi... | [] | [
{
"body": "<p>First off streams and specifically the stream operators >> and << are designed for robustness not speed. They make the code harder to write incorrectly (and provide some local specific conversions) that make expensive in terms of using (consider changing to C fscanf() if speed is paramount).... | {
"AcceptedAnswerId": "4587",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-04T17:00:20.227",
"Id": "4585",
"Score": "4",
"Tags": [
"c++",
"performance",
"parsing",
"csv"
],
"Title": "File parsing code in C++"
} | 4585 |
<p>I have to use a C++ member function in pthread_create. Also, the member function needs to be able to get the argument.</p>
<p>So, I have implemented a launcher function, which with help of a launcher object which stores the member function's address and the argument, will be able to do the desired.</p>
<p>Is there... | [] | [
{
"body": "<p>Technically pthreads is a C library.<br>\nThus the callback function you pass to pthread_create() must be a C function with C linkage. To do this in C++ code the function must be declared as extern \"C\".</p>\n\n<p>So it may work, but it is non portable and you just happen to be getting lucky that... | {
"AcceptedAnswerId": "4592",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-04T22:29:56.303",
"Id": "4589",
"Score": "2",
"Tags": [
"c++",
"multithreading"
],
"Title": "Passing a member function in pthread_create"
} | 4589 |
<p>Are there any issues with below implementation?<br>
Input: from STDIN, a list of strings<br>
Output: serialize to a file called "out.txt" and then unserialize into a list of strings, and output to STDOUT </p>
<p>Goal is not here too much about code organization, but I would like to know if this code can fail for c... | [] | [
{
"body": "<p>Looks like it will work fine.<br>\nYou preserve the string integrity in the file by maintaining its length as a separate entity that you can check independently. So it should work fine.</p>\n\n<p>Not sure why you copy it to intermediate arrays.<br>\nWhy not copy directly from input to file then fr... | {
"AcceptedAnswerId": "4602",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-05T00:47:35.140",
"Id": "4593",
"Score": "1",
"Tags": [
"c++",
"strings"
],
"Title": "Serialization/Unserialization of a list of strings - C++"
} | 4593 |
<p>I wrote a language in C, dubbed <code>gecho</code>. The code can be found <a href="http://github.com/tekknolagi/gecho/tree/testing" rel="nofollow">here</a>.</p>
<p>I'm writing this for a purely educational reason (not for school at all) and I just hope to make it Turing complete, and to improve the structure. The b... | [] | [
{
"body": "<p>It looks like you have some of basics of language development, so well done for a first start.</p>\n\n<p>I'd say that you want to avoid things like your RES_SIZE and VAR_SIZE constants. Where do these numbers come from? Are they designed to be suitable for the system that you're running on? What a... | {
"AcceptedAnswerId": "4601",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-05T05:22:14.240",
"Id": "4596",
"Score": "-1",
"Tags": [
"c"
],
"Title": "My language, gecho"
} | 4596 |
<p>I'm a beginning Scala programmer with a strong background in functional programming (ML, Haskell, Scheme) and I've just written my first Scala program. It is an implementation of a FSA (finite state automaton). Below is a simplified version that has 3 events/actions/labels (E0, E1, E2) and four states (S0, S1, S2, S... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T20:15:50.710",
"Id": "6964",
"Score": "1",
"body": "If you look for alternative implementations, Akka has an interesting FSM implementation (with actors, of course, but it is easy to reduce it without them, I did that for a lightwei... | [
{
"body": "<p>Looks fine to me. You don't need so much parens:</p>\n\n<pre><code>object S0 extends State {\n override def event (e : Event) : State = e match {\n case E0 => S1 \n case E1 => S0 \n case E2 => S2 \n } \n} \n</code></pre>\n\n<p>But in this easy example I would use a <code>M... | {
"AcceptedAnswerId": "4611",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-05T11:09:08.900",
"Id": "4597",
"Score": "6",
"Tags": [
"scala"
],
"Title": "FSA (finite state automaton) in Scala"
} | 4597 |
<p>I'm trying to get a list of all artists on an iPhone / iPod touch music library. The best way I've found has been to group by artists (the convenience constructor on MPMediaQuery) and to iterate over the collections, being one for each artist. That way I've optimized out having to use an NSSet to ensure uniqueness i... | [] | [
{
"body": "<p>Is it actually necessary to add just the artist to the array? We could simply do this:</p>\n\n<pre><code>NSMutableArray *artists = artistsQuery.collections;\n</code></pre>\n\n<p>Now we don't have to iterate through an entire array. And later, when we need to access the artist at a particular arr... | {
"AcceptedAnswerId": "56242",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-05T23:04:12.937",
"Id": "4605",
"Score": "7",
"Tags": [
"objective-c",
"ios",
"search"
],
"Title": "Optimizing a search for list of artists in iTunes library"
} | 4605 |
<p>So I have some Javascript code that resembles the following:</p>
<pre><code>var mylibrary = new (function ()
{
this._getLibraryObj = function ()
{
var newLibraryObj = {};
var libraryData = window.specifiedLibraryData;
// Add head librarian details
// open library
// ... | [] | [
{
"body": "<p>Another downfall of your <code>this.item()</code> function is that if <code>item</code> isn't in <code>this.obj</code>, <code>this._getLibraryObj()</code> will be called every time.</p>\n\n<p>Try</p>\n\n<pre><code>this.item = function(item) {\n if (this.obj) {\n return this.obj[item] || ... | {
"AcceptedAnswerId": "4609",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-06T00:52:21.777",
"Id": "4606",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Javascript get item in object code"
} | 4606 |
<p>For a site I wrote this JS contact parser. It simply reads contacts and parses links if a known service is identified. Could this be made more compact? How about robustness? (it cannot handle exceptions where the url does not begin with http for instance). What other services should I consider to add?</p>
<p>Here i... | [] | [
{
"body": "<p>Firstly I would change all the occurances of </p>\n\n<pre><code>}\n\nif(!i && c.indexOf(...\n</code></pre>\n\n<p>to </p>\n\n<pre><code> } else if(c.indexOf(...\n</code></pre>\n\n<p>To me there doesn't seem to be any difference logically and its cleaner.</p>\n\n<p>Second I would use regexes... | {
"AcceptedAnswerId": "4608",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-06T02:40:00.150",
"Id": "4607",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "Better JS Contact Parser"
} | 4607 |
<p>I have an array of objects eg.</p>
<p>[
array(
'id' => 1,
'name' => "simon"
),
...
]</p>
<p>and I need to get an array of IDs eg.
[1,2,3,4,5];</p>
<p>Currently I'm doing this:</p>
<pre><code> $entities = $this->works_order_model->get_assigned_entities($id);
$employee_ids = array();
f... | [] | [
{
"body": "<p>I think array_map is what you are looking for:</p>\n\n<pre><code>php > $aa = array (array (\"id\" => 1, \"name\" => 'what'), array('id' => 2));\nphp > function id($i) { return $i['id'];};\nphp > print_r(array_map ('id', $aa));\nArray\n(\n [0] => 1\n [1] => 2\n)\n</cod... | {
"AcceptedAnswerId": "4616",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-06T05:27:48.420",
"Id": "4610",
"Score": "3",
"Tags": [
"php",
"array"
],
"Title": "Getting an array from one property of an associative array best practice"
} | 4610 |
<p>After I made a change to the html structure for a project, I found myself having to change many jquery selectors in many places. To avoid this problem in the future I decided to make a simple function where I pass an element indicating where I am and a string indicating where I want to go. This function should app... | [] | [
{
"body": "<p>The answer depends, for me, on many things. Some are:</p>\n\n<ul>\n<li>is it a prototype or not? Looks like it is</li>\n<li>are you in a rush? If so, do whatever works for you IF it's a prototype.</li>\n<li>how big will the whole project be?</li>\n</ul>\n\n<p>Here's a list of things that bother me... | {
"AcceptedAnswerId": "4613",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-06T07:10:36.670",
"Id": "4612",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Using one function to go from one element to another"
} | 4612 |
<p>Is the code below safe from SQL injection?</p>
<pre><code><?
mysql_connect ("localhost", "db","pass") or die (mysql_error());
mysql_select_db ("db");
$term = mysql_real_escape_string($_POST['term']);
$sql = mysql_query("select * from tblListings where category like '%$term%' or title like '%$term%' or postco... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-02-22T16:14:31.120",
"Id": "148007",
"Score": "1",
"body": "As far as I know it is safe from SQL injection, but it is vulnerable to HTML/Javascript injection (xss attacks) unless the details in the database are explicitly stored in HTML f... | [
{
"body": "<p>I <strong>HIGHLY</strong> suggest using PHP PDO with prepared statements ALONG with filtering each field for specific accepted characters. </p>\n\n<p>But to answer your question, your method above is no longer considered safe and can be exploited. </p>\n\n<p>PDO & Tutorial:</p>\n\n<ul>\n<li><a... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-06T15:23:40.120",
"Id": "4617",
"Score": "2",
"Tags": [
"php",
"mysql",
"security",
"sql-injection"
],
"Title": "Simultaneously searching listings by attributes such as category,... | 4617 |
<p>I'm creating a dispatcher class - which is itself a long running task which can be cancelled at anytime by the user. This Task will poll the database to see if there is any work that needs to be done, and run up to X [5] # of child tasks.</p>
<p>As far as I can tell - it's working great, but I have a few questions... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-22T04:57:53.563",
"Id": "28342",
"Score": "0",
"body": "Matthew I am writing almost the exactly the same code. :) We should collaborate!"
}
] | [
{
"body": "<p>Bug in your code: if you have 5 or more tasks running, no task will ever respond to a Cancel() request on the CancellationToken.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-09-29T19:51:48.430",
"Id": "194299",
"Score": "... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-06T19:55:03.123",
"Id": "4620",
"Score": "1",
"Tags": [
"c#",
"multithreading",
"winforms"
],
"Title": "Properly creating a Task to poll and dispatch child tasks with cancellation fo... | 4620 |
<p>I am developing a class library for processing credit cards. There is a thought in management in the short-term future to look for a new credit card processor. So I want to write once and use everywhere (I should be anyway, right?).</p>
<p>We are currently using First Data's Global Gateway Web Service API. I need a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-10-17T23:35:03.573",
"Id": "8193",
"Score": "0",
"body": "Is your objective to support both the test and live processing in a single environment? Usually your live environment goes to a live CC processor, and your test to test. Thus, wh... | [
{
"body": "<p>Here's one method. In your settings file, define a \"Mode\" setting. Toggle that for Live/Test. Then create a public property that uses that (I put it in my Settings.cs file).</p>\n\n<pre><code> /// <summary>\n /// Gets the DB connection string\n /// </summary>\n /// <... | {
"AcceptedAnswerId": "5494",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-06T20:05:48.867",
"Id": "4621",
"Score": "3",
"Tags": [
"c#",
"finance"
],
"Title": "Class library for processing credit cards"
} | 4621 |
<p>I was told that I might get some feed back about the code below. I'm learning and need some criticism.</p>
<p>My initial question was how to save users answers and tally them up to display number correct/wrong.</p>
<pre><code>import random
import os
if __name__=='__main__':
books=['Genesis', 'Exodus', 'Levit... | [] | [
{
"body": "<pre><code>import random\nimport os\n\nif __name__=='__main__':\n\n books=['Genesis', 'Exodus', 'Leviticus', 'Numbers', 'Deuteronomy', 'Joshua',\n</code></pre>\n\n<p>The python style guide recommends that global constants be in ALL_CAPS. There is no reason to put such assignments inside <code>if _... | {
"AcceptedAnswerId": "4625",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-06T20:59:00.217",
"Id": "4623",
"Score": "2",
"Tags": [
"python"
],
"Title": "Matching and enumerating the results of a quiz"
} | 4623 |
<p>I wanted to give Haskell a try, and I started with a simple exercise I found <a href="http://www.cs.brown.edu/courses/cs173/2008/Assignments/04-laziness-prog.html" rel="nofollow">here</a>.</p>
<blockquote>
<ol>
<li>Write <code>isPrime :: Integer -> Bool</code>, which determines whether a given
integer is p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T01:55:53.693",
"Id": "6933",
"Score": "0",
"body": "I realize QA may be a better fit on stackoverflow, but the questions I'm more interrested in are QB and QC, which (I think) belong to codereview."
},
{
"ContentLicense": "C... | [
{
"body": "<p>Not an answer to your questions, but a correction for your first, looping attempt for Q3:</p>\n\n<p>Things get much easier if you initially have at least one prime number in your list. You <em>could</em> ensure this by a separate case in <code>isPrime</code>, but why not cheat a little bit, and ad... | {
"AcceptedAnswerId": "4633",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T01:51:38.367",
"Id": "4626",
"Score": "1",
"Tags": [
"haskell",
"primes"
],
"Title": "Lazy computation of primes in Haskell"
} | 4626 |
<p>Please review this:</p>
<pre><code>#include <iostream>
using namespace std;
template <class T>
struct Node
{
T data;
Node * next;
Node(T data) : data(data), next(NULL) {}
};
template <class T>
class CircularLinkedList
{
public:
CircularLinkedList() : head(NULL) {}
~CircularLinkedList()... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T06:33:57.693",
"Id": "6934",
"Score": "0",
"body": "Most of the cases I wrote for your other question are also applicable here: http://codereview.stackexchange.com/questions/4629/doubly-linked-list-c/4630#4630"
},
{
"Content... | [
{
"body": "<p>)</p>\n\n<p>My first comment is you should start looking at smart pointers.<br>\nThey will definitely simplify your code.</p>\n\n<p>The second comment: look at the <a href=\"http://www.sgi.com/tech/stl/Container.html\" rel=\"nofollow noreferrer\">STL containers</a>.<br>\nContainers in C++ follow a... | {
"AcceptedAnswerId": "4640",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T05:07:08.233",
"Id": "4628",
"Score": "4",
"Tags": [
"c++",
"linked-list",
"circular-list"
],
"Title": "Circular linked list"
} | 4628 |
<p>Please, review the code:</p>
<pre><code>#include <iostream>
using namespace std;
template <class T>
struct Node
{
Node(T data) : data(data), next(NULL), prev(NULL) {}
T data;
Node * next;
Node * prev;
};
template <class T>
class DoublyLinkedList
{
public:
DoublyLinkedList() : head(NULL... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-26T09:04:16.073",
"Id": "7476",
"Score": "0",
"body": "never open a namespace declaration in a header file btw. So for instance, don't put in 'using namespace std;'"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2... | [
{
"body": "<ol>\n<li><p>Consider replacing <code>Node<T></code> with:</p>\n\n<pre><code>typedef Node<T> node_t;\n\n...\n\nnode_t node;\n</code></pre></li>\n<li><p>Consider making your implementation STL-enabled. If I were user of this class, the first thing I'd ask you is \"how do I iterate over thi... | {
"AcceptedAnswerId": "4630",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T05:13:21.910",
"Id": "4629",
"Score": "8",
"Tags": [
"c++",
"linked-list"
],
"Title": "Doubly linked list in C++"
} | 4629 |
<p>Please review this:</p>
<pre><code>#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
template <class T>
class Stack
{
public:
Stack() {}
void push(T x);
void pop();
T & top();
size_t size();
bool empty();
private:
std::vector<T> elems;
};
... | [] | [
{
"body": "<p>Most of the cases I wrote for <a href=\"https://codereview.stackexchange.com/questions/4629/doubly-linked-list-c/4630#4630\">your other question</a> are also applicable here. Here's an extra thing:</p>\n\n<p><code>return elems.size() == 0 ? true : false;</code></p>\n\n<p>The expression <code>elems... | {
"AcceptedAnswerId": "4643",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T06:01:01.607",
"Id": "4631",
"Score": "1",
"Tags": [
"c++",
"stack"
],
"Title": "Stack class in C++"
} | 4631 |
<p>There is a 1-to-many relationship between the <code>posts</code> table and the <code>votes</code> table, and they join on <code>posts.id = votes.postid</code>. I would like to know how many posts have 1, 2, 3, 5, etc. votes.</p>
<p>Thanks to Waffles' <a href="http://data.stackexchange.com/stackoverflow/s/87/most-co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T17:47:30.610",
"Id": "6954",
"Score": "1",
"body": "Is there some reason you can't restrict your where clause to `where VoteTypeId = 2` and then just `count(*)` the rows? That's essentially what you're currently asking. Or do you ... | [
{
"body": "<p>Not creating the VoteStats table makes a big difference. Gets it down to ~5.5 seconds.</p>\n\n<pre><code>set nocount on\n\nselect up, count(*)\nfrom (\n select\n PostId,\n up = sum(case when VoteTypeId = 2 then 1 else 0 end)\n from Votes\n where VoteTypeId in (2,3)\n grou... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T09:55:25.783",
"Id": "4635",
"Score": "3",
"Tags": [
"sql",
"stackexchange"
],
"Title": "Upvote distribution SEDE query"
} | 4635 |
<p>I'm volunteering some time to work on an open-data project, which I've started a repo out here for:</p>
<p><a href="https://github.com/0xdeadcafe/Open-Hamilton/blob/master/whereare.js" rel="nofollow">https://github.com/0xdeadcafe/Open-Hamilton/blob/master/whereare.js</a></p>
<p>The general idea is you'll paste in ... | [] | [
{
"body": "<p>There's nothing stopping you putting a closure in around the script part so you don't have global variables - all except closures cause memory leaks in IE6 - in fact, Google Analytic does it.</p>\n\n<p>The switch statement does look a bit over-kill in <code>confMerge</code>. I'm not sure typeof wi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T13:54:35.780",
"Id": "4639",
"Score": "-1",
"Tags": [
"javascript"
],
"Title": "Javascript widget patterns and merging configurations"
} | 4639 |
<p>I am trying to send mail via the <code>mail()</code> method, but I am doing it on my localhost, which does not appear to have a SMTP server running. </p>
<p>I think the code is fine, and the mail method itself is returning <code>true</code>, but could someone tell me if there is anything wrong with the use of the f... | [] | [
{
"body": "<p>Your email headers need to be seperated by CRLFs.\nFrom php.net:</p>\n\n<blockquote>\n <p>Multiple extra headers should be separated with a CRLF (<code>\\r\\n</code>)</p>\n</blockquote>\n\n<p>so you would need to add in <code>\"\\r\\n\"</code> between header declarations.</p>\n\n<p>Example from p... | {
"AcceptedAnswerId": "4646",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T15:51:49.487",
"Id": "4644",
"Score": "-1",
"Tags": [
"php"
],
"Title": "Localhost Mail() issues"
} | 4644 |
<p>I've written a class that makes writing singletons easy. The class is meant to be used as a decorator (example below). I'd like to see your thoughts about the code, the documentation, and everything else that you feel is worth noting.</p>
<pre><code>class Singleton:
"""
Helper class meant to ease the creati... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T20:15:21.153",
"Id": "6963",
"Score": "0",
"body": "Isn't Alex Martelli's \"Borg\" the existing, recommended solution? http://code.activestate.com/recipes/66531-singleton-we-dont-need-no-stinkin-singleton-the-bo/. Why reinvent thi... | [
{
"body": "<p>Hmmm, if it's called from multiple threads, it may create few instances. So, some locking would be welcome.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T16:57:10.037",
"Id": "6950",
"Score": "1",
"body": "Oh... | {
"AcceptedAnswerId": "4652",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T16:45:03.060",
"Id": "4648",
"Score": "4",
"Tags": [
"python",
"singleton"
],
"Title": "Singleton Decorator"
} | 4648 |
<p>I have a lot of repeatable blocks of code and want to optimize/simplify them:</p>
<pre><code> function animationInit() {
content = $('#content')
.bind('show',function(event, f) {
$(this).animate({right:0}, lag + 200, function() {
if (f) f();
});
})
... | [] | [
{
"body": "<p>I don't understand the need for </p>\n\n<pre><code>function() {\n if (f) f();\n}\n</code></pre>\n\n<p>put <code>f</code> instead of that whole thing. If it is undefined it won't get called.</p>\n\n<p>e.g</p>\n\n<pre><code>.bind('show',function(event, f) {\n $(this).animate({right:0}, lag + 2... | {
"AcceptedAnswerId": "4665",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T21:40:03.853",
"Id": "4654",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"callback"
],
"Title": "jQuery callbacks optimization"
} | 4654 |
<p>I'm doing something quite strange. I'm trying to create a tiny system for creating templates inline in PHP, so that I can refactor by creating multiple templates in the original script, and eventually move the templates to separate scripts.</p>
<p>Here's the silly/basic template library that just calls an anonymou... | [] | [
{
"body": "<p>Something like this would get you most of the way there:</p>\n\n<pre><code><?php\nfunction h($val) {\n echo $val;\n}\n\nfunction template_function($template_body) {\n return function(array $template_output_variables = null) use ($template_body) {\n if ($template_output_variables !=... | {
"AcceptedAnswerId": "10144",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T22:08:34.437",
"Id": "4656",
"Score": "3",
"Tags": [
"php",
"template"
],
"Title": "Passing anonymous functions and getting variables from an outer scope"
} | 4656 |
<p>I have a table that contains the <code>UserAgent</code> string and a <code>Count</code> of how many times its seen. The T-SQL below is used to give a breakdown of what browsers are seen and how often then are seen.</p>
<p>I'm looking for comments (good or bad) and suggestions (good only).</p>
<pre><code>SELECT
Br... | [] | [
{
"body": "<p>Not a full answer but I would personally try to store all the mapping you use in the \"case\" statement in table.\nSo you could replace your sub query with all these cases by a join.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
... | {
"AcceptedAnswerId": "4714",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2011-09-07T22:25:12.547",
"Id": "4657",
"Score": "11",
"Tags": [
"performance",
"sql",
"sql-server"
],
"Title": "T-SQL statement to breakdown UserAgent information"
} | 4657 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.