body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I just spent the whole night writing this little script for my search engine. Now i want to improve it.</p>
<p>Any ideas?</p>
<pre><code><?php
echo "KEYWORDS : ". $searchstring = "the and";
$sentence = "Skype Home is unavailable at the moment. Check back later to see your news and alerts. It's easy to star... | [] | [
{
"body": "<h1>Unused if statements</h1>\n\n<p>You have a <code>if($num<=1)</code> statment that is empty, while your using <code>else</code>. Reverse the statement like this.</p>\n\n<pre><code>if ($num > 1) {\n $sentence = $_SESSION['NewSentence'];\n}\n</code></pre>\n\n<h1>Ambiguous use of $_SESSION<... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T08:48:35.210",
"Id": "18240",
"Score": "3",
"Tags": [
"php"
],
"Title": "php highlight search keywords [working solution]!"
} | 18240 |
<p>I am new at OOP and I wonder if the code below is OOP or it can be better and also what can be better?</p>
<pre><code>class cForm{
private $_TagAction;
private $_TagMethod;
private $_TagName;
private $_TagExtraAttr;
//var form field
private $_FieldType;
private $_FieldName;
//var ... | [] | [
{
"body": "<p>If you have more than one button or input field per form, or are ever using the same instance for more than one form, then no, this code is not OO at all. Even if you only have one, it's quite a stretch, and the way you're using it in your example is not very OO. If you'd set everything first an... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T09:56:03.657",
"Id": "18241",
"Score": "4",
"Tags": [
"php",
"object-oriented",
"form"
],
"Title": "OOP PHP form ok?"
} | 18241 |
<p>The following script closes a virtual machine (which is run in a screen session), waits for the session to close, creates a backup of the VM, and restarts the VM. The shutdown and bootup scripts speak for themselves, but I can post them if necessary. Is there any way to clean up the <code>sockets_found</code> functi... | [] | [
{
"body": "<p>You also can find if the socket file exists on <code>/var/run/screen/S-yourname/pid.screenname</code>.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T10:05:15.393",
"Id": "18655",
"Pare... | {
"AcceptedAnswerId": "128332",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T13:23:29.683",
"Id": "18246",
"Score": "4",
"Tags": [
"bash"
],
"Title": "Bash Backup Script"
} | 18246 |
<p>I just wanted to confirm if this example I created would qualify as a good example of a multithreaded producer consumer. I would like any review changes on improving this example. I found that static fields are essential for synchronization of the threads.
The wait-timeout mechanism along with the available flag ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-01-19T15:20:31.870",
"Id": "141235",
"Score": "0",
"body": "I would suggest using classes in the concurrent packages and also an Executor for your workers."
}
] | [
{
"body": "<p>Why don't you use a <a href=\"http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/BlockingQueue.html\" rel=\"nofollow\">BlockingQueue</a> instead of the transfer collection? The implemenations in util.concurrent use internal synchronization, which is most likely more performant than exte... | {
"AcceptedAnswerId": "18584",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T15:07:06.810",
"Id": "18250",
"Score": "1",
"Tags": [
"java",
"multithreading",
"locking",
"producer-consumer"
],
"Title": "Multithreading concepts with Producer Consumer"
... | 18250 |
<p>I have an XML layout used by 2 activities. Within this layout, there's a view that is <code>visible</code> for <code>Activity1</code> and <code>gone</code> for <code>Activity2</code>. <code>Activity1</code> is used more times compared to <code>Activity2</code>. I would like to know which of the following methods is ... | [] | [
{
"body": "<p>According to <a href=\"http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.1_r1/android/view/View.java\" rel=\"nofollow\">View source code</a> setting visibility through xml (line 3450) is cheaper than through <code>setVisibility</code> method (line 5511).</p>\... | {
"AcceptedAnswerId": "18277",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T16:10:11.093",
"Id": "18255",
"Score": "2",
"Tags": [
"java",
"design-patterns",
"android"
],
"Title": "Change View visibility programmatically or through XML?"
} | 18255 |
<p>A while back I was asked to write some sample code for a job that I was applying for. They wanted a class that had a function that would accept three lengths and return the appropriate type of triangle (Scalene, Isosceles or Equilateral) based on that. They also wanted unit tests.</p>
<p>After sending this I neve... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T20:38:43.183",
"Id": "29124",
"Score": "1",
"body": "Did they want a 'type' proper, as in some kind of triangle factory, or just the kind for identification, as demonstrated by the enum?"
},
{
"ContentLicense": "CC BY-SA 3.0... | [
{
"body": "<p>I don't see anything wrong with your standards.</p>\n\n<p>I do see some design issues though.</p>\n\n<p>The biggest one is your unit test. I count 6 distinct unit tests, not 1. Each one of those asserts should be in its own test with a method name describing the test. Assuming you are using NUn... | {
"AcceptedAnswerId": "18259",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T17:20:39.690",
"Id": "18257",
"Score": "9",
"Tags": [
"c#",
".net",
"unit-testing",
"nunit"
],
"Title": "Function for determining triangle type"
} | 18257 |
<p>I have an application where I am receiving big byte array very fast around per 50 miliseconds.</p>
<p>The byte array contains some information like file name etc. The data (byte array ) may come from several sources.</p>
<p>Each time I receive the data, I have to find the file name and save the data to that file n... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T22:35:36.400",
"Id": "29126",
"Score": "0",
"body": "Consider using [this][1] approach, I believe you have a similar situation.\r\n\r\n\r\n [1]: http://stackoverflow.com/questions/6203836/most-efficient-way-to-process-a-queue-with-... | [
{
"body": "<p>Careful about how many files you keep open, OS handles are not free. See <a href=\"http://msdn.microsoft.com/en-us/library/yz8tx0w3.aspx\" rel=\"nofollow\">http://msdn.microsoft.com/en-us/library/yz8tx0w3.aspx</a></p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"Con... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T22:19:30.287",
"Id": "18266",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Design guideline for saving big byte stream in c#"
} | 18266 |
<p>I have an implementation of a BrickBreaker-like game where instead of pieces being just removed from the ceiling, each impact results in a new ball being released, gradually building up to a pretty chaotic game.</p>
<p>The SDL related code that actually draws the game is not included here.</p>
<p>This is my second... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T11:48:04.410",
"Id": "29225",
"Score": "1",
"body": "Removing SDL dependency would help to review the code as it's hard to install"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T15:49:20.590",
"I... | [
{
"body": "<p>One comment on your modelling...</p>\n\n<p>Consider making the paddle position part of your <code>GameState</code>. Regardless of how you are going to control the paddle, conceptually it is part of the state. In particular, it is required in order to draw the game screen. Your game loop will look ... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T23:43:45.260",
"Id": "18268",
"Score": "3",
"Tags": [
"game",
"haskell",
"collision"
],
"Title": "BrickBreaker Spinoff in Haskell"
} | 18268 |
<p>Background: I need to use mutation observers to watch for nodes being added/removed under a specific element.</p>
<p>The code below is an attempt to implement something re-usable that uses <a href="https://developer.mozilla.org/en-US/docs/DOM/MutationObserver" rel="nofollow"><code>MutationObserver</code></a>s where... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-06T01:49:51.723",
"Id": "29132",
"Score": "0",
"body": "Any reason you're not declaring `'use strict'` globally?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-06T05:21:38.550",
"Id": "29138",
"Sco... | [
{
"body": "<p>2 observations:</p>\n\n<ol>\n<li><p>You can place 'use strict' in an IIFE, which keeps lint happy and it's DRYer</p>\n\n<pre><code>function DOMChildListMutationListenerFactory() {'use strict';}\n\n(function () \n{\n 'use strict';\n /* Do your thing with DOMChildListMutationListenerFactory.proto... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-06T00:15:15.237",
"Id": "18269",
"Score": "4",
"Tags": [
"javascript",
"dom"
],
"Title": "Simple DOM mutation abstraction"
} | 18269 |
<p>Recently, I've been thinking about better ways to make my WP themes more maintainable. What I've tried on one of my last projects is to separate out the presentation and logic as much as I can. First, I created a function with the loop in it and has all of the logic. It returns all of the data into an array. In the ... | [] | [
{
"body": "<p>Actually, there is something better, and that is <strong>using templates</strong>. Yes, it might be \"radical\" especially when you see no other developer near you use it. And yes, even my college instructors and friends don't know what templates are and still stuff logic with the presentation so ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-06T04:50:43.390",
"Id": "18275",
"Score": "2",
"Tags": [
"php"
],
"Title": "Separating logic and presentation in wordpress"
} | 18275 |
<p>I posted a question last week <a href="https://codereview.stackexchange.com/questions/18158/improve-on-an-after-create-callback-with-database-queries-ruby-on-rails">about refactoring an after_create callback</a>. The code in this question is for the create action. I'm using Stripe to handle credit card payments and ... | [] | [
{
"body": "<p>Most of the following can be summed up as the ol' Rails rule-of-thumb: <em>Skinny controller, fat model</em></p>\n\n<hr>\n\n<p><strong>1. Move logic to the model, and make it automatic</strong></p>\n\n<p>If you're doing this:</p>\n\n<pre><code>@payment.kind = @payment.determine_kind\n</code></pre>... | {
"AcceptedAnswerId": "18283",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-06T05:36:20.010",
"Id": "18278",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Create Action in Rails 3.2"
} | 18278 |
<p>I am making a review system and I need to be able to only select the DISTINCT url from the database, but then pull the relevant page title and rating time. I have managed to get it working by using:</p>
<pre><code><?php
//opens conection
include 'conn.php';
echo $_COOKIE["search"];
$sql = "SELECT * FROM feedba... | [] | [
{
"body": "<p>I would do it like this</p>\n\n<pre><code><?php\n#opens conection\ninclude 'conn.php';\n\necho $_COOKIE[\"search\"];\n\n\n$search = mysql_real_escape_string($_COOKIE[search]);\n$sql = \"SELECT * FROM feedback WHERE url LIKE '%{$search}%' GROUP BY url ORDER BY ratingtime DESC\";\n#runs the qu... | {
"AcceptedAnswerId": "18287",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-06T16:11:11.227",
"Id": "18285",
"Score": "2",
"Tags": [
"php",
"mysql"
],
"Title": "Need unique url but require non unique information from other columns"
} | 18285 |
<p>I'm pretty new to asp and c# and I have a couple of concerns with the security of the code I have written (shown below). Basically all it does is allow you to enter a quantity before you add the item to your cart using a razor form.</p>
<p>Every example I see uses validation on input fields, like: </p>
<pre><code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-06T22:59:59.907",
"Id": "29151",
"Score": "1",
"body": "What exactly do you mean by 'secure'?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T18:38:53.117",
"Id": "29250",
"Score": "0",
"body... | [
{
"body": "<p>Security is an important aspect of any application, so you must evaluate what you want to do for security.If this is a public portal then you need to make sure all query string value are safe and no problem with the input value , MVC also does care these things automatically but t to make sure you... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-06T16:28:32.503",
"Id": "18286",
"Score": "6",
"Tags": [
"c#",
"html",
"security",
"asp.net-mvc-3"
],
"Title": "Is this user input field secure?"
} | 18286 |
<p>I'd like to display a vector (implemented in my custom <code>Vector</code> class) and have the output width of the elements be configurable. I've done this by creating a simple wrapper for the element being displayed which stores the desired width in a static field. I'm not sure if this is the best approach.</p>
<p... | [] | [
{
"body": "<p>There are one problem with your approach you make local information global as consequence your <code>FixedWidthDouble</code> class is not thread-safe. There is a simple way to solve the problem by turning <code>width_</code> into a integral template argument of the class template <code>template<... | {
"AcceptedAnswerId": "18298",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-06T21:49:37.703",
"Id": "18291",
"Score": "7",
"Tags": [
"c++",
"iterator",
"stl"
],
"Title": "Setting output width with ostream_iterator"
} | 18291 |
<p>I am asking this for coding style. I have a program class that calls a function(of a data access class) that reads from a table (using entity framework by the way), and I'm preparing to write the <code>DataAccess.ReadMethod()</code>. </p>
<p>Is it better to pass the function a 2d string array <code>string[rows][fi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-06T23:52:17.467",
"Id": "29152",
"Score": "1",
"body": "Why are you even considering using an array of strings? Don't you have an entity for what you need?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-07... | [
{
"body": "<p>I have discovered, with thanks to you each, that it is better to call the display method within the DataAccess.ReadMethod() than to pass strings, Here's what I think i should do:</p>\n\n<pre><code>public class DataAccess\n{\n public bool CreateMan(TestDatabaseEntities dbEntities, Man M)\n {\... | {
"AcceptedAnswerId": "18330",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-06T23:35:22.090",
"Id": "18292",
"Score": "0",
"Tags": [
"c#",
"entity-framework"
],
"Title": "using 2D array to read datatable ok? or repeatedly call function that reads record by re... | 18292 |
<p>I've simplified this for posting, since there are going to be more than 4 options sets for this function to cycle through:</p>
<pre><code>function redundantSee() {
var optionSet1 = $('.wrapper:eq(0)'),
optionSet2 = $('.wrapper:eq(1)');
optionSet1.find('.options').each(function(){
var self = $(this... | [] | [
{
"body": "<p>Create a function with the common code:</p>\n\n<pre><code>function redundantSee() {\n\n var optionSet1 = $('.wrapper:eq(0)'),\n optionSet2 = $('.wrapper:eq(1)');\n\n\n function addImage(correspond, item) {\n var self = $(this),\n input = self.find('input'),\n title ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-07T03:14:13.040",
"Id": "18293",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"dom"
],
"Title": "Populating two lists, each from their respective with user input field"
} | 18293 |
<p>I am doing a database design I want to create a database with information of employees, their jobs, salaries and projects.</p>
<p>I want to keep information of the cost of a project (real value of project and the days a employee invested).</p>
<p>For <code>Employee</code> and <code>Project</code>, each <code>Emplo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-07T08:37:48.240",
"Id": "29168",
"Score": "0",
"body": "One change I would prefer is to have a primary key named as \"id\" for every table. So here Employee table will have the primary key - id, not the \"EmployeeID\". Doing so Dept-Em... | [
{
"body": "<ul>\n<li><p>Make the ids of the m-n-mapping tables their PK, you probably don't want to have duplicates there.</p></li>\n<li><p>Address and Name are to short for real world data.</p></li>\n<li><p>Avoid duplication of the table name in columns (e.g. jobname) in table jobs</p></li>\n<li><p>I'd apply t... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-07T07:52:01.237",
"Id": "18299",
"Score": "4",
"Tags": [
"sql",
"mysql"
],
"Title": "Database design with information of employees, their jobs, salaries and projects"
} | 18299 |
<pre><code> (function( $ ){
var monthNames = [ "Январь", "Февраль", "Март", "Апрель", "Май", "Июнь",
"Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь" ];
var dayNames = ["Пн","Вт","Ср","Чт","Пт","Сб","Вс"];
var now = new Date();
var methods = {
... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>THANK YOU for having all your code and variables in English, very nice</li>\n<li><p>In init I would suggest you extract <code>data</code>, fill it in if needed and put it back, so going from this</p>\n\n<pre><code> return this.each(function(){\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-07T09:01:21.393",
"Id": "18300",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"datetime"
],
"Title": "jQuery calendar plugin"
} | 18300 |
<p>I have a method(C#) which takes an XmlNodeList and a String and saves the xml data into a database. That code isn't the problem (at least for the moment), but because I have multiple XmlNodeLists, each needing a different String (the heading), I end up with code like</p>
<pre><code>saveToDB(students, "Students");
s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-07T11:00:25.470",
"Id": "29171",
"Score": "0",
"body": "Where does the `saveToDB` method live? Is it static? How are the `XmlNodeList` created and modified?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-0... | [
{
"body": "<p>I think you could create a new <code>saveToDB</code> method that requires a <code>Dictionary<string, XmlNodeList></code> inside this new method you could cycle through the Keys (string) and for each one call the current <code>saveToDB(string, XmlNodeList)</code>.</p>\n\n<p>Yes, it only move ... | {
"AcceptedAnswerId": "18305",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-07T09:15:27.143",
"Id": "18301",
"Score": "7",
"Tags": [
"c#",
".net"
],
"Title": "Is there a better way to call the same method with different parameters?"
} | 18301 |
<p>There are a number of different ways to do this. What do people prefer and why?</p>
<pre><code>public boolean checkNameStartsWith(List<Foo> foos) {
for (Foo foo : foos) {
if (!(foo.getName().startsWith("bar"))) {
return Boolean.FALSE;
}
}
return Boolean.TRUE;
}
</code><... | [] | [
{
"body": "<p>I'd change <code>Boolean.FALSE</code> to <code>false</code> and <code>Boolean.TRUE</code> to <code>true</code>. Using the constants objects from <code>Boolean</code> is rather unnecessary since the method returns with primitive <code>boolean</code>.</p>\n",
"comments": [
{
"Conte... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-07T10:22:06.420",
"Id": "18302",
"Score": "7",
"Tags": [
"java"
],
"Title": "Looping over a list, checking a boolean and return value"
} | 18302 |
<p>If I have this basic structure</p>
<pre><code>var Foo = function(str)
{
console.log('Object string: ' + this.str);
console.log('Param string : ' + str);
}
var Bar = function()
{
this.str = 'object string';
}
var obj = new Bar();
Foo.call(obj, 'param string');
</code></pre>
<p>It's fairly obvious wh... | [] | [
{
"body": "<p>I may be misunderstanding your question, but I'll have a go at answering. If I'm completely off, let me know.</p>\n\n<p>Technically, no prototypes are being extended, only the instance is being extended. In your last example, the <code>Bar</code> constructor (aka \"class\") does not have any of th... | {
"AcceptedAnswerId": "18333",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-07T11:07:35.990",
"Id": "18306",
"Score": "-1",
"Tags": [
"javascript"
],
"Title": "Extending an object with .call() and .apply()"
} | 18306 |
<p>I am new to WCF and need to work with another programmer's code. I am unsure of the way the WCF service client is used here:</p>
<pre><code>private void barButtonDocuments_ItemClick(object sender, ItemClickEventArgs e)
{
try
{
MyServiceClient myServiceClient = new MyServiceClient();
try
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T21:41:03.960",
"Id": "71717",
"Score": "0",
"body": "You may be interested in this WCF approach I asked about here: http://codereview.stackexchange.com/q/41692/1714"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate":... | [
{
"body": "<p>Use <code>Close</code> always for a clean path of code execution. Use <code>Abort</code> in case of a faulted channel, or if your code threw an error. As you might know, if you call <code>Close</code> on a faulted channel, it will throw another error, <code>Close</code> is a graceful shutdown of c... | {
"AcceptedAnswerId": "18324",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-07T14:45:34.193",
"Id": "18319",
"Score": "14",
"Tags": [
"c#",
"beginner",
"error-handling",
"wcf"
],
"Title": "Using a WCF service client and handling its exceptions"
} | 18319 |
<p>I have a select statement which is infact a subquery within a larger select statement built up programmatically. The problem is if I elect to include this subquery it acts as a bottle neck and the whole query becomes painfully slow.</p>
<p>An example of the data is as follows:</p>
<pre><code>Payment
.Receipt_no|.P... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T14:14:39.873",
"Id": "29231",
"Score": "1",
"body": "**What is the database type and version?** Also, have you looked into [`RANK()`](http://msdn.microsoft.com/en-us/library/ms176102.aspx) or equivalent?"
},
{
"ContentLicens... | [
{
"body": "<p>I see that in your question you said:</p>\n\n<blockquote>\n <p><em>\"I am unable to move the subquery out to a temporary table as temporary tables are simply not supported within the programming language used by my application.\"</em></p>\n</blockquote>\n\n<p>But, have you considered calling a st... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-07T16:01:20.177",
"Id": "18321",
"Score": "3",
"Tags": [
"optimization",
"sql"
],
"Title": "Optimize a Sql subquery containing multiple inner joins and aggregate functions"
} | 18321 |
<p>Okay, so I wrote this function yesterday for one of our websites here at the office, the site is responsive, but one of the banners wasn't behaving at a certain screen size (was getting chopped off when screen size was less than 1067px). Basically, this script checks for window size of 1067px (higher than 1068px, ba... | [] | [
{
"body": "<p>Ok, assuming:</p>\n\n<ul>\n<li>You didn't use media queries for cross-browser reasons</li>\n<li>This function is already bound to a resize event, since you didn't include what triggers the function call</li>\n<li>Assuming that <code>this</code> is the <code>window</code> object, judging from the w... | {
"AcceptedAnswerId": "18331",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-07T22:29:10.250",
"Id": "18328",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Refactor/Review JS function which moves a banner on window resize"
} | 18328 |
<p>I came across an exercise (in the book "The Art and Science of Java" by Eric Roberts) that requires using only GArc and GLine classes to create a lettering library which draws your initials on the canvas. This should be made independent of the GLabel class.</p>
<blockquote>
<p>Write a <strong><code>GraphicsProgra... | [] | [
{
"body": "<ol>\n<li><p>You might want to remove the unused lines. The code does not use <code>line[2]</code>, <code>line[4]</code>, <code>line[5]</code>, <code>line[18]</code> etc.</p></li>\n<li><p>You should check the input value of the <code>GLetter</code> class. Currently it does not show, for example, lett... | {
"AcceptedAnswerId": "20423",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-07T23:37:49.470",
"Id": "18332",
"Score": "2",
"Tags": [
"java",
"api"
],
"Title": "ACM API based Java exercise"
} | 18332 |
<p>Here is my QuadTree class and node.</p>
<p>The problem is really with Querying.</p>
<p>In my game, I have a city which can have n * n streets (randomly generated).
And each street has buildings.</p>
<p>What I do is put all buildings and roads in a quadtree and render the result. The problem is as the city gets bi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T15:52:30.797",
"Id": "59081",
"Score": "0",
"body": "Did you profile that code? What happens when the city size grows by 10x? 100x? (Without doing anything else than quadtree queries.)"
},
{
"ContentLicense": "CC BY-SA 3.0",... | [
{
"body": "<p>Unless you really need fast performance for head-insert, or <code>iterator.add()</code>/<code>remove()</code>, then LinkedList is almost always the wrong choice for a program.</p>\n\n<p>Certainly, LinkedList has a bigger footprint on memory (it takes up many times more bytes of memory than the equ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T00:23:59.280",
"Id": "18334",
"Score": "3",
"Tags": [
"java",
"optimization",
"performance",
"complexity"
],
"Title": "Not getting Log(n) performance from quadtree"
} | 18334 |
<p>I'm new to Python, just attempted the task <a href="https://www.cs.duke.edu/courses/cps100/fall03/assign/extra/treesum.html" rel="nofollow">here</a>.</p>
<p>The part I found hardest was parsing the expression into the tree structure. I was originally trying to build a regular tree structure (i.e. a Node object with... | [] | [
{
"body": "<ol>\n<li><p><strong>Avoid indentation</strong>.</p>\n\n<pre><code> print \"no\"\n</code></pre>\n\n<p>When you need this amount of spaces in front of your code, I'd say <em>no</em> too.</p>\n\n<p>This is clearly a sign that what you're writing could be extracted into a function... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T09:48:31.203",
"Id": "18342",
"Score": "5",
"Tags": [
"python",
"beginner"
],
"Title": "Parsing s-expression structure into tree and summing the paths"
} | 18342 |
<p>I'm writing a validation class, and I need one version which takes one type parameter, and one which takes two, and who knows one day I might want one which takes three. I have a lot of repeated code as the two versions are effectively identical except for the different number of type parameters. I'm looking for sug... | [] | [
{
"body": "<p>The biggest difference between the two classes is whether they use <code>IValidate<T></code> or <code>IValidate<T, K></code>. So, you want to create a base class that can use either of those types in a type-safe manner. You can do that by making the base class also generic, so your der... | {
"AcceptedAnswerId": "18389",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T12:19:22.687",
"Id": "18344",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Identical classes with different number of type parameters"
} | 18344 |
<p>I have two sieves that I wrote in python and would like help optimizing them if at all possible. The divisorSieve calculates the divisors of all numbers up to <code>n</code>. Each index of the list contains a list of its divisors. The numDivisorSieve just counts the number of divisors each index has but doesn't stor... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T02:04:30.323",
"Id": "29298",
"Score": "0",
"body": "What are you doing with the result?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T02:31:49.577",
"Id": "29301",
"Score": "0",
"body":... | [
{
"body": "<p>You can use <code>xrange</code>'s third param to do the stepping for you to shave off a little bit of time (not huge).</p>\n\n<p>Changing:</p>\n\n<pre><code>for j in xrange(1, n / i + 1):\n divs[i * j].append(i)\n</code></pre>\n\n<p>To:</p>\n\n<pre><code>for j in xrange(i, n + 1, i):\n divs[... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T13:16:23.207",
"Id": "18346",
"Score": "4",
"Tags": [
"python",
"optimization"
],
"Title": "Optimizing Divisor Sieve"
} | 18346 |
<p>This is a script I use to count how many items are selected in a form. It currently loops through the entire form to count how many check boxes are selected, each time a checkbox is clicked. The form has thousands of checkboxes, and it's painfully obvious how slow the script is with this many elements (About 18,240 ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T00:44:12.483",
"Id": "29293",
"Score": "0",
"body": "Adding a listener to every checkbox is pretty inefficient (though much better than your original). See my answer for how to use a single listener on the form instead (same concept... | [
{
"body": "<p>Maybe the slowlyness is because you do not use the default functions. I never heard of the function \"multi\".</p>\n\n<pre><code>function countSelected()\n{\n var form = document.forms.resultsForm;\n var counter = 0;\n\n for (var i = 0; i < form.elements.length; i++)\n {\n v... | {
"AcceptedAnswerId": "18355",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T15:14:50.017",
"Id": "18349",
"Score": "5",
"Tags": [
"javascript",
"performance",
"form",
"dom"
],
"Title": "Counting thousands of selected checkboxes"
} | 18349 |
<p>I've been reading <em>The Pragmatic Programmer</em> for a few days and I've come across a reference to the strategy pattern. Looked it up in <em>Design Patterns</em> and figured I could refactor a piece of code I'm currently working on to comply with the strategy pattern.</p>
<p>I need to process text using many st... | [] | [
{
"body": "<p>It seems like a you should implement Chain of responsibility as you are passing the same string to different kind of processor with a particular sequence</p>\n\n<p><a href=\"http://www.dofactory.com/Patterns/PatternChain.aspx#_self1\">http://www.dofactory.com/Patterns/PatternChain.aspx#_self1</a><... | {
"AcceptedAnswerId": "18359",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T15:32:41.133",
"Id": "18352",
"Score": "12",
"Tags": [
"c#",
"design-patterns"
],
"Title": "Is this a good example of the strategy pattern?"
} | 18352 |
<p>Just saw this at work in a code review and was wondering if this style of coding - for loop, doing && like that, seems fine to you or is there a better way of doing the same?</p>
<pre><code>for (int j = 1; j <= ETtop; j++)
{
// Check everything.
int k = ET[j].PriIdx;
for (int z = 1; z <= ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T22:20:47.577",
"Id": "29267",
"Score": "1",
"body": "Yep seems ok to me. Perhaps minor changes might be changing j, z and k to an actual meaning if relevant."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012... | [
{
"body": "<p>Currently, once you get <code>ready</code> to be false, all other checks after that will fail (as <code>false && condition2</code> will always be false). </p>\n\n<p>Why not just break out of the inner for loop when <code>ET[k].Arg[z].Valid</code> is false? If <code>ready</code> is needed... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T21:13:33.130",
"Id": "18363",
"Score": "3",
"Tags": [
"c#",
"algorithm"
],
"Title": "Is this a right and effcient way of checking AND in a for loop"
} | 18363 |
<p>I want to insert about 10000 new rows into an existing table which already contains 10000 rows. I need to get the <code>insertid</code> for the query and to use that <code>id</code> in another function inside the loop.</p>
<pre><code>foreach($values as $val){
$sql = "INSERT INTO wp_posts (`post_author`, `post_da... | [] | [
{
"body": "<p>Before I continue, the following must be said:</p>\n\n<h1>Stop using <code>mysql_query</code>.</h1>\n\n<p>Seriously. There have been very good replacements for going-on a decade now. And considering this code does not appear to escape anything at all, you'd do well to learn to use parameterized ... | {
"AcceptedAnswerId": "18368",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T21:44:59.803",
"Id": "18365",
"Score": "2",
"Tags": [
"php",
"performance",
"mysql"
],
"Title": "Inserting new rows into an existing table"
} | 18365 |
<p>I am using C# and the .NET entity framework, and I'm also learning how to better use OOP concepts in my program. My code is all displayed below. I would like to ensure my logic is properly organized before I try to implement the next step in my program.</p>
<p>My goal is twofold:</p>
<ol>
<li>Ensure my code is SO... | [] | [
{
"body": "<p>A few comments on your code as follows :</p>\n\n<ol>\n<li><p>Your UI code should not contain a <code>SaveChanges</code> methods as per SRP, it should be in EF itself.</p></li>\n<li><p>Your UserInterface is actually just a utility method. Encapsulate your validation\nand prompt logic different plac... | {
"AcceptedAnswerId": "18393",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T21:48:33.153",
"Id": "18366",
"Score": "1",
"Tags": [
"c#",
"entity-framework",
"crud"
],
"Title": "Preparing code for more versatile CRUD functions"
} | 18366 |
<p>This is what I have, But I think I can write it in a sohrter and more efficient way too, what do you suggest?</p>
<pre><code> string actionString= string.Empty;
if (auditAction == DSRHelper.SaveStatusEnum.Save)
{
actionString = Properties.Resources.SAVE_ACTION_MESSAGE;
}
if (auditAction... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T22:37:03.730",
"Id": "29272",
"Score": "1",
"body": "I really don't like the nested 'if' in the 'else if'. I would go with the method solution below."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T2... | [
{
"body": "<p>Maybe a switch? Although whether it's shorter or more efficient or even easier to read up for debate.</p>\n\n<pre><code>string actionString = GetStatusMessage(auditAction);\n\n// ...\nfunction GetStatusMessage(DSRHelper.SaveStatusEnum status) \n{\n switch(status)\n {\n case DSRHelper.Sav... | {
"AcceptedAnswerId": "18370",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T22:25:46.213",
"Id": "18369",
"Score": "3",
"Tags": [
"c#"
],
"Title": "Is there better way of writing these IF checks?"
} | 18369 |
<p>My <a href="https://www.github.com/silvinci/node-sanitize-arguments" rel="nofollow">argument sanitization</a> lib has a byproduct which does some typechecking and constructor investigation. I'm unsure if I'm using the fastest / most efficient approach here.</p>
<p>What are your opinions? Total rubbish or does it ha... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T00:41:24.820",
"Id": "29292",
"Score": "2",
"body": "You could return the string `\"anonymous\"` instead of `false` for a function name. Also it will throw an error for `[1]` because `.match()` can return `null`"
},
{
"Conte... | [
{
"body": "<p>Fun question,</p>\n\n<p>I believe the only reliable way of getting the name and parameters of a function is to indeed parse the <code>toString</code>. However, you can figure out whether the parameter is a function without a regex. I would propose from <a href=\"https://codereview.stackexchange.co... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T23:53:08.657",
"Id": "18372",
"Score": "4",
"Tags": [
"javascript",
"node.js"
],
"Title": "Type / Constructor testing utilities"
} | 18372 |
<p>I'm working on a school project right now. It's an ordered(ascending) doubly linked list. I just wrote the Insert operation on it but I feel like the way I wrote it isn't that great.</p>
<pre><code>void OrdListClass::Insert(ItemType item)
{
if(Find(item))
{
//throw DuplicateKeyException;
}//End ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T08:33:23.530",
"Id": "29331",
"Score": "0",
"body": "Could you explain a bit more about the `Find` function? Is it used elsewhere in the class? Is it public?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-... | [
{
"body": "<p>I think your <code>Insert</code> function is about as tight as you can make it without getting into strictly-organizational functions to tuck the list details (<code>head</code>, <code>tail</code>) and node details (<code>next</code>, <code>prev</code>) out of sight. Not a big deal for this one fu... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T00:04:57.193",
"Id": "18373",
"Score": "1",
"Tags": [
"c++",
"linked-list"
],
"Title": "Ordered Doubly Linked List Insertion"
} | 18373 |
<p>Based off simple controller implementations like those seen in micro-frameworks like Slim, Silex, F3, Laravel, Tonic, Flight, Klein, etc.</p>
<p>/EDIT tried to link the above sources, but as a new user I only get 2 links...</p>
<p>Any potential issues? Improvements? </p>
<pre><code>class Router {
priva... | [] | [
{
"body": "<p>I'm not seeing why you <code>preg_match_all</code>, considering you (can!) really only deal with the first match. Why not something like </p>\n\n<pre><code>if (preg_match($pattern, $url, $params)) {\n array_shift($params);\n return call_user_func_array($callback, array_values($params));\n}\... | {
"AcceptedAnswerId": "18377",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T02:21:47.880",
"Id": "18376",
"Score": "3",
"Tags": [
"php"
],
"Title": "Simple PHP Router"
} | 18376 |
<p>For homework, I had to write an RPN Evaluator and write the results to a text file. I've done all that, but it feels weird, like the writing to my results text file. It also doesn't feel efficient. There are some constraints, like no <code><vector></code> or <code><string></code> libraries and no other e... | [] | [
{
"body": "<p>Once you've underflowed the stack, an expression is invalid. Every operation from that point til the next <code>;</code> could be considered broken. Even if the expression later \"recovers\" and contains enough extra operands to look valid at the end, at some point along the way an invalid opera... | {
"AcceptedAnswerId": "18404",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T02:58:56.100",
"Id": "18378",
"Score": "2",
"Tags": [
"c++",
"homework",
"stack",
"math-expression-eval"
],
"Title": "RPN Evaluator that writes the results to a text file"
... | 18378 |
<p>I have 2 methods that do almost the same things except a few lines of code. The sample is like below.</p>
<pre><code>public void Method1()
{
DoX();
if (value)
{
var input = GetA();
DoA1();
DoA2(input);
}
DoY();
}
public void Method2()
{
DoX();
if (value)
{... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T04:21:11.463",
"Id": "29311",
"Score": "2",
"body": "ermmm, Perhaps you could post the actual code and see if someone could offer comment. Or perhaps this is better suited for SE??"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>Yes your code needs few re-factoring.Always remember encapsulate logic in one place if it varies.</p>\n\n<p>try this way and include a new param bool and when you need to include it pass true else false </p>\n\n<pre><code>public void Method1(bool IncludeDoA1)\n {\n DoX();\n\n i... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T04:01:55.103",
"Id": "18379",
"Score": "3",
"Tags": [
"c#"
],
"Title": "How to remove code duplication that difference only a few lines?"
} | 18379 |
<p>I'm brand new at OOP PHP and I would like to get as many of the coding conventions right as fast as possible. I made this tiny guestbook script, and I would like to know if there's anything not done as it should.</p>
<p><strong>Index.php:</strong></p>
<pre><code><?php
$username = "root";
$password = "";
$databa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T08:27:49.807",
"Id": "29338",
"Score": "0",
"body": "You might want to take a look at the PHP manual online about your use of database operations for MySQL for example `mysql_query()` is no longer suggested http://php.net/manual/en/... | [
{
"body": "<p>This is not at all OOP. guestbook.php has a class and contains few methods but that doesn't mean that you are applying OO concepts. I am afraid that your example has little scope to apply OO. Few improvements you can do here, separate presentation logic from getPosts(). </p>\n\n<p>Thus getPosts() ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T08:27:10.357",
"Id": "18386",
"Score": "3",
"Tags": [
"php",
"object-oriented"
],
"Title": "Guestbook script"
} | 18386 |
<p>This is a simple demonstration of a singly linked list, from my class work:</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <wctype.h>
#include <errno.h>
#include <assert.h>
#include <ctype.h>
#include <stddef.h>
#include <wchar.h>
#include <locale.h... | [] | [
{
"body": "<p>I'm not a C-guru at all but I believe I can give you a few advices to improve your code:</p>\n\n<ol>\n<li><p>Review your included libraries. Do you really need all those ones? Nope. <del>Chuck Testa</del> You only use <code>stdio.h</code> and <code>stdlib.h</code>.</p></li>\n<li><p><code>main()</c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T09:10:26.487",
"Id": "18387",
"Score": "2",
"Tags": [
"c",
"linked-list"
],
"Title": "Demonstration of a singly linked list"
} | 18387 |
<p>It was written in Emacs Lisp and requires Common Lisp loop facility.</p>
<p>Can this code be improved? Did I hit any anti-patterns along the way?</p>
<pre><code>(defun combos (list)
(let* ((a (car list))
(d (cdr list))
(s (and d (combos d)))
(v (loop for c in s collect (cons a c))))
... | [] | [
{
"body": "<p>I would suggest handling a nil input explicitly. Then you can:</p>\n\n<ul>\n<li>strip out the <code>and</code> (in <code>s</code>'s binding), and just recurse directly</li>\n<li>strip out the <code>cons</code> at the bottom, leaving only the <code>append</code></li>\n</ul>\n\n<p>Here's the code I ... | {
"AcceptedAnswerId": "18400",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T12:57:47.637",
"Id": "18398",
"Score": "6",
"Tags": [
"combinatorics",
"lisp",
"elisp"
],
"Title": "Combinations of list elements"
} | 18398 |
<p>I wrote a simple class implementing the <code>collections.Sequence</code> interface, that forwards calls to its items to member functions of its items.</p>
<p>I'm requesting a review of the following code snippet.</p>
<pre><code>import collections
class ForwardSequence(collections.Sequence):
def __init__(self... | [] | [
{
"body": "<pre><code>import collections\n\nclass ForwardSequence(collections.Sequence):\n def __init__(self, *args, **kw):\n super(ForwardSequence, self).__init__()\n self._sequence = tuple(*args)\n</code></pre>\n\n<p>A tuple only takes on argument, why are you passing a variable number of arg... | {
"AcceptedAnswerId": "18408",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T13:13:08.203",
"Id": "18399",
"Score": "3",
"Tags": [
"python"
],
"Title": "Forwarding sequence"
} | 18399 |
<p>I'm just starting to develop more in C# after being mainly a VB.NET developer and was looking for someone to critique my implementation of a NewtonSoft Json.Net serialiser.</p>
<p>Can you provide some feedback on the following points:</p>
<ol>
<li>Is this a good way to build the class (using Unity)?</li>
<li>Is it... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-10T03:39:22.470",
"Id": "29388",
"Score": "2",
"body": "I don't see anything wrong with throwing the exception in the constructor. If the parameter is required, it's required. At least caught in the constructor you have a chance to r... | [
{
"body": "<p>Code looks good, I like this IoC style.\n3 points to your consideration:</p>\n\n<ol>\n<li>You should <code>catch</code> an <code>AggregateException</code> over <code>await</code>.</li>\n<li>I wouldn't bother passing a <code>logger</code> to a <code>serializer</code> - that's none of his business. ... | {
"AcceptedAnswerId": "18556",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T13:22:21.203",
"Id": "18401",
"Score": "11",
"Tags": [
"c#",
"json",
"serialization",
"async-await",
"json.net"
],
"Title": "NewtonSoft Json.Net serialiser"
} | 18401 |
<p>I have been working on a Playfair Cipher in C++ for a final Project in a Cryptography class. I was hoping for some feedback on the project so far. I recently got a job programming before I've even graduated and I feel like I've already learned so much.</p>
<p>I would just like some feedback on my code style, commen... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T19:46:22.013",
"Id": "29362",
"Score": "0",
"body": "Can you post the header file so we can see the interface."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T02:05:21.980",
"Id": "29538",
"Sc... | [
{
"body": "<p>Code looks clean and readable. 3 quick remarks:</p>\n\n<ol>\n<li>Magic numbers and string: Move'm aside. What's with that <code>5</code> ? Is that a cosmic constant, or something your boss may change tomorrow? Make it <code>#define</code> or <code>extern</code>.</li>\n<li>Defend your code. Your <c... | {
"AcceptedAnswerId": "18446",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T16:18:58.577",
"Id": "18407",
"Score": "4",
"Tags": [
"c++",
"cryptography"
],
"Title": "Playfair Cipher in C++"
} | 18407 |
<p>Below is a script I've written that uses AJAX to check if all links on the page are alive or dead. Could this be modified to be more efficient in any way? Thank you very much.</p>
<pre><code>$(document).ready(function() {
var liveLinks = [];
var deadLinks = [];
function updateLive() {
$live = N... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T20:20:37.763",
"Id": "29364",
"Score": "0",
"body": "For readability sake, you can remove the quotes around the JSON properties, i.e.: `width: \"130px\", border: \"1px solid black\"`"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>First of all, jQuery's <code>error</code> callback gets invoked on network errors, parser errors, or 4xx/5xx <a href=\"http://httpstatus.es\" rel=\"nofollow\">HTTP status codes</a>.</p>\n\n<p>The status codes do not necessarily mean that a link is dead. At least there's a server at the other end. ... | {
"AcceptedAnswerId": "18413",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T18:35:51.167",
"Id": "18412",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"ajax"
],
"Title": "Optimize JQuery/JavaScript Link Checker"
} | 18412 |
<p>Here's some code that removes the specified character, <code>ch</code>, from the string passed in. Is there a better way to do this? Specifically, one that's more efficient and/or portable?</p>
<pre><code>//returns string without any 'ch' characters in it, if any.
#include <string>
using namespace std;
string... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-10T01:21:51.500",
"Id": "29381",
"Score": "1",
"body": "Where is iostream involved in this? Also, there's a one-liner version of it, though I'm not quite sure how the performance will compare: `str.erase(std::remove(str.begin(), str.e... | [
{
"body": "<p>I'm not entirely sure how the performance will compare, but the standard way to accomplish this would be the <a href=\"http://en.wikipedia.org/wiki/Erase-remove_idiom\" rel=\"nofollow\">erase-remove idiom</a>:</p>\n\n<pre><code>str.erase(std::remove(str.begin(). str.end(), ch), str.end());\n</code... | {
"AcceptedAnswerId": "18444",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T19:51:56.037",
"Id": "18415",
"Score": "3",
"Tags": [
"c++"
],
"Title": "Stripping specified character"
} | 18415 |
<p>I'm using linear algebra as my basis. One very specific change I'd like to make is to allow for equality tests between points and vectors with an unequal number of components by assuming that all undefined components are zero (all points and vectors have infinite components; equality tests stop testing once a check ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T20:29:31.037",
"Id": "29367",
"Score": "0",
"body": "Why don't you use numpy? It's fast, reliable and extremely powerful."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T20:46:27.617",
"Id": "2936... | [
{
"body": "<pre><code>import math, sys, os\n\nTOLERANCE = 0.00001\n\nclass SizeError(Exception):\n def __init__(self, *args):\n self.args = args\n print \"Size Error between \" + str(args)\n</code></pre>\n\n<p>You shouldn't print in an exception constructor. At most, you should define a <code>_... | {
"AcceptedAnswerId": "18429",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T20:20:45.593",
"Id": "18418",
"Score": "1",
"Tags": [
"python",
"beginner"
],
"Title": "Linear algebra architecture"
} | 18418 |
<p>I made this Rock Paper Scissors game and I would like for this to be critiqued.</p>
<pre><code>import System.IO
import System.Random
import Control.Monad
import Control.Arrow
data Throw = Rock | Paper | Scissors
deriving (Show, Read, Enum, Bounded)
instance Random Throw where
random g = first toEnum ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-10T09:06:47.403",
"Id": "29397",
"Score": "0",
"body": "I can't see any way to improve. Well done! Hackage should have a template Haskell library to derive of `Random` instances but as far as I know it doesn't have yet."
}
] | [
{
"body": "<p>The style is pretty good, I can just see two minor improvements you could do: Firstly, you can define <code>random</code> in terms of your own <code>randomR</code> in order to save a few keystrokes:</p>\n\n<pre><code>instance Random Throw where\n random = randomR (minBound, maxBound)\n randomR (... | {
"AcceptedAnswerId": "18449",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T21:07:07.900",
"Id": "18422",
"Score": "7",
"Tags": [
"game",
"haskell",
"rock-paper-scissors"
],
"Title": "First attempt at writing Rock Paper Scissors game"
} | 18422 |
<p>I am writing a program for learning purposes that takes an input of a file structured similarly to:</p>
<blockquote>
<pre><code>13,22,13,14,31,22, 3, 1,12,10
11, 4,23, 7, 5, 1, 9,33,11,10
40,19,17,23, 2,43,35,21, 4,34
30,25,16,12,11, 9,87,45, 3, 1
1,2,3,4,5,6,7,8,9,10
</code></pre>
</blockquote>
<p>Which will then... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-12-16T04:22:29.853",
"Id": "211423",
"Score": "0",
"body": "Asking for help fixing bugs, or helping you write new features is off-topic, I've edited that paragraph out."
}
] | [
{
"body": "<p>Brad, you code compiles cleanly, which is a good sign :-) Clearly it could be split into functions. An obvious approach would be to split the reading of the values from the processing of those values. </p>\n\n<p>I would take a slightly different approach, but remember there is no one \"correct\" ... | {
"AcceptedAnswerId": "18432",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T21:17:20.117",
"Id": "18423",
"Score": "1",
"Tags": [
"performance",
"c",
"array"
],
"Title": "Printing the largest sum from integers in a file"
} | 18423 |
<p>I was asked a question in an interview the other day:</p>
<blockquote>
<p>You have an array list of numbers from 1 to 100, the problem is that
one number is missing. How would you find that number?</p>
</blockquote>
<p>This is a mock of the question. The code seems to work.</p>
<p>Could you give me some feedb... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T10:44:56.993",
"Id": "29478",
"Score": "0",
"body": "as sky said you can count list size(). If you want know the missing number, use a TreeSet instead of List , then parse it with Jeremy K finder"
},
{
"ContentLicense": "CC ... | [
{
"body": "<p>If the list is ordered like in your example you could do something like:</p>\n\n<pre><code>for (int i = 0; i < ints.size(); ++i) {\n if (i + 1 != ints.get(i)) {\n return i + 1;\n }\n}\n</code></pre>\n\n<p>The value will always be 1 more than the index (since you start at 1 and not ... | {
"AcceptedAnswerId": "18443",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T22:06:03.033",
"Id": "18424",
"Score": "9",
"Tags": [
"java",
"interview-questions"
],
"Title": "Find missing number from list"
} | 18424 |
<p>I am working on legacy code, specifically a sort of BoundedBlockingQueue (mainly used as a pipe between different threads). As it is heavily used in the system and the current implementation features fully synchronized methods and a wait/notify mechanism, I attempted to rewrite it, using the java 5 concurrency utili... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-10T15:48:54.063",
"Id": "29410",
"Score": "0",
"body": "The present perfect of `write` is `has written`, so I'd use that instead of `hasWrote`. Apart from that: wouldn't this be a good opportunity to update the queue to use generics? L... | [
{
"body": "<ol>\n<li><p>read or write methods requires 3 synchronization operations (2 semaphore operations and one access to the LinkedBlockingQueue. If you use synchronized methods (or locking with ReentrantLock) and non-synchronized underlying queue, then only one synchronization operation is needed per read... | {
"AcceptedAnswerId": "18448",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T22:38:23.070",
"Id": "18427",
"Score": "3",
"Tags": [
"java",
"optimization",
"multithreading"
],
"Title": "Closable BlockingQueue"
} | 18427 |
<p>I created small module to help me create rich sendgrid html emails using the mako templating engine. Any feedback on the design would be appreciated:</p>
<p>makosg.py</p>
<pre><code>from sendgrid.message import Message
from mako.template import Template
from mako.lookup import TemplateLookup
class MakoMessage(Me... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-10T04:03:55.833",
"Id": "29389",
"Score": "1",
"body": "Can you please post the code you need reviewed in the question. It makes it easier for people to review. Also the link you provided might go dead some day which makes this quest... | [
{
"body": "<p>Here a few things I spotted (not necessarily design related):</p>\n\n<ul>\n<li><code>vars</code> is a builtin, and should be avoided as a variable name. Many template systems call this the context (what you are calling vars), so that's probably a better name.</li>\n<li><p>Defaulting function para... | {
"AcceptedAnswerId": "18458",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-09T23:28:20.307",
"Id": "18430",
"Score": "0",
"Tags": [
"python"
],
"Title": "Sendgrid + Mako email templates quick code review"
} | 18430 |
<p>I'm working on an exercise where I"m supposed to display all data contained in a table. Here's the solution I can up with:</p>
<pre><code><?php
$result = mysql_query("SELECT * FROM contacts ORDER BY id DESC");
while($user= mysql_fetch_array($result)) {
echo $user['first'] . " " . $user['last'] . "&l... | [] | [
{
"body": "<p>Yours is better. Both are bad.<br></p>\n<h2>Don't use either of them</h2>\n<p>The mysql_* functions aren't a good way to learn how to interact with databases. It is a shame that there are still tutorials teaching how to interact with databases using these functions. Here is a snippet that expla... | {
"AcceptedAnswerId": "18434",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-10T01:36:27.553",
"Id": "18433",
"Score": "2",
"Tags": [
"php",
"beginner",
"mysql"
],
"Title": "Echoing table contents"
} | 18433 |
<p>I want to "canonicalize" URLs for my static (files and folders) website.</p>
<p>The 'Aims' describes what I want to accomplish. The 'Code' gives my current <code>.htaccess</code>. </p>
<p>Everything works right now, but I wonder if the code could be improved:</p>
<ul>
<li>any changes for better performance?</li>
... | [] | [
{
"body": "<p>First, I'll start with an observation that applying these rewriting rules — in particular, removing trailing slashes in the URL — can break pages that reference relative URLs. I assume you know that and want to proceed anyway.</p>\n\n<p>In general, you should realize that every <code>RewriteRule<... | {
"AcceptedAnswerId": "45069",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-10T04:52:58.443",
"Id": "18440",
"Score": "7",
"Tags": [
"optimization",
"url",
".htaccess"
],
"Title": "Canonicalize URLs for static website"
} | 18440 |
<p>This code smells to me, but I don't see the way to clean it up. I see v. mentioned over and over. Any hints would be appreciated!</p>
<pre><code> #
# Create a new Value if it doesn't already exist, and initialize the attributes per
# the parameters of the call.
#
def self.find_or_create_value(prog_id, part... | [] | [
{
"body": "<p>Well I will repost my answer from stackoverflow for further discussion:</p>\n\n<p>Ok here is a couple of things/smells that I notice about this:</p>\n\n<ol>\n<li>A method with over 4 parameters is a smell itself... that makes it unnecessarily complex. Maybe find objects that encapsulate some of th... | {
"AcceptedAnswerId": "18454",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-10T22:03:29.317",
"Id": "18451",
"Score": "3",
"Tags": [
"ruby"
],
"Title": "Repeating use of \"v.\" annoys me. Do you see a nicer way?"
} | 18451 |
<p>Examples of code smells include</p>
<ul>
<li>many parameters to a function</li>
<li>difficult test code setup</li>
<li>low cohesion</li>
<li>high coupling.</li>
</ul>
<p>A code smell does not mean that there is a problem - but it points to a problem.</p>
<p>A good resource on them can be found on the <a href="htt... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-11T04:01:23.890",
"Id": "18456",
"Score": "0",
"Tags": null,
"Title": null
} | 18456 |
A sign of a possible problem in a program. Use this tag for code reviews where you can already "smell" something and would like others to confirm your thoughts or dissipate your doubts, and hopefully to propose ideas for making it "smell better". | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-11T04:01:23.890",
"Id": "18457",
"Score": "0",
"Tags": null,
"Title": null
} | 18457 |
<p>The logic is simple, but I was wondering if anyone could help with rewriting the conditional logic. Also, the only error conditions I can think of are the sides should not be equal to or less than zero. Are there any other error conditions that seem to occur to you?</p>
<pre><code>public class TriangleType {
s... | [] | [
{
"body": "<p>The code seems to work...</p>\n\n<p>For enhancements:</p>\n\n<pre><code>if (a == b && b == c && c== a)\n</code></pre>\n\n<p>is redundant. Shorter is</p>\n\n<pre><code>if (a == b && b== c)\n</code></pre>\n\n<p>because in this case <code>a == c</code> holds always true.</p>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-11T16:57:39.390",
"Id": "18463",
"Score": "8",
"Tags": [
"java"
],
"Title": "Determining triangle type from three integer inputs"
} | 18463 |
<p>I'm looking for a good and easy to use solution for creating MultiSelectLists in MVC for many-to-many relationships.</p>
<p>I have this following example code and it works fine, but it just takes a lot of code. It would be cool if it were shorter, smarter, or even made generic somehow, so that it's easy to create ... | [] | [
{
"body": "<p>Rather than using ViewData I might consider using ViewBag (if on MVC 3 and above) or even wrapping Author within a ViewModel. That what you won't need the cast on the view (if using a viewModel).</p>\n\n<p>Otherwise your MultiSelectList code is only one line. Don't see you getting much better th... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-11T18:31:02.257",
"Id": "18466",
"Score": "6",
"Tags": [
"c#",
".net",
"mvc",
"entity-framework",
"asp.net-mvc-4"
],
"Title": "ListBox for a many-to-many relationship"
} | 18466 |
<p>I wrote some code to validate a form, I'm using live validation, as the user types, here is the snippet that I wrote just for the live validation, but I think I'm repeating too much and I'm looking for some advices:</p>
<pre><code> $('form input').focus(function(){
var inp = $(this).attr('name');
switc... | [] | [
{
"body": "<p>Overall, I see the following issues with your code</p>\n\n<ul>\n<li>It's coupled way to tightly to the markup</li>\n<li>It's overly complex</li>\n<li>You call <code>$(this)</code> again and again without ever caching the result</li>\n<li>It's repetitive</li>\n</ul>\n\n<p>I won't be posting fully r... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-11T19:02:22.217",
"Id": "18468",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Code refactory for a form validation"
} | 18468 |
<p>I have a small function for filtering data from users. I'd like a review on logical mistakes I've made and if I'm somewhat protected using it.</p>
<pre><code>public static function filtru($str, $filtre = []){
if(is_array($str)){//verifica daca datele trimise spre curatare sant array
$str_curat = [];
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-11T23:12:47.867",
"Id": "29458",
"Score": "3",
"body": "This function isn't small; by modern standards, it's huge and should be split up."
}
] | [
{
"body": "<ul>\n<li>Your function should be broken into many more functions. Each different type of escaping should be its own function.</li>\n<li>You should either use separate functions where the array version calls the non-array version, or youo should try to fold your array and non array logic into one\n<... | {
"AcceptedAnswerId": "18488",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-11T20:08:33.770",
"Id": "18471",
"Score": "4",
"Tags": [
"php",
"security"
],
"Title": "Filtering data from users"
} | 18471 |
<p>So I have a function which creates a Playlist object. Currently, this function accepts two paramaters: id and name. However, it also exposes a method called 'loadData' which can set the entire object after construction. I'm realizing this is a poor way to go about things and would like to modify my code such that th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T12:29:18.997",
"Id": "29489",
"Score": "2",
"body": "Why is it important to prevent `a caller from extending my Playlist object with additional, unintended properties`?"
}
] | [
{
"body": "<p>You could use <code>||</code> instead of <code>$.extend</code>. eg:</p>\n\n<pre><code>id: config.id || Helpers.generateGuid(),\n</code></pre>\n\n<p>That has the benefit of not creating properties you don't use.</p>\n\n<p>Also, did you strip out some code? Because it seems like all you're doing is ... | {
"AcceptedAnswerId": "18759",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-11T22:39:49.233",
"Id": "18474",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"require.js"
],
"Title": "Refactoring a constructor to accept a config object"
} | 18474 |
<p>I'm a Python newbie and I'd like to know how I could clean this up/optimize it (but nothing too advanced, please).</p>
<p>As far as I know, it's working as it should, but if you see any errors then please point it out! This is a numerical guessing game with two symbols in front. You can pretty much see how it works... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-11T23:47:18.563",
"Id": "29459",
"Score": "4",
"body": "A good start would be not using globals - there is always a better way. In this case, pass more arguments and return more values."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<ul>\n<li><p>Not good:</p>\n\n<pre><code>points = points - 2 # lots of this kind of code\n</code></pre>\n\n<p>Good:</p>\n\n<pre><code>points -= 2\n</code></pre></li>\n<li><p>Not good:</p>\n\n<pre><code>allowed = list(string.digits + '+' + '*')\n</code></pre>\n\n<p>Good:</p>\n\n<pre><code>allowed = st... | {
"AcceptedAnswerId": "18533",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-11T23:34:37.937",
"Id": "18476",
"Score": "8",
"Tags": [
"python",
"optimization",
"beginner",
"game"
],
"Title": "Cleaning up/optimizing numerical guessing game"
} | 18476 |
<p>I have a class that delegates some responsibilities to another helper class which is abstract. When instantiating the class the user needs to provide a pointer to a concrete instance of the abstract helper class. I'm wondering who should be responsible for deleting the helper class instance, the user, or the class i... | [] | [
{
"body": "<p>It depends. (By the way, as things are your <code>Classifier::Train</code> function is ill-formed due to missing a return type; I'll assume <code>void</code>.)</p>\n\n<p>If you expect the value to need dynamic storage duration, use the first method, but use a smart pointer (<code>std::unique_ptr<... | {
"AcceptedAnswerId": "18479",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T02:52:03.223",
"Id": "18477",
"Score": "2",
"Tags": [
"c++",
"object-oriented"
],
"Title": "Ownership and deletion responsibility"
} | 18477 |
<p>Recently I had to lock collections (of type <code>List<T></code>) when items were added or removed. Because several collections were used in given code instead of creating helper methods for each collection, I made an extension methods:</p>
<pre><code>public static class MyExtension
{
public static void A... | [] | [
{
"body": "<p><strong>EDIT</strong>: +1 for throwing on null in extension method. That's the right way to go.</p>\n\n<ol>\n<li>Use <a href=\"http://msdn.microsoft.com/en-us/library/dd267312.aspx\" rel=\"nofollow\"><code>BlockingCollection</code></a> (starting .Net 4) - that's what it is for.</li>\n<li>Not sure ... | {
"AcceptedAnswerId": "18493",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T08:50:40.553",
"Id": "18483",
"Score": "12",
"Tags": [
"c#",
"thread-safety",
"collections"
],
"Title": "Add/Remove items thread-safely in List<T>"
} | 18483 |
<p>I've got one multimap: <code>mm1</code> and a map: <code>mm2</code>. The size of <code>mm1</code> is <em>usually</em> expected to be smaller than <code>mm2</code>. So I begin by iterating through <code>mm1</code>, and for each key in <code>mm1</code> that also exists in <code>mm2</code>, will print the values of the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T17:23:16.897",
"Id": "29507",
"Score": "0",
"body": "I don't understand what you are trying to achieve. The English description does not seem to match the first example. The key \"aa\" in mm1 is not in mm2 so why is it in the expect... | [
{
"body": "<p>You can merge both maps to a \"list\". That should give you O(n) complexity solution where n is a total number of elements in both maps.<br>\nmap elements are sorted from lower to higher, so simple iteration would yield an ordered list.<br>\nTo merge maps, you need to iterate both of the maps, ins... | {
"AcceptedAnswerId": "18522",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T11:13:04.957",
"Id": "18490",
"Score": "0",
"Tags": [
"c++"
],
"Title": "Iterating through one map and one multimap and printing the vlaue of common keys"
} | 18490 |
<p>I've been learning Haskell, and a while ago I created this Hangman game. I've been working on using a library for terminal output, so no more hardcoded escape codes, but in the meantime I'd like some comments on what I have until now.</p>
<p>Is this readable, correct Haskell code with no obvious performance problem... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T23:06:55.603",
"Id": "29585",
"Score": "2",
"body": "`startplaying words = do index <- randomRIO (0,length words)` should be `startplaying words = do index <- randomRIO (0,length words - 1)` so you don't go off the end of the list."... | [
{
"body": "<p>Why do you have so much redundant data in <code>State</code>? That just means you have to put a lot of effort into keeping everything up-to-date - which doesn't just make your program longer, but is also prone to mistakes.</p>\n\n<p>By eliminating all redundancy as well as replacing the explicit s... | {
"AcceptedAnswerId": "18549",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-11-12T14:41:57.220",
"Id": "18497",
"Score": "6",
"Tags": [
"game",
"haskell",
"hangman"
],
"Title": "Small Haskell Hangman game"
} | 18497 |
<p>Below is a simplified version of some code I am using to execute a function after all asynchronous calls complete. Is this a reasonable piece of code? It seems to work. Nothing would break if <code>DoStuff()</code> was called twice, though that would be very inefficient.</p>
<pre><code>var i = 0;
var done = funct... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T15:43:19.903",
"Id": "29502",
"Score": "0",
"body": "So you want `DoStuff()` called only when *both* are done?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T16:18:55.110",
"Id": "29503",
"Sc... | [
{
"body": "<p>The approach itself (i.e. using a counter) is reasonable, but the hard-coded <code>2</code> and <code>DoStuff</code> limits its use.</p>\n\n<p>You could do something like this, to derive more generic implementation:</p>\n\n<pre><code>function createCounter(count, callback) {\n count || (count = 1... | {
"AcceptedAnswerId": "18500",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T15:24:30.137",
"Id": "18499",
"Score": "1",
"Tags": [
"javascript",
"asynchronous",
"callback"
],
"Title": "Calling a function when all asynchronous calls complete"
} | 18499 |
<p>I had to create an executable to search and replace strings in a file. This is to be used in my installer for text file manipulation. I have various placeholders in configuration files that I need to replace with proper values after querying the end user system.</p>
<p>I have written the following code. This being ... | [] | [
{
"body": "<h2>Use the <code>params</code> keyword</h2>\n\n<pre><code>//The new Logger for the exe\nstatic void WriteLog(string exception, int status, params string[] arguments)\n{\n string logFile = string.Format(\"D:\\\\TempLogs\\\\Grep-{0:yyyy-MM-dd_hh-mm-ss-tt}.log\", DateTime.Now);\n StreamWriter gre... | {
"AcceptedAnswerId": "18503",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T16:04:32.803",
"Id": "18501",
"Score": "10",
"Tags": [
"c#",
"strings",
"beginner",
"exception-handling",
"file"
],
"Title": "Replace strings in a file"
} | 18501 |
<p>Are there any security vulnerabilities in this code?</p>
<p>
<pre><code>class Session {
private $id = array();
private $data = array();
private $name = 'session';
public function __construct() {
session_start();
global $db;
$this->id = isset($_COOKIE[$this->name]) ?... | [] | [
{
"body": "<p>Nope. Let's walk through it from a hypothetical attackers point of view.</p>\n\n<blockquote>\n <p>Okay. It's sending an identification cookie. It's hex. 32 digits long.\n Probably an md5 hash. I wonder what's hashed? I'll throw it in\n oclHashcat to check. I can make a billion guesses a second,... | {
"AcceptedAnswerId": "18507",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T16:53:48.707",
"Id": "18502",
"Score": "1",
"Tags": [
"php",
"security",
"session"
],
"Title": "Is this session handler secure?"
} | 18502 |
<p>I'm working on an app that downloads some SVG paths from a server and draws them. </p>
<p>Anything in here is open to critique, but specifically I'd like to review my use of a module pattern and my implementation and use of promise objects.</p>
<p>The "modules" are each a file, and the aim is to limit and explici... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T21:18:49.133",
"Id": "29522",
"Score": "0",
"body": "You shouldn't be using keywords like `then` as variable names. Most browsers will be ok with it, but it's by no means guaranteed."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>I assume that you are not going to use readily available third-party libraries for this one. If I had the option to, I'd be using jQuery as it already supports promises, and AJAX.</p>\n\n<p>Anyways, let's start reviewing. I pretty much explain in the comments so watch out for them. Any explanation... | {
"AcceptedAnswerId": "18755",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T20:19:06.937",
"Id": "18513",
"Score": "4",
"Tags": [
"javascript",
"design-patterns",
"ajax",
"modules"
],
"Title": "How are my javascript module pattern and promise patte... | 18513 |
<p>Ran across this question today:</p>
<blockquote>
<p>write a class Tool which will have a function void type() that every
derived class should implement . A function Action() that every
derived class can override . function init() which is available to
only Tool and variable Name which will tell which class`... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T22:16:52.890",
"Id": "29529",
"Score": "2",
"body": "One minor thing I noticed is that you don't include std::string"
}
] | [
{
"body": "<p>Your code does not work: <a href=\"http://codepad.org/OtKa9Aki\" rel=\"nofollow\">http://codepad.org/OtKa9Aki</a></p>\n\n<p>Just like calls to virtual functions in a constructor call the base class function, such usage of typeid also does not recognise the derived class. You could have the <code>... | {
"AcceptedAnswerId": "18530",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-12T22:03:10.150",
"Id": "18514",
"Score": "1",
"Tags": [
"c++"
],
"Title": "C++ Class Writing Interview Query"
} | 18514 |
<p>I have been looking everywhere to find good real world examples of the new Async and Await features in .net 4.5. I have come up with the following code to download a list of files and limit the number of concurrent downloads. I would appreciate any best practices or ways to improve/optimize this code.</p>
<p>We are... | [] | [
{
"body": "<p>Sorry, I did not look thoroughly through your code, but regarding \"good real world examples of the new Async and Await features\":</p>\n\n<p>Writing simple windows 8 store (ex-\"Metro-style\") application helped me greatly to understand and get used to async/await pattern.</p>\n\n<p>Basically, in... | {
"AcceptedAnswerId": "18679",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T01:24:50.080",
"Id": "18519",
"Score": "25",
"Tags": [
"c#",
"asynchronous"
],
"Title": "Real World Async and Await Code Example"
} | 18519 |
<p>I am wondering if in particular the function called <code>AssignDBStatusMessage</code> and <code>TryDataBaseAction</code> are unnecessary. It seems to me that the logic is more cluttered if i do away with those functions. Please provide me with your ideas and thoughts.</p>
<p>If you have other thoughts please let... | [] | [
{
"body": "<p>Not huge thoughts but a couple of things. </p>\n\n<ol>\n<li><p>I would probably consider making the entities object a class level parameter since it seems to be used in every method.</p></li>\n<li><p>I wouldn't put the success message in this class as that seems more caller dependant. Hence I wou... | {
"AcceptedAnswerId": "18524",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T01:39:06.397",
"Id": "18520",
"Score": "2",
"Tags": [
"c#",
"entity-framework"
],
"Title": "Am I using too many functions in my DataAccess Class?"
} | 18520 |
<p>There at least 2 patterns of using <code>Stack.Pop</code></p>
<ol>
<li>
<pre><code>private Stack<T> availableResources;
...
if (availableResources.Count > 0)
{
resource = availableResources.Pop();
...
}
</code></pre></li>
<li>
<pre><code>private Stack<T> availableResources;
...
try
{
resour... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T22:12:06.373",
"Id": "29741",
"Score": "0",
"body": "Save your exceptions for exceptional cases you don't know how to handle. Patterns 2 is good for wrapping a method that can fail for various non-related or unknown reasons (`Downlo... | [
{
"body": "<p>Program defensively and use option 1.</p>\n\n<p>Since the <code>Stack</code> class provides the ability to check whether it contains anything before trying to <code>Pop</code> a value from it, you should do the check and avoid using the exception for flow control.</p>\n\n<p>If you want to avoid do... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T10:28:11.343",
"Id": "18531",
"Score": "9",
"Tags": [
"c#",
"stack"
],
"Title": "Which is the most correct pattern for using Stack.Pop?"
} | 18531 |
<p>I wrote simple delegate in C++11 for my GUI project. I think that some parts can be optimized or cleaned.</p>
<pre><code>#ifndef DELEGATE_H
#define DELEGATE_H
//Container interface
template<typename... Args>
class IContainer
{
public:
virtual void Call(Args...) {}
virtual ~IContainer() {}
IContai... | [] | [
{
"body": "<h3>IContainer</h3>\n<p>In the class <code>IContainer</code> the member <code>next</code> is public. Which leads to potential incorrect useage.</p>\n<p>Non private members is a code smell they should be hidden behind access methods (not get/set but more like chain()). Also it would be easier if you u... | {
"AcceptedAnswerId": "18547",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T12:22:32.603",
"Id": "18537",
"Score": "2",
"Tags": [
"c++",
"optimization",
"c++11",
"delegates"
],
"Title": "Delegate for GUI project"
} | 18537 |
<p>I'm still trying to learn how to write good tests (and write testable code).</p>
<p>This is the function I want to verify, </p>
<pre><code> void IAutoTisDal.UpdateRange(Range range)
{
using (var repo = _repositoryFactory.GetRepository(_baseline))
{
var rangeqry = from r in repo.Query<Range&g... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T14:40:39.223",
"Id": "29564",
"Score": "0",
"body": "side topic: Would IAutoTisDal be a considered service layer or a data access layer? This is a problem-domain-specific interface that calls my `IRepository`. The concrete `IReposit... | [
{
"body": "<p>First of all, your single method is doing multiple things:</p>\n\n<ol>\n<li>Get Range by id </li>\n<li>Copy properties from one instance to another</li>\n<li>Commit</li>\n</ol>\n\n<p>Let's try to separate responsibilities:</p>\n\n<pre><code> Range GetRangeById(Repository repo, int id)\n {\n ret... | {
"AcceptedAnswerId": "18542",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T14:29:52.940",
"Id": "18541",
"Score": "6",
"Tags": [
"c#",
"unit-testing",
"moq"
],
"Title": "Is this UnitTest for updating an object in data-access layer sensible?"
} | 18541 |
<p>I'm new to Erlang and this is my first code in that. As Erlang has no loop statements, the only way I could think of doing this is as follows:</p>
<pre><code>-module(verschickten).
-export([f/0]).
f() -> io:format("~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~p ~... | [] | [
{
"body": "<p>I would use recursion here:</p>\n\n<pre><code>-module(arith_progr).\n-export([progr/3]).\n\nprogr(Start, _Increment, End) when Start > End ->\n io:format(\"~n\");\nprogr(Start, Increment, End) ->\n io:format(\"~p \", [Start]),\n progr(Start+Increment, Increment, End).\n</code></p... | {
"AcceptedAnswerId": "18586",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T14:53:07.490",
"Id": "18543",
"Score": "2",
"Tags": [
"beginner",
"erlang"
],
"Title": "Arithmetic progression to 7561"
} | 18543 |
<p>I'm making my first steps in ELisp programming and I want to know is there a better solution for this problem:</p>
<p>I have a file with two columns, that are separated by one or more spaces, ex.:</p>
<pre><code>One 1
Two 2
Three 3
Four 4
</code></pre>
<p>I'd like to make some alignment (columns are separated by... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2018-09-19T10:09:09.187",
"Id": "393286",
"Score": "0",
"body": "You are aware of the `align` command, that comes with Emacs? You seem to be addressing a solved problem."
}
] | [
{
"body": "<p>You should use <code>dolist</code> </p>\n\n<blockquote>\n <p>(dolist (VAR LIST [RESULT]) BODY...)</p>\n</blockquote>\n\n<p>and <code>insert-char</code> </p>\n\n<blockquote>\n <p>(insert-char CHARACTER &optional COUNT INHERIT)</p>\n</blockquote>\n\n<p>instead of the <code>while</code> constru... | {
"AcceptedAnswerId": "19150",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T16:30:31.130",
"Id": "18548",
"Score": "4",
"Tags": [
"elisp"
],
"Title": "Emacs column alignment command"
} | 18548 |
<p>I'm currently writing Report's system. I have about 20 different users with different access.
Am I doing it correctly? Can I improve my style of writing this code? All my reports based on the same structure.</p>
<p>In my Report's Controller:</p>
<pre><code>function my_report_name()
{
//current week by... | [] | [
{
"body": "<p>The code is fine, but why are you passing from date and to date to model ? Its not being used at model. May be you are trying to add a condition to filter the data set under specified dates. Anyway, your starting is good. Good luck.</p>\n",
"comments": [],
"meta_data": {
"CommentCoun... | {
"AcceptedAnswerId": "19732",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T19:01:00.497",
"Id": "18555",
"Score": "4",
"Tags": [
"php",
"mvc",
"codeigniter"
],
"Title": "Am I using MVC Codeigniter correctly?"
} | 18555 |
<p>I have been working with PHP sessions and login protected pages for some time, but I want to start using some AJAX for managing some actions inside login protected pages (easy way with jQuery).</p>
<p>Here is what I want to do:</p>
<p>The user logs in (classic no-AJAX method), and wants to submit a message. I make... | [] | [
{
"body": "<h2>Consider adding User Agent check</h2>\n\n<p>Adding a User Agent check will add another layer of security. This will slow down Session Hijacking a bit.</p>\n\n<h2>AJAX alone is not a security issue</h2>\n\n<p>AJAX is no more vulnerable then regular access when it comes to sessions. </p>\n\n<h2>SES... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T21:44:09.860",
"Id": "18564",
"Score": "2",
"Tags": [
"php",
"security",
"ajax",
"session"
],
"Title": "Using AJAX to secure sessions and save messages"
} | 18564 |
<p>The basic idea is not to allow the same text and add +1 at the end.</p>
<p>Imagine that I have a datagrid (WPF) with names, and every time I click the add button, I will put a new name on the list automatically by running this method to ensure that no two names are alike.</p>
<p>My standard used: if there is repea... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T07:56:00.957",
"Id": "29605",
"Score": "0",
"body": "It looks kind of under specified to me. What is the output of {\"t(1)\", \"a(2)\"}? {\"t(t(1))\", \"T(42)\"}? {\"hello\",\"world\"}? Your test suggests you didn't clarify to yours... | [
{
"body": "<p>Here's a way. Not fully Linq but using a little bit in the for loop. Also passes a few more unit tests than your original.</p>\n\n<p><strong>[EDIT]</strong>: After re-reading your question and some comments by other reviewers I added a few more unit tests and low and behold my original answer b... | {
"AcceptedAnswerId": "18597",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T23:44:13.903",
"Id": "18570",
"Score": "4",
"Tags": [
"c#",
"optimization",
"algorithm"
],
"Title": "Creating text without repetition"
} | 18570 |
<p>My friend wrote a program which compares random arrangements of die faces to find the one with the most evenly distributed faces - especially when the faces are not a mere sequence.</p>
<p>I translated his program into haskell because I've been looking for a reason to talk someone's ear off about how cool haskell i... | [] | [
{
"body": "<p>Just a quick observation: as the length of values and centers increase, the list indexes (!!) are increasingly inefficient. Try values :: Vector Float, centers :: Vector Center with Data.Vector.(!) and see if performance improves.</p>\n\n<p>I'm trying to see what other improvements can be made, I ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T02:25:26.340",
"Id": "18574",
"Score": "3",
"Tags": [
"performance",
"haskell",
"recursion"
],
"Title": "Haskell tips/why doesnt this scale linearly?"
} | 18574 |
<p>I am taking a data structures course. I would like to check whether my <code>BinaryTree</code> code is perfect, fine or has lots of mistakes.</p>
<p>I would like any kind of advice on this code so I can learn from my mistakes (syntax, techniques, style, etc...).</p>
<p><strong>Note: This is not a binary search tr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T08:24:41.850",
"Id": "29608",
"Score": "0",
"body": "In terms of generics, there should be no reason why you would be bounding it by `Integer` (which is `final` and doesn't make sense) -- it should be bounded by `Number` (`public cl... | [
{
"body": "<p>This is a good start. Here's what I have to say about it.</p>\n\n<ul>\n<li><p>There really is no point in making <code>E</code> constrained on <code>Integer</code>. The Integer class is <code>final</code> so it can't be anything but an <code>Integer</code>. Either remove that constraint or remo... | {
"AcceptedAnswerId": "18579",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T02:35:01.243",
"Id": "18575",
"Score": "3",
"Tags": [
"java",
"classes",
"tree"
],
"Title": "BinaryTree class with extra methods"
} | 18575 |
<pre><code> class session{
//variabile folosite
private static $_sessionStarted = false;
private static $_crypt = 'qwerty347658@$%AdfSV045*&erT2Erb%6w!07&[.?;ru';
private static $_salt = 'qwertyAF347658@$%AdfSV045*&erTyUsdfYtrLmncBGhu';
private static $_rand = 'abcdefghijklmnoqprstuvxwz0123456789!@#$%^... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T18:15:04.713",
"Id": "29648",
"Score": "1",
"body": "What are you trying to accomplish by encrypting session keys?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T19:43:34.133",
"Id": "29655",
... | [
{
"body": "<ol>\n<li><p>You said in a comment that you're storing half of the encryption key alongside the data the data you're encrypting, and the other half in the code itself. What's the point of that? If they have access to the PHP files, they probably have access to the session files, too.</p></li>\n<li><p... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T04:35:10.550",
"Id": "18577",
"Score": "3",
"Tags": [
"php",
"session"
],
"Title": "Php session wrapper class"
} | 18577 |
<p>I've never really done anything with concurrency, so I'm not sure if this is done correctly. </p>
<p>Basically, I have a class that handles all messages from the server and decides what to do them. It uses a separate thread to keep looping through a list to check for any new messages it has to deal with. </p>
<p>T... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T08:14:28.707",
"Id": "29607",
"Score": "1",
"body": "Minor quib, program to the interface (e.g. `List<Message> messages = new ArrayList<Message>();` also have you checked out using the `Collections` API? `Collections.synchronizedLis... | [
{
"body": "<p>Your ArrayList is correctly guarded from access by multiple threads but you've got another problem. The busy wait in your run method is going to hog the CPU and might even starve the other threads that would be trying to put a message in the queue. You'll need some way of signaling that the queue ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T04:51:28.873",
"Id": "18578",
"Score": "7",
"Tags": [
"java",
"synchronization"
],
"Title": "Handling messages from a server"
} | 18578 |
<p><strong>I would really love to hear your critiques on:</strong></p>
<ul>
<li>Code quality</li>
<li>Code clarity</li>
<li>More efficient alternative code</li>
</ul>
<p>Code:</p>
<pre><code>function array_mask(array $source, array $filter){
foreach ($source as $key => $value){
if (!isset($filter[$key... | [] | [
{
"body": "<p>Looks good to me, but you can make a small optimization:</p>\n\n<p>change this</p>\n\n<pre><code> if (array_search($key, $filter) !== false){\n continue;\n }\n unset($source[$key]);\n</code></pre>\n\n<p>to </p>\n\n<pre><code> if (array_search($key, $filter) =... | {
"AcceptedAnswerId": "18603",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T06:21:14.170",
"Id": "18582",
"Score": "2",
"Tags": [
"php"
],
"Title": "array_mask, Seeking alternative code"
} | 18582 |
<p>Both unit tests pass and they both test the same thing. The production code uses the right error codes.</p>
<p>System Under Test (SUT)</p>
<pre><code>public interface IRepository {
string GetParameter(int id);
}
public class Repository {
public string GetParameter(int id) {
return "foo";
}
}
... | [] | [
{
"body": "<p>They test the same \"action\". The semantic difference is:</p>\n\n<p>The first test verifies the values returned by the method being tested. </p>\n\n<p>The second verifies that it called a particular method.</p>\n\n<p>//disclaimer// I'm certainly no UnitTesting expert; I'm still learning, but I t... | {
"AcceptedAnswerId": "18610",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T09:43:22.623",
"Id": "18591",
"Score": "14",
"Tags": [
"c#",
"unit-testing",
"error-handling",
"comparative-review",
"moq"
],
"Title": "Unit tests for testing error cod... | 18591 |
<p>Inspired by <a href="https://codereview.stackexchange.com/q/18578/8953">this question</a>, I have a Java Enterprise application running in Glassfish 2.1 and a Java SE client that communicates with the server application.</p>
<p>For this I have a bean that maintains a collection of jobs that is set by the server and... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-05-19T00:26:58.157",
"Id": "165254",
"Score": "0",
"body": "I don't know much about EJB, but the article looks horrible to me. I know quite a lot about concurrency in Java SE, and after reading the article I still don't know anything abou... | [
{
"body": "<ol>\n<li>Your <code>@Stateless</code> service contains a shared state. It looks weird for me.</li>\n<li><p>You never modify a state of <code>jobs</code>, you always create a new object</p>\n\n<pre><code>this.jobs = Collections.synchronizedSet(new HashSet<String>());\n</code></pre>\n\n<p>Could ... | {
"AcceptedAnswerId": "18601",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T09:52:26.767",
"Id": "18592",
"Score": "1",
"Tags": [
"java",
"thread-safety"
],
"Title": "Querying a list of jobs on a server using EJBs"
} | 18592 |
<p>I've been struggling to get to grips with <a href="http://joda-time.sourceforge.net/api-release/index.html" rel="nofollow">Joda-Time</a>, but feel that I've finnaly managed to get a grip on some of the functionality that I need.</p>
<p>I have written a function that will convert a <code>DateTime</code> from one tim... | [] | [
{
"body": "<ol>\n<li><p>First of all, currently it does not compile. You should fix that, non-working codes are off-topic here.</p></li>\n<li><p>According to the <a href=\"http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#367\">Code Conventions for the Java Programming Lang... | {
"AcceptedAnswerId": "18812",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T11:23:57.760",
"Id": "18599",
"Score": "3",
"Tags": [
"java",
"datetime",
"jodatime"
],
"Title": "Converting timedate timezones with Joda-Time"
} | 18599 |
<p>I inherited a lot of C code with many ellipsis (variadic) functions.</p>
<p>I have a lots of API with the following signature:</p>
<pre><code>void getXY(int foo, ...) // many parameters
</code></pre>
<p>and this is used in this way as usual:</p>
<pre><code>getXY(1, "sizex", 12, "sizey", 24, 0);
</code></pre>
<p... | [] | [
{
"body": "<p>If the arguments are that simple, what's wrong with a locally defined array?</p>\n\n<pre><code>Test t;\nconst Test args[] = { {\"sizex\", 12}, {\"sizey\", 24} };\nt.get(1, args, sizeof(args)/sizeof(*args));\n</code></pre>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T12:56:58.680",
"Id": "18604",
"Score": "1",
"Tags": [
"c++",
"variadic"
],
"Title": "C-style va_args replacement"
} | 18604 |
<p>I have a pretty common issue: I need to know the name of current user and also name of the current controller so I can highlight/disable some links.</p>
<p>Here's some solutions I found by myself:</p>
<ol>
<li><p>Get all what's needed inside <code>PartialView</code>.</p>
<p>I have a PartialView inside my page lay... | [] | [
{
"body": "<p>I think it is controller's responsibility to decide what should be visible to user. So it looks to me like a good idea to pass some boolean flags to ViewData dictionary like</p>\n\n<pre><code>VeiwData[\"IsSomeUserSpecificLinkVisible\"] = Context.GetUser<Agent>().Name == \"Foo\";\n</code></pr... | {
"AcceptedAnswerId": "18621",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T13:35:24.797",
"Id": "18606",
"Score": "5",
"Tags": [
"c#",
"mvc",
"http",
"asp.net-mvc-3"
],
"Title": "Is it ok to use HttpContext inside View?"
} | 18606 |
<p>I wrote some code in Flask for site menu:</p>
<pre><code>def menu(parent_id=0, menutree=None):
menutree = menutree or []
cur = g.db.execute('select id, parent, alias, title, ord from static where parent="'+ str(parent_id) +'" and ord>0 order by ord')
fetch = cur.fetchall()
if not fetch:
... | [] | [
{
"body": "<p>In this code, at first I didn't see the \"danger\" until I scrolled to the right by accident:</p>\n\n<blockquote>\n<pre><code>def menu(parent_id=0, menutree=None):\n menutree = menutree or []\n cur = g.db.execute('select id, parent, alias, title, ord from static where parent=\"'+ str(parent_... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T15:12:00.830",
"Id": "18614",
"Score": "4",
"Tags": [
"python",
"flask"
],
"Title": "Website menu with Flask"
} | 18614 |
<p>I wonder how could I simplify the code below? Please note that it's <strong>not</strong> allowed to use instance variables here for some reason.</p>
<pre><code> private bool ValidateQueryString(NameValueCollection queryString, out byte[] errorMessages)
{
var errorsList = new List<strin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T15:45:25.337",
"Id": "29632",
"Score": "0",
"body": "Is the method signature of `ValidateQueryString` fixed or can it be changed?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T15:59:35.293",
"Id... | [
{
"body": "<p>I notice that methods should be separated.</p>\n\n<pre><code>private bool TryGetQSErrors(NameValueCollection queryString, out List<string> errorsList)\n{\n int aId;\n if (!int.TryParse(queryString[\"a_id\"], out aId))\n {\n errorsList.Add(\"aId invalid\");\n }\n\n strin... | {
"AcceptedAnswerId": "18661",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T15:39:21.770",
"Id": "18616",
"Score": "-1",
"Tags": [
"c#"
],
"Title": "Simplify the code in C#"
} | 18616 |
<p>I have written a caching wrapper method for some of my services. The actual wrapper method is written as follows:</p>
<pre><code>public T GetFromCache<T>(string key, Func<T> defaultValuePredicate, object cacheLock, TimeSpan duration)
{
lock (cacheLock)
{
var result = _cache[key] is T ? (... | [] | [
{
"body": "<p>I see a minor issues with the code: you are locking every time, no matter if it's needed on not. I would implemented GetFromCache like this</p>\n\n<pre><code>public T GetFromCache<T>(string key, object cacheLock, Func<T> defaultValuePredicate, TimeSpan duration)\n{\n object result =... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T15:43:34.233",
"Id": "18617",
"Score": "1",
"Tags": [
"c#",
".net",
"asp.net",
"cache",
"wrapper"
],
"Title": "Wrapper for caching methods in ASP.NET"
} | 18617 |
<p>I'm writing a script that:</p>
<ol>
<li>fetch a list of urls from a db (about 10000 urls)</li>
<li>download all the pages and insert them into the db</li>
<li>parse the code</li>
<li>if(some condition) do other inserts into the db</li>
</ol>
<p>I have a Xeon quad-core with hyper-threading, so a total of 8 thread a... | [] | [
{
"body": "<p>Q: <em>should I create as many cursors as the number of threads?</em></p>\n\n<p>A: <del>Yes</del> Maybe. Don't share DB connection among threads, as docs say thread safety level = 1. Maybe better to have a <code>queue</code> of db connections. Once a thread popped a cursor from the queue, it's his... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-11-14T15:48:23.993",
"Id": "18618",
"Score": "5",
"Tags": [
"python",
"mysql",
"multithreading",
"curl"
],
"Title": "Better multithreading with network IO and database queries"
} | 18618 |
<p>I have a simple text file setup as a Resource through my application's Properties as a byte[]. In order to access a "Stream.ReadLine" function, I believe I need to make it into a StreamReader. Is there a way to get the following result using only 1 Stream, or else, any tricks to make it better?</p>
<pre><code>List&... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T17:43:38.060",
"Id": "29646",
"Score": "2",
"body": "Why would you hold your file as byte[] in the first place? That's the reason code looks clumsy - `StreamReader` is for reading text, `MemoryStream` is for raw, formatless data, wh... | [
{
"body": "<p>Not without having to reinvent a lot of other things and make it more complex, no. This solution looks to be the best to me. You even use <code>using</code> correctly, which is one of my frequent nitpicks. However, if you want to simplify that bit of code, you might be able to help it with an exte... | {
"AcceptedAnswerId": "18622",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T15:50:43.373",
"Id": "18619",
"Score": "5",
"Tags": [
"c#",
".net"
],
"Title": "Are 2 streams really needed?"
} | 18619 |
<p>I have a string, where I am only interested in getting the numbers encapsulated in single quotes. </p>
<p>For instance if I have the string "hsa456456 ['1', '2', ...]</p>
<p>I only want the 1 and the 2 and whatever numbers follow</p>
<p>To do this, I have the following code:</p>
<pre><code>import re
#pattern = ... | [] | [
{
"body": "<h3>New regex</h3>\n\n<p>If you change your regular expression to the following you won't need to even do <code>str.strip()</code></p>\n\n<pre><code>valuepattern = re.compile(\"'(\\d+)'\")\n</code></pre>\n\n<h3>List Comprehension</h3>\n\n<p>Alternatively if you don't want to do that, you could do the... | {
"AcceptedAnswerId": "18628",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T19:39:43.483",
"Id": "18626",
"Score": "1",
"Tags": [
"python",
"regex"
],
"Title": "Minimize Number of Lists"
} | 18626 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.