body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I want to make a C++ object hierarchy of "classifiers", which can be composed together via logical operators into a single classifier that implements the whole logical combination.</p>
<p>This is actually for a particle physics analysis library, but I'll present a much simpler example which just classifies integers... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-24T20:57:26.110",
"Id": "28495",
"Score": "2",
"body": "I think you will have better success using templates and duck typeing rather than a polymorphic interface. The C++ standard library uses duck typing to achieve the same affect you... | [
{
"body": "<p>I think you will have better success using templates and duck typeing rather than a polymorphic interface. The C++ standard library uses duck typing to achieve the same affect you are trying to achieve here.</p>\n\n<p>This is what I would do:</p>\n\n<pre><code>// A couple of these are already in t... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-24T12:26:40.680",
"Id": "17881",
"Score": "4",
"Tags": [
"c++",
"object-oriented",
"operator-overloading"
],
"Title": "Implementing C++ boolean function objects with logical operator... | 17881 |
<p>The function takes 2 arguments: array: int[], cap: int</p>
<p>Members would be ranged from 0 to cap.</p>
<p>e.g.</p>
<pre><code>array = [0,0,0,2,6,3,0,4,2,4,0]
cap = 6
</code></pre>
<p>The return value is a new array of same length based on these rules:</p>
<ol>
<li><p>The function can only change values of con... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-24T14:39:49.853",
"Id": "28468",
"Score": "1",
"body": "What is your question? Are you wanting this improved in F#, C# or both? What type of improvements are you looking for: performance, readability?"
},
{
"ContentLicense": ... | [
{
"body": "<p>Seems you might be overusing Linq since you are manipulating an array. Here is an example that to me is a bit more readable (although the readability could be improved further) and it is faster.</p>\n\n<pre><code>private static int[] EquivalentOutput(int cap, int[] permutation)\n{\n int[] copy... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-24T13:35:24.253",
"Id": "17882",
"Score": "2",
"Tags": [
"c#",
"f#"
],
"Title": "How to improve this array manipulation function?"
} | 17882 |
<p>I have a for loop which loops through a list and builds and object, I needed to check the previous object with the one i'm building...which way is better?</p>
<p>This way?:</p>
<pre><code> String lastDirection= "";
List<Stages> stages = new ArrayList();
for (Object object : results) {
Vect... | [] | [
{
"body": "<p>The former would definitely be more efficient.</p>\n\n<p>In the latter case, you \"forget\" a local variable that you have available (by letting it go out of scope), and then on the next iteration get it back by calling <code>stages.get()</code>. There's no way that the <code>get()</code> call wi... | {
"AcceptedAnswerId": "17886",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-24T15:45:36.170",
"Id": "17885",
"Score": "6",
"Tags": [
"java"
],
"Title": "Which is better for checking previous object in list?"
} | 17885 |
<p>I'm curious when a piece of code should be its own method or just left alone. This came up when I was creating a "work item" from the thread pool. When passing the argument to the "WaitCallback" object, I would argue that if the code that will run will ONLY run when this thread is being run, then it's OK to wrap the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T17:33:02.297",
"Id": "28541",
"Score": "1",
"body": "My experience has been that things that are only used once are almost always only used once *for now*."
}
] | [
{
"body": "<p>I believe that option one is the most correct option and I say that because limiting the number of threads that have availability to a specific piece of code built to run on a background thread will keep you from seeing locking and race conditions in production that you wouldn't see in development... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-24T18:45:55.447",
"Id": "17893",
"Score": "6",
"Tags": [
"c#",
"multithreading"
],
"Title": "Should a piece of code only ever called once be a separate method?"
} | 17893 |
<p>I have a chunk of code that averages around the points of a grid of values and Im trying to figure out if there is a better way to do the averaging. The array itself is 1 dimensional but i am using an x and y and stride to keep track of it in 2d space. Im mainly just trying to figure out if there is a more optimized... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-24T21:27:19.163",
"Id": "28500",
"Score": "1",
"body": "You'll get more useful answers if you include the language you are using in the tags. I can't really tell from the code itself."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>I'm not into C++, but here's a suggestion for what it is worth. Create a class that encapsulates the array, let's call it <code>Array</code>. Define an <code>operator[]</code> method that gives you the value of the element of the array at (x,y); the function returns 0.0 if the coordinates are in... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-24T20:56:38.523",
"Id": "17900",
"Score": "2",
"Tags": [
"c++",
"optimization"
],
"Title": "Better way to average around points"
} | 17900 |
<p>My goal is to compute the intersections of several vectors (sets of identifiers, gene-names to be specific). I start with a list of vectors and run the function below, which loops through 1:n where n is the number of sets and then uses <a href="http://stat.ethz.ch/R-manual/R-patched/library/utils/html/combn.html" re... | [] | [
{
"body": "<p>Your approach seems reasonable, but there are some simplifications you can make.</p>\n\n<p>First, your construction of <code>name</code> is needlessly complex. This works just as well:</p>\n\n<pre><code>name <- paste(names(l)[indices], collapse=\"_\")\n</code></pre>\n\n<p>Second, you can call ... | {
"AcceptedAnswerId": "17931",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-24T22:07:18.310",
"Id": "17905",
"Score": "3",
"Tags": [
"r"
],
"Title": "Compute intersections of all combinations of vectors in a list of vectors in R"
} | 17905 |
<blockquote>
<p>Given two strings str1 and str2, write a function that prints all
interleavings of the given two strings. You may assume that all
characters in both strings are different</p>
<p>Example:</p>
<pre><code>Input: str1 = "AB", str2 = "CD"
Output:
ABCD
ACBD
ACDB
CABD
CADB
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T14:05:48.103",
"Id": "28534",
"Score": "4",
"body": "There is a standard function to do this: `std::next_permutation()`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T14:48:48.990",
"Id": "28539"... | [
{
"body": "<p>Your algorithm is correct, as you explained. However, I didn't find the code easy to understand.</p>\n\n<p>Staying within the spirit of your solution, I've cleaned it up a bit:</p>\n\n<ul>\n<li>Renamed <code>s2</code> → <code>s1</code> (because <code>s2</code> coming first is confusing), <code>re... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T02:57:11.637",
"Id": "17909",
"Score": "2",
"Tags": [
"c++",
"strings",
"recursion",
"combinatorics"
],
"Title": "Print all interleavings of two given strings"
} | 17909 |
<p>Here is a code I want to simplify:</p>
<pre><code>public void Method1(Context context, EventLog log = null)
{
Class myClass = ConvertToMyClass();
ApiCall1 apiCall = new ApiCall1(context);
if (log != null)
{
eventLog.WriteEntry("Starting");
}
try
{
apiCall.Call1(myClass, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T11:42:12.573",
"Id": "28520",
"Score": "0",
"body": "Do ApiCall1/2/3 all implement the same base class or interface?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-27T16:03:24.690",
"Id": "28683",
... | [
{
"body": "<p>Alright, let's see if we can <s>simplify</s>abstract this for you. I'm not going to say simplify because often times abstracting something is far from simplifying it.</p>\n\n<p>I <strong>think</strong> you can turn the method into something like this:</p>\n\n<pre><code>public void Method<T>(... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T06:36:13.737",
"Id": "17911",
"Score": "3",
"Tags": [
"c#",
".net"
],
"Title": "How do I simplify the code in C#?"
} | 17911 |
<p>I have implemented a Non Reentrant Lock. I want to know if this has any mistakes, race conditions etc. I am aware of the fact that existing libraries have to be used (instead of writing our own), but this is just to see if I am understanding the java concurrency correctly. Any feedback is appreciated.</p>
<pre><cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T12:54:55.473",
"Id": "28525",
"Score": "0",
"body": "Your `wait()` action lock the `while(..)`, you have to give wait[Time](inMilliseconds)."
}
] | [
{
"body": "<p>Shouldn't isLocked be set to <code>true</code> somewhere in here? It seems like when this thread gets notified, it will just print \"lock acquired\" without actually acquiring the lock and setting the owner to itself.</p>\n\n<pre><code> wait();\n }\n // Perhaps here you s... | {
"AcceptedAnswerId": "17990",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T10:25:14.247",
"Id": "17913",
"Score": "3",
"Tags": [
"java",
"locking",
"synchronization"
],
"Title": "Java Non Reentrant Lock Implementation"
} | 17913 |
<p>I have a gridview with <code>CheckBox</code> inside it. When the user selects a row and clicks
on a button, a message is sent for the specific user.</p>
<p>How can this be optimized?</p>
<pre><code>protected void btnSendSMSForSpeceficUser_Click(object sender, EventArgs e)
{
using (NoavaranModel.Noavar... | [] | [
{
"body": "<p>To be perfectly honest it seems quite optimized to me. And to prove that point, about the only thing you could change is making it so you only make one round trip to the server for all of the ID's, but that would also force you to iterate that list twice, consider the following code:</p>\n\n<pre><... | {
"AcceptedAnswerId": "17916",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T11:01:25.707",
"Id": "17914",
"Score": "2",
"Tags": [
"c#",
"asp.net"
],
"Title": "Sending a message based on selected row"
} | 17914 |
<p>Please review this code, which should calculate the tax percentage a person will pay in a progressive tax system. The goal is to have a perfect program.</p>
<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{... | [] | [
{
"body": "<p>Define \"perfect program\". If it works every time and does not have any bugs then I say it is perfect.</p>\n\n<p>Having said that, if you are looking for ways that you may improve the code...</p>\n\n<ul>\n<li><p>Your code does not following <a href=\"http://msdn.microsoft.com/en-us/library/vstud... | {
"AcceptedAnswerId": "17919",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T13:02:10.517",
"Id": "17918",
"Score": "5",
"Tags": [
"c#",
".net",
"finance"
],
"Title": "Progressive tax program"
} | 17918 |
<p>Is this the best way to check if two floating point numbers are equal, or close to being equal?</p>
<pre><code>template <class T>
bool IsEqual(T rhs, T lhs)
{
T diff = std::abs(lhs - rhs);
T epsilon = std::numeric_limits<T>::epsilon( ) * std::max(std::abs(rhs), std::abs(lhs));
return diff ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T14:23:51.680",
"Id": "28590",
"Score": "1",
"body": "So I should consider: 100000000000000000 and 100000000000000020 to be the same number?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T14:24:16.483... | [
{
"body": "<p>Seems unlikely. <code>epsilon</code> from <code>std::numeric_limits</code> is the smallest increment representable by the type (around the value 1).</p>\n\n<p>You want to check for something \"close to\" equal, but you don't say what close to means for you. Assuming it to be a few multiples of ep... | {
"AcceptedAnswerId": "18516",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T16:37:18.890",
"Id": "17923",
"Score": "7",
"Tags": [
"c++",
"floating-point"
],
"Title": "Checking if two floating point numbers are equal"
} | 17923 |
<p>I wrote this function to read Las file and save a shapefile. The function creates a shapefile with 8 fields. What I wish insert a parse element in the function in order to select the fields I wish to save <code>LAS2SHP(inFile, outFile=None, parse=None)</code>. If <code>parse=None</code> all fields are saved. If <co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T18:33:03.240",
"Id": "28546",
"Score": "0",
"body": "If you'd post the code of the function, I could help you convert the if/elifs/else to a dictionary."
}
] | [
{
"body": "<p>A possible dictionary based solution:</p>\n\n<pre><code>import os.path\n\nimport shapefile\nfrom liblas import file as lasfile\n\n\n# map fields representing characters to field name and attribute\nFIELDS = {\n 'i': ('Intensity', 'intensity'),\n 'r': ('Return', 'return_number'),\n 'n': ('... | {
"AcceptedAnswerId": "17933",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T17:17:39.417",
"Id": "17924",
"Score": "2",
"Tags": [
"python",
"optimization"
],
"Title": "Python: improve in elegant way (code saving) a function in order to avoid several statem... | 17924 |
<p>What can I do to improve performance of this function? So far I've changed stuff as local as possible and made a <code>break</code> if all possible surrounding tiles have been found. Also I use a separate variable to track the length of a list instead of <code>len()</code>.</p>
<p>The usage of this is to find surro... | [] | [
{
"body": "<pre><code>def getsurroundings(tiles):\n # skip the last rect in the outer loop, as it can't possibly have any subsequent neighbors\n for index, t in enumerate(tiles[:-2]):\n # if you've already found the maximum neighbors for t, skip the whole process\n if len(t.surroundings) <... | {
"AcceptedAnswerId": "17946",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T17:58:58.923",
"Id": "17925",
"Score": "2",
"Tags": [
"python",
"performance"
],
"Title": "Finding surrounding tiles for all tiles"
} | 17925 |
<p>I've recently been learning (and struggling with) integrating AutoFac, NHibernate & ASP.NET Web API. I have found several tutorials with code that did not work as anticipated but managed to finally find a working solution.</p>
<p>Essentially what I'm doing is registering a singleton of my <code>SessionFactory</... | [] | [
{
"body": "<p>This is not going to answer your question directly but..</p>\n\n<blockquote>\n <p>By definition I suppose that Code Review allows me to suggest and\n share subjective ideas (to be determined)...</p>\n</blockquote>\n\n<p>By convention, stuff that needs to be done on the application start can be l... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T20:05:04.587",
"Id": "17930",
"Score": "8",
"Tags": [
"c#",
"dependency-injection",
"asp.net-mvc-4"
],
"Title": "AutoFac, NHibernate & ASP.NET Web API integration"
} | 17930 |
<p>I am new to Java and I am trying to learn about optimizing code to make it production ready. I have the following code below. I would like to know how I could optimize it. I thought by using a small snippet of could, it would be a good way to learn.</p>
<p>Some points:</p>
<ol>
<li>The function would be run many t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T21:28:49.727",
"Id": "28550",
"Score": "3",
"body": "I feel like I'm missing something? Why don't you use `String replace(CharSequence target, CharSequence replacement);`? `String`s implement `CharSequence`, so you could use that ... | [
{
"body": "<p>String.replace(..) will work as Corbin said.</p>\n\n<p>Be careful when you mix String objects with the '+' operator in Java, especially within a loop.</p>\n\n<pre><code>String s = a + b; \n</code></pre>\n\n<p>will be (generally) interpreted as</p>\n\n<pre><code>String s = new StringBuffer(a).appen... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T20:25:40.680",
"Id": "17932",
"Score": "6",
"Tags": [
"java",
"optimization",
"strings"
],
"Title": "Java string replace"
} | 17932 |
<p>I have to do a table like this one:</p>
<pre><code>+-------+-------+-------+-------+-------+-------+
| th 1 | th 2 | th 3 | th 4 |
+-------+-------+-------+-------+-------+-------+
| | | | td 1 | td 2 | td 3 |
| | | th 7 +-------+-------+-------+
| | ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T21:02:20.900",
"Id": "28552",
"Score": "3",
"body": "Looks fine to me."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T21:32:17.703",
"Id": "28553",
"Score": "2",
"body": "The structure lo... | [
{
"body": "<p>I can't fault your tags at all. The only problem is that due to your table being quite complex, assistive technology may not be able to figure out the structure of your table.</p>\n\n<p>I was going to recommend using <code>scope</code> but according to <a href=\"http://www.w3.org/TR/WCAG20-TECHS/H... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-25T20:51:19.173",
"Id": "17936",
"Score": "13",
"Tags": [
"html",
"html5"
],
"Title": "Best way to construct a semantic HTML table?"
} | 17936 |
<p>I'm still learning Python, so I tried to build a basic MVC app using wxPython and pubsub. While it seems to work fine, the code seems to be getting out of hand.</p>
<p>In model I decided against using traditional (e.g. Java) accessors and went with the more Pythonic approach of properties. I only wanted to set the ... | [] | [
{
"body": "<p>It mostly looks pretty good. I have just a couple tweaks to suggest.</p>\n\n<p>You have </p>\n\n<pre><code>import wx.lib.pubsub\n\n# this seems to be required -- bug?\npub = wx.lib.pubsub.Publisher()\n</code></pre>\n\n<p>The example from the wxpython wiki does</p>\n\n<pre><code>from wx.lib.pubsub ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T00:32:10.963",
"Id": "17939",
"Score": "4",
"Tags": [
"python",
"mvc",
"wxpython"
],
"Title": "Pubsub-driven MVC application with wxPython"
} | 17939 |
<p>I more or less asked the same questions on stackoverflow.com, but maybe this is more for this forum. I have a hard time getting to grips with how to implement a top navigation (common for the whole site) and a page specific navigation (common for the current controller). I use <a href="http://www.williamsconcepts.co... | [] | [
{
"body": "<p>I'm not familiar with CI, but from what I can tell the concept seems alright. At least, what I am able to glean from your code seems to be. There are some improvements you could make however.</p>\n\n<p>The only reason to abstract the setting of the <code>$_nav</code> property with the <code>_load_... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T00:53:00.720",
"Id": "17941",
"Score": "2",
"Tags": [
"php",
"programming-challenge",
"mvc",
"codeigniter"
],
"Title": "CodeIgniter nav/menu insecurities"
} | 17941 |
<p>I am trying to learn the absolute best way to program/design classes in PHP. I am hoping that you would be able to review and critique this simple class.</p>
<p>Note: I know that there aren't any comments. Please don't critique me on that.</p>
<pre><code><?php
class VisitorCounter
{
protected $numVisits;
... | [] | [
{
"body": "<ol>\n<li>The construcotr may not contain any business logic/work process</li>\n<li>Your logic is not enough clear to me (hard coded WHERE clause first [id=2] then in getNumVisits() is just a simple select all query, etc.)</li>\n<li>No they should not be used in classes, force to inject them into the... | {
"AcceptedAnswerId": "17977",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T04:31:52.100",
"Id": "17944",
"Score": "8",
"Tags": [
"php"
],
"Title": "Simple VisitorCounter class"
} | 17944 |
<pre><code>String Name = "yyyy MM DD abjwg kelk.exe"
public static bool IsNameRight(string Name)
{
string[] temp = Name.Split(' ');
string[] de= Name.Split('.');
if (de[1] == "pdf" && temp .Length == 5)
{
if (temp [0].Length == 4
&& temp [1].Length == 2
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T19:23:12.730",
"Id": "28637",
"Score": "1",
"body": "What will this code do if given `foo.pdf.exe`?"
}
] | [
{
"body": "<p>The method name would be better called <code>IsNameValid</code> and the parameter <code>name</code> should be camel cased.</p>\n\n<pre><code>public static bool IsNameValid(string name)\n{\n // firstly always validate parameters, either throw an exception or return false.\n if (name == null) ... | {
"AcceptedAnswerId": "17952",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T07:59:08.617",
"Id": "17949",
"Score": "6",
"Tags": [
"c#",
".net"
],
"Title": "Validate that a given string (name) meets certain requirements"
} | 17949 |
<p>I'm making an avatar creator with jQuery where users can select and change hair, eye and skin colour. The page is a form with different values and when the user clicks on the form options the values are translated to CSS. This allows the avatar options to change. <a href="https://github.com/fgiasson/jquery-enhanced-... | [] | [
{
"body": "<p>You are perfectly right to be looking at functions as you way out of repetition. In this case the code:</p>\n\n<pre><code>$(\"span#hair\").removeAttr('class');\n$(\"span#hair\").addClass('hair' + gender + '1');\n$.cookie(product + \"hairstyle\", 'hair' + gender + '1');\n</code></pre>\n\n<p>appears... | {
"AcceptedAnswerId": "18083",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T15:00:17.353",
"Id": "17962",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"form"
],
"Title": "Avatar creator form"
} | 17962 |
<p>I'm looking for a way to simplify this code, because I could develop more overloads for <code>TryThis</code> I made the string and int both of class <code>Nullable</code> so that in each overloaded function, the catch block could return the same value. </p>
<p>The problem is I need, if possible, no overloads of <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T17:12:49.733",
"Id": "28603",
"Score": "6",
"body": "fyi, theres no such thing as a `Nullable<string>`. `string` is a reference type."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T17:13:30.120",
... | [
{
"body": "<p>You can use the generic delegate <code>Func<></code>:</p>\n\n<pre><code>static private T TryThis<T>(Func<T> MyAction) {\n try {\n return MyAction();\n } catch (Exception ex) {\n Console.WriteLine(ex.ToString());\n return default(T);\n }\n}\n</code></... | {
"AcceptedAnswerId": "17972",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T17:10:33.307",
"Id": "17968",
"Score": "4",
"Tags": [
"c#",
"delegates"
],
"Title": "How to simplify these delegate functions?"
} | 17968 |
<p>I'm modeling a reflection-based controller. I would like to know if you agree with my implementation and about what could be enhanced.</p>
<p>I'm starting with reflection and I would like to know if I'm using good practices.</p>
<pre><code>public class StartController extends HttpServlet {
@Override
publi... | [] | [
{
"body": "<p>Only few general comments from me:</p>\n\n<ol>\n<li><p>Start your method names with lowercase.</p></li>\n<li><p>Remove excess <code>try</code> keywords.</p></li>\n<li><p>Catch only specific type of <code>Exception</code>s!</p></li>\n</ol>\n",
"comments": [
{
"ContentLicense": "CC... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T17:30:01.693",
"Id": "17971",
"Score": "7",
"Tags": [
"java",
"mvc",
"reflection",
"controller"
],
"Title": "Action based controller using reflections"
} | 17971 |
<p>This is just a fun little exercise I had to do for a homework once (in Java rather than Clojure though). Basically, the goal is to find the number of different coin stacks you can build with the coins 1,2,5 and 10 to form a number N (I believe a closed form solution for this exists, but this isn't what this is about... | [] | [
{
"body": "<p>I would write <code>(def maximum (partial reduce max))</code> as:</p>\n\n<pre><code>(defn max-coll [coll] (apply max coll)) \n</code></pre>\n\n<p>although writing a special function for <code>(apply max coll)</code> seems a bit overdone in my taste.</p>\n\n<p>Another minor rewrite:</p>\n\n<pre><co... | {
"AcceptedAnswerId": "18003",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T17:50:42.387",
"Id": "17973",
"Score": "6",
"Tags": [
"algorithm",
"clojure"
],
"Title": "Counting ways to form an amount using coins"
} | 17973 |
<pre><code>var ContentEditingHelper;
$(ContentEditingHelper = function () {
var costCenterSelector = '#CostCenter';
var projectSubcodeSelector = '#ProjectSubcode';
var incidentNumberSelector = '#IncidentNumber';
//This bit of code affects the 'Add New Order' dialog. It works on the 'Incident Number', '... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T18:41:32.933",
"Id": "28622",
"Score": "0",
"body": "I *really* don't understand the `var ContentEditingHelper; $(ContentEditingHelper = function () {` purpose. `var ContentEditingHelper = function () { ... }; $(ContentEditingHelper... | [
{
"body": "<pre><code>var $inputs = $('#CostCenter, #ProjectSubcode, #IncidentNumber');\n\n$inputs.on('keyup', function() {\n $inputs.not(this).prop('disabled', this.value !== '');\n});\n</code></pre>\n\n<hr>\n\n<p>If your elements are not available at document ready, use this:</p>\n\n<pre><code>var selector... | {
"AcceptedAnswerId": "17975",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T18:23:09.593",
"Id": "17974",
"Score": "-1",
"Tags": [
"javascript",
"jquery"
],
"Title": "I have three input fields. When one has any information in it, the others should be disab... | 17974 |
<p>I have created an SslStream Abstract Class for my Client and i want you to review and enhance it for me if needed</p>
<p>SecureStream.cs</p>
<pre><code>using System;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Ta... | [] | [
{
"body": "<pre><code>new byte[0x1f80]\n</code></pre>\n\n<p>I think using decimal would be more readable here. And I don't understand why is your buffer 8096 bytes, usual sizes are powers of two, like 8192.</p>\n\n<pre><code>IpAddress = \"192.168.1.65\"\n</code></pre>\n\n<p>This looks like a perfect example of ... | {
"AcceptedAnswerId": "18000",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T20:01:30.180",
"Id": "17978",
"Score": "10",
"Tags": [
"c#"
],
"Title": "SslStream Class Review"
} | 17978 |
<p>I am working on a Java project for college that involves us setting up a TCP Server and Client. I have that part working and now to add more of a feel to my project I want to add a GUI.</p>
<p>We have not begun learning about GUI's in Java yet. However I want to try as I think it would be a useful exercise. I have ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-21T18:50:19.940",
"Id": "73063",
"Score": "0",
"body": "This question appears to be off-topic because it is primarily a design review."
}
] | [
{
"body": "<p>What you want is called the <strong>BoxLayout</strong>, which feeds UI elements in columns or rows. And then you can nest them one inside another, e.g. have one horizontal box layout panel as an element in another that is vertical (kind of like nested HTML tables). <a href=\"http://zetcode.com/tut... | {
"AcceptedAnswerId": "17981",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T21:42:46.660",
"Id": "17980",
"Score": "1",
"Tags": [
"java",
"swing",
"layout"
],
"Title": "Java Swing Panel layout"
} | 17980 |
<p>This isn't urgent, it is more along the lines of trivia or a challenge. The solution works fine as it is, but I suspect it could be better.</p>
<p>What follows is a method I came up with a while back in a rather ugly situation where I need to make a "best effort" to try casting an object of an unrestricted unknown... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-27T20:01:04.657",
"Id": "28695",
"Score": "3",
"body": "If you think some of the things in your code need explaining, why didn't you include those comments in your original code? If you expect that we would be confused by your code, wh... | [
{
"body": "<p>For casting, I have a much simpler method in mind:</p>\n\n<pre><code>public static bool TryCast<T>(this object obj, out T result)\n{\n if (obj is T)\n {\n result = (T)obj;\n return true;\n }\n\n result = default(T);\n return false;\n}\n</code></pre>\n\n<p>You don... | {
"AcceptedAnswerId": "18036",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T23:09:53.730",
"Id": "17982",
"Score": "29",
"Tags": [
"c#",
"casting"
],
"Title": "TryCast<T> method"
} | 17982 |
<p>It might be a bit redundant, and I'm not experienced enough to wrap it all into one function. But,
I'm aiming for unicode email adresses and a quick loose but secure validation. How can I improve this?</p>
<p>note: I'm using PDO, so I'm mainly focusing on preventing HTML injection. Is this an issue ether way if I'm... | [] | [
{
"body": "<p>How about this? </p>\n\n<pre><code>$email = \"<strong>Bàt mâ'n</strong>@çupærman.dc\";\n\nfunction validateEmail($email){\n $encoded_email = htmlspecialchars($email, ENT_COMPAT, 'UTF-8');\n $is_valid = !preg_match('/[^ ]+@[^ ]+\\.[^ ]{2,7}/', $email);\n\n if( $is_valid || $enc... | {
"AcceptedAnswerId": "18030",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-27T10:36:39.277",
"Id": "17986",
"Score": "2",
"Tags": [
"php"
],
"Title": "Is this PHP email validation comprehensive and complete?"
} | 17986 |
<p>I wrote this code for reversing a doubly linked list containing words in each node, which <strong>works perfectly fine</strong>. My teacher says the algorithm is difficult to understand and the code as a whole could be made more efficient(reducing overhead and memory consumption).</p>
<ol>
<li>What changes can i ma... | [] | [
{
"body": "<p>For the part where you don't need to ask the user for the number of words perhaps ask the user to terminate it with a full stop and take the input until a '.' is encountered.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"Cr... | {
"AcceptedAnswerId": "18006",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-27T12:57:20.690",
"Id": "17987",
"Score": "3",
"Tags": [
"c",
"linked-list"
],
"Title": "Simpler and faster code for reversing list?"
} | 17987 |
<p>I am hoping someone can help me tidy up my code (for a practical for university). The practical is to use the random number generator to produce 100 integers (all between 1 and 10) and store them in an array. We then need to scan the array and print out how often each number appears. Following this, we needed to cre... | [] | [
{
"body": "<p>There is much to say about this piece of code. I'll just focus on some parts of it.</p>\n\n<p><strong>One long method</strong></p>\n\n<p>There is one long main method. It makes it hard to get an overview of what is happening. Consider breaking the main method into several methods that each does it... | {
"AcceptedAnswerId": "18001",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-27T14:31:37.160",
"Id": "17992",
"Score": "8",
"Tags": [
"java",
"random"
],
"Title": "Tidy up number counting code"
} | 17992 |
<p>I am using the Python module <code>urllib3</code>. It occurs to me that there is a better way to design a good class when I rebuild my last site crawler.</p>
<pre><code>class Global:
host = 'http://xxx.org/'
proxy=True
proxyHost='http://127.0.0.1:8087/'
opts=AttrDict(
method='GET',
h... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-27T05:28:23.103",
"Id": "28686",
"Score": "0",
"body": "I think that those two are really parts of the same class. And should be combined."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-27T05:32:31.560",
... | [
{
"body": "<h3>Class design</h3>\n\n<p>A good class in general is one that corresponds to an <em>Abstract Data Type</em>,\nwhich is a collection of data and operations that work on that data.\nA good ADT should have a single, clear responsibility.</p>\n\n<p>The <code>Global</code> class is not a good ADT:</p>\n... | {
"AcceptedAnswerId": "74256",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-27T04:57:12.143",
"Id": "17993",
"Score": "2",
"Tags": [
"python",
"object-oriented",
"http"
],
"Title": "Two Python classes for a web crawler"
} | 17993 |
<p>How could I improve this code to make it shorter and more functional?</p>
<pre><code>#!usr/bin/python
import time
integer = 0
print("The current integer is set at " + str(integer) + ".")
print("\n")
time.sleep(2)
prompt = raw_input("Would you like to change the integer? (Y/N) ")
print("\n")
if prompt == 'y':
in... | [] | [
{
"body": "<p>How about something like this?</p>\n\n<pre><code>import time\n\ndef add_num(x):\n added_int = int(raw_input(\"What number would you like to add to your integer (%s) by?\" % x))\n outcome = x + added_int\n print(\"\\nThe sum of %s + %s is %s\" % (x, added_int, outcome))\n return outcome... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-27T18:12:31.087",
"Id": "17996",
"Score": "4",
"Tags": [
"python",
"calculator"
],
"Title": "Performing calculations with updated integer"
} | 17996 |
<p>I would like to get some general comments on style and use of STL in particular. This is some code I wrote to do machine learning classification (logistic regression). Any suggestions would be very appreciated!</p>
<p>A record containing an individual training example:</p>
<pre><code>/*
* A class representing a s... | [] | [
{
"body": "<p>Have you considered passing output arguments using pointers instead of by reference?</p>\n\n<p>That way it's clearer in your method call what the input and output arguments are, e.g instead of</p>\n\n<pre><code>trainer.Train(training_records, classifier);\n</code></pre>\n\n<p>you would have</p>\n\... | {
"AcceptedAnswerId": "18064",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-27T21:05:03.863",
"Id": "18002",
"Score": "4",
"Tags": [
"c++",
"algorithm",
"object-oriented",
"stl",
"machine-learning"
],
"Title": "C++ and STL - Machine Learning Probl... | 18002 |
<p>In this program, I have been asked to read an existing textfile (1324passlist) containing a list of passwords, then create a dictionary file with both the password and MD5 hash of the password on the same line. It should also have the user input a password hash, search the created dictionary file and print the corre... | [] | [
{
"body": "<p>Some comments that don't relate to efficiency:</p>\n<p>Exceptions and exception handling. In a couple of places you are SQUASHING exceptions; e.g.</p>\n<pre><code> catch(FileNotFoundException e)\n {\n }\n</code></pre>\n<p>So, if we can't open the password file, we effectively <em>ignore<... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-28T00:20:56.100",
"Id": "18004",
"Score": "7",
"Tags": [
"java",
"optimization",
"cryptography",
"file",
"hash-map"
],
"Title": "Creating and searching a dictionary of passwo... | 18004 |
<p>Can someone improve this code? I need to eliminate the <code>for</code> loop.</p>
<pre><code>public bool CheckMobileSim(List<Mobile_Range> numberRange, string MobileNumber)
{
bool SimType = new bool();
string NineDigits = MobileNumber.Substring(0, 9).ToString();
long Number = Convert.ToInt64(NineD... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-28T09:06:52.440",
"Id": "28710",
"Score": "6",
"body": "Why do you need to eliminate the loop?"
}
] | [
{
"body": "<pre><code>public bool CheckMobileSim(List<Mobile_Range> numberRange, string MobileNumber)\n{\n var digits = new List<long>();\n for (int i = 5; i < 10; i++)\n digits.Add(Convert.ToInt64(MobileNumber.Substring(0, i).ToString()));\n\n return numberRange != null &&... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-28T07:57:36.623",
"Id": "18008",
"Score": "2",
"Tags": [
"c#",
"asp.net",
"validation"
],
"Title": "Checking mobile SIMs"
} | 18008 |
<p>I am developing a BlackJack game using Java, and it came to a point that I am using <code>instanceof</code> operator to determine if it is a type of some subclass.</p>
<p>Here's an example:</p>
<pre><code>public void checkForBlackJack(Player player) {
Hand fHand = player.getHands().get(0);
if (fHan... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T10:46:48.823",
"Id": "28808",
"Score": "0",
"body": "In the most of the cases you can get rid of `instanceof` by implementing the [visitor pattern](http://en.wikipedia.org/wiki/Visitor_pattern). But this would be a bit over-engineer... | [
{
"body": "<p>why don't you declare a function for both types of <code>Player</code>?</p>\n\n<pre><code>public void checkForBlackJack(BlackJackPlayer blackjackplayer) {\n // ....\n }\n\npublic void checkForBlackJack(BlackJackDealer blackjackdealer) {\n // ....\n }\n</code></pre>\n",
"comments": [
{
... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-28T08:00:21.420",
"Id": "18009",
"Score": "2",
"Tags": [
"java",
"design-patterns",
"playing-cards"
],
"Title": "Using Java's instanceof operator"
} | 18009 |
<p>I have a <code>Value</code> class that may represent many different types:</p>
<pre><code>private BigInteger fNum;
private BigDecimal fReal;
private ArrayList<StaticValue> fArrayValues;
private int fArrayOffset;
private HashMapArray<String, StaticValue> fRecordValues;
private boolean fIsCharLiteral;
pri... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-28T23:13:55.490",
"Id": "28724",
"Score": "4",
"body": "Could you show a test too?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T09:44:18.160",
"Id": "28733",
"Score": "0",
"body": "It is a... | [
{
"body": "<p>In a first glance, having <code>StaticValueTypeXXX</code> for each type and puting them in a <em>Obervable/Observer</em> pattern puts the <code>ifTypeIs(..)</code> in the <em>Observers</em>, not in a huge switch in <em>Observable</em>.</p>\n\n<p>So you can reduce size of <em>Observers</em> [each <... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-28T15:44:02.780",
"Id": "18016",
"Score": "7",
"Tags": [
"java",
"performance"
],
"Title": "Value class representing different types"
} | 18016 |
<p>I've successfully solved the <a href="http://code.google.com/codejam/contest/90101/dashboard#s=p0" rel="nofollow">Alien Languages problem for Google Code Jam</a> in Haskell:</p>
<p>The algorithm is trivial - turn the patterns into regular expressions and see how many of the known words match these expressions.</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T11:53:23.983",
"Id": "29226",
"Score": "0",
"body": "As for \"most of the time I was battling with getting my types correct\" - it's common for beginners. My solution to it was just to keep writing programs until I learned the type ... | [
{
"body": "<p>A good rule of thumb is that you should only ever use <code>foldr</code> when you're really sure that your fold is not an instance of something simpler. In your case, the fold is doing pretty much exactly two things while traversing the pattern list:</p>\n\n<ol>\n<li>Keeping track of the \"case in... | {
"AcceptedAnswerId": "18054",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-28T16:02:11.197",
"Id": "18017",
"Score": "3",
"Tags": [
"haskell",
"programming-challenge"
],
"Title": "Google Code Jam - Alien Language"
} | 18017 |
<p>Can anyone review my <code>addMatrix()</code> method to see if I am following the instructions correctly?</p>
<p>These are the instructions:</p>
<blockquote>
<p>This is a <code>public</code> method (I'm calling it <code>addMatrix()</code>) that has <em>only one parameter</em> for a <code>DoubleMatrix</code> to add t... | [] | [
{
"body": "<ol>\n<li><p>I think you should operate your matrices as objects, not as two-dimensional arrays, so you could change your method</p>\n\n<pre><code>public double[][] addMatrix(double[][] doubMatrix)\n</code></pre>\n\n<p>to</p>\n\n<pre><code>public DoubleMatrix add(DoubleMatrix secondMatrix)\n</code></... | {
"AcceptedAnswerId": "18045",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T03:26:56.860",
"Id": "18026",
"Score": "3",
"Tags": [
"java",
"matrix",
"homework"
],
"Title": "addMatrix() method"
} | 18026 |
<p>Im using Struts2 running in google app engine.</p>
<p>User can use their google and facebook account to login to the site. When a user login, i have:</p>
<pre><code>session.put("email", email);
</code></pre>
<p>When a user log-out, I have</p>
<pre><code>session.remove("email");
</code></pre>
<p>In Struts2 Actio... | [] | [
{
"body": "<p>Code looks good, But why not move this Part:</p>\n\n<pre><code>String email = (String) session.get(\"email\");\nif ( email == null)\n return LOGIN; \n</code></pre>\n\n<p>into an Interceptor? Or do you have only one relevant Action?</p>\n",
"comments": [],
"meta_data": {
"CommentCo... | {
"AcceptedAnswerId": "18114",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T06:42:33.070",
"Id": "18029",
"Score": "2",
"Tags": [
"java",
"google-app-engine",
"struts2"
],
"Title": "Session in Struts2 and Google App Engine"
} | 18029 |
<p>Can you help me optimize the speed and security of my homepage?</p>
<p><em>(Link now dead - 2014/04/10 - <code>http://www.pixel-klicker.de</code>)</em></p>
<pre><code>var aktiv=0;
var red ;
var enable = [];
var count = 1;
var number = 0;
var Jetzt = 0;
var Start = 0;
var codes = [];
var xmlHttp;
function ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T19:38:12.797",
"Id": "28768",
"Score": "0",
"body": "[JSLint](http://www.jslint.com/) is a good starting point for JavaScript. It will flag up quite a few issues. In particular, it's complaining about references before definitions; ... | [
{
"body": "<ul>\n<li>Don't mix German and English code. I'd highly suggest you to use only English in your code (and I'm German myself).</li>\n<li>Don't mix different variable naming styles and only use variable names starting with a capital letter for constructor function which must be used with the <code>new<... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T11:02:28.013",
"Id": "18037",
"Score": "3",
"Tags": [
"javascript",
"optimization",
"beginner",
"security",
"ajax"
],
"Title": "Efficient (Virtual) Home Security"
} | 18037 |
<p>I posted the following code <a href="https://codereview.stackexchange.com/questions/17992/request-for-help-to-tidy-up-code-involving-arrays-and-for-statements">on here a few days ago</a>:</p>
<pre><code>public class Practical4_Assessed
{
public static void main(String[] args)
{
Random numberGenerat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T13:39:20.537",
"Id": "28744",
"Score": "0",
"body": "Maybe try to do it in very small steps? And make sure that each step doesn't break anything. [The other question](http://codereview.stackexchange.com/questions/17992/request-for-h... | [
{
"body": "<p>After stressing about it for about two hours, I got the methods sorted, so I'll answer my own question. Please note - I'm just a beginner and I'm sure there are plenty of things that could be done even more efficiently!</p>\n\n<pre><code>import java.util.Random;\n// Imports Java random number gene... | {
"AcceptedAnswerId": "18050",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T11:04:17.490",
"Id": "18038",
"Score": "1",
"Tags": [
"java",
"array",
"classes"
],
"Title": "Request for help to tidy up code involving arrays and loops"
} | 18038 |
<p>explain:</p>
<p><strong>from start day till now I've got 7.7 mb size, how long it will be to make it 10 gb size</strong></p>
<pre><code>open System
let dd = (DateTime.Now - DateTime.Parse("12/09/2012")).Days
let oneday = 7.7 / Convert.ToDouble(dd)
let in10gb = Convert.ToInt32( Math.Round (10.0 * 1024.0 / oneday)... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T14:53:51.830",
"Id": "28754",
"Score": "0",
"body": "Be careful with things like `DateTime.Parse(\"12/09/2012\")`. They can give different results on different computes, due to culture settings."
}
] | [
{
"body": "<p>I would propose an alternative method of calculating your time, using seconds and DateTimes:</p>\n\n<pre><code>open System\n\nlet startDate = DateTime.Parse (\"2012-09-12\")\nlet now = DateTime.Now;\nlet currentRuntime = (now - startDate).TotalSeconds\nlet timePerGig = currentRuntime / 7.7;\nlet t... | {
"AcceptedAnswerId": "18055",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T11:47:18.870",
"Id": "18040",
"Score": "1",
"Tags": [
"f#"
],
"Title": "TimeSpan don't support years so how do I deal with it? Is there could be smarter solution?"
} | 18040 |
<pre><code>public bool CheckPlace(string State, string City)
{
TestDataContext data = new TestDataContext();
bool IsKochi = new bool();
if (!string.IsNullOrEmpty(State) && !string.IsNullOrEmpty(City))
{
var Place = (from a in data.Places where a.State == State || a.City == City select a.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T22:51:37.157",
"Id": "28784",
"Score": "1",
"body": "`new bool()` is a very weird way to write `false`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-08-04T23:33:38.980",
"Id": "181559",
"Score": ... | [
{
"body": "<pre><code>public bool CheckPlace(string State, string City)\n{\n if (string.IsNullOrEmpty(State) || string.IsNullOrEmpty(City))\n {\n return false;\n }\n\n using (var data = new TestDataContext())\n {\n var ret = data.Places.Where(a => (a.State == State || a.City == C... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T13:23:42.703",
"Id": "18044",
"Score": "1",
"Tags": [
"c#",
"asp.net",
"linq"
],
"Title": "Can someone improve this code?"
} | 18044 |
<p>The basic idea here is that I want to measure the number of seconds between two python datetime objects. However, I only want to count hours between 8:00 and 17:00, as well as skipping weekends (saturday and sunday). This works, but I wondered if anyone had clever ideas to make it cleaner.</p>
<pre><code>START_HOUR... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2020-01-15T01:04:19.407",
"Id": "461344",
"Score": "0",
"body": "What about other holidays? It sounds as if by excluding weekends you mean to exclude all free days. Note that in Arabic countries, Friday is not a work day, but sunday is."
},
... | [
{
"body": "<p>I think the initial calculation between the two dates looks cleaner using a generator expression + sum. The posterior correction is easier to understand if you do the intersection of hours by thinking in seconds of the day</p>\n\n<pre><code>from datetime import datetime\nfrom datetime import timed... | {
"AcceptedAnswerId": "18912",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T15:43:41.037",
"Id": "18053",
"Score": "22",
"Tags": [
"python",
"datetime"
],
"Title": "Seconds between datestimes excluding weekends and evenings"
} | 18053 |
<p><a href="http://code.google.com/p/guava-libraries/" rel="nofollow">Guava</a> has a <a href="http://code.google.com/p/guava-libraries/issues/detail?id=872" rel="nofollow">feature request</a> which is asking to provide the ability to forget memoized value on a given supplier.</p>
<p>On top on that I needed another fu... | [] | [
{
"body": "<ol>\n<li><p><a href=\"http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-135099.html#367\">Class names should be nouns</a>. I'd rename <code>DoubleCheck</code> to <code>DoubleCheckedResource</code> or something similar.</p></li>\n<li><p><code>ForgettableMemoizingSupplier</co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T18:29:01.940",
"Id": "18056",
"Score": "7",
"Tags": [
"java",
"multithreading",
"cache",
"guava",
"memoization"
],
"Title": "Ability to forget the memoized supplier value"... | 18056 |
<p>When I look at this style of code I feel like there has to be a better way to write this:</p>
<pre><code><div id="by_cx">
<!-- free text input for name -->
<label>Name:<input type="text" id="cxByNameInput" name="cxByNameInput"/></label>
<!-- cx state drop down -->
... | [] | [
{
"body": "<h2>Code separation</h2>\n\n<p>What you have there is everything mixed together - just by moving the php logic to the top of the file, makes it easier to read. With some minor reformatting it becomes easier to read/maintain:</p>\n\n<pre><code><?php\n$states = getStates();\n$statusList = getCxStatu... | {
"AcceptedAnswerId": "18060",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T19:52:14.833",
"Id": "18058",
"Score": "2",
"Tags": [
"php",
"html"
],
"Title": "Better way to incorporate HTML and PHP"
} | 18058 |
<pre><code>public static class ThreadStatic<T> where T : new()
{
[ThreadStatic]
private static T instance;
public static T Instance
{
get { return instance ?? (instance = new T()); }
}
}
</code></pre>
<p>Used like this:</p>
<pre><code>var probability = ThreadStatic<Random>.Ins... | [] | [
{
"body": "<ol>\n<li><p>I'm not sure to be honest, the contained resource would be specific per thread and created upon first read so volatile may be unnecessary as I believe that's for multiple threads reading and writing to the same field.</p></li>\n<li><p>It looks like you are trying to make a singleton vers... | {
"AcceptedAnswerId": "18061",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T20:05:17.390",
"Id": "18059",
"Score": "5",
"Tags": [
"c#",
"thread-safety"
],
"Title": "Is this a thread safe way to control access to a reusable resource? Is there a better way?"... | 18059 |
<p>So I created this custom application and ported it into a few websites. It uses the Twitch API and pulls in active streams and the viewer count. The problem I run into is when the list gets so big it seems to become too much to do though ajax. I think this because sometimes it will show a stream online when it has b... | [] | [
{
"body": "<p>Updating the list through ajax every second takes a lot of resources, both client and server side. If you insist on doing the update so often I recommend you take a look at, comet or websockets. Read <a href=\"https://stackoverflow.com/questions/19995/is-there-some-way-to-push-data-from-web-server... | {
"AcceptedAnswerId": "18289",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-29T23:58:43.507",
"Id": "18066",
"Score": "2",
"Tags": [
"javascript",
"php",
"jquery",
"ajax",
"api"
],
"Title": "Custom Streaming Application - Twitch"
} | 18066 |
<p>As part of an assignment in Cryptography I've been asked to write code that involves calculating modular exponentiation. The BigInteger modPow is not allowed in this case, we have to implement it ourselves. </p>
<p>I have the assignment working, but I think my modular exponentiation function is not the greatest in ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T04:46:46.800",
"Id": "28793",
"Score": "0",
"body": "Your loop is going to run (b / 2) times. That is what is slowing you down."
}
] | [
{
"body": "<p>Just a quick note, not an optimization idea:</p>\n\n<pre><code>if(compareVal.compareTo(BigInteger.ONE) ==0) { ... }\n</code></pre>\n\n<p>could be </p>\n\n<pre><code>if (compareVal.equals(BigInteger.ONE)) { ... }\n</code></pre>\n\n<p>which is a little bit easier to read. Furthermore, if you switch... | {
"AcceptedAnswerId": "18093",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T00:42:20.830",
"Id": "18067",
"Score": "2",
"Tags": [
"java",
"optimization",
"cryptography"
],
"Title": "Modular exponentiation optimisation in Java"
} | 18067 |
<p>How can I design this class and its implementation so that it looks like it was developed by a seasoned senior level PHP developer that follows all of the best practices? I'm trying to design this class so that it can be reused in other applications. I also have some other questions that are located inside of the co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-06T13:43:18.190",
"Id": "29146",
"Score": "0",
"body": "Why is everyone doing the password check using SQL instead of PHP? SQL will use a collation when comparing strings that is not always predictable (CI, AI). PHP will compare the st... | [
{
"body": "<h1>Red flag</h1>\n<pre><code> $query = "SELECT * FROM admin WHERE user = :user AND password = :pass";\n</code></pre>\n<p>Ok, so you've heard that you should hash passwords before storing them, because it turns out that <code>pass</code> is a SHA hash. But you don't seem to have heard o... | {
"AcceptedAnswerId": "18163",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T02:39:13.757",
"Id": "18068",
"Score": "14",
"Tags": [
"php",
"php5"
],
"Title": "How would a senior PHP developer design this Login class?"
} | 18068 |
<p>This function was hard to write as a Clojure newbie, and I don't like the result.
Can you help me find a better (more readable) way to do it?</p>
<pre><code>(defn split-seq
"Splits a seq into blocks defined by start-fn and stop-fn.
Returns a lazy seq of seqs"
[start-fn stop-fn lines]
(let [step (fn [c state... | [] | [
{
"body": "<p>So the idea in this new approach is to write two expressions:</p>\n\n<ul>\n<li>one that extracts the next expresstion:<br>\n<code>(take-while #(not= \"#ENTRY_END\" %) \n (rest (drop-while #(not= \"#ENTRY_START\" %) data)))</code></li>\n<li>one that extracts everything af... | {
"AcceptedAnswerId": "18072",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T07:15:58.680",
"Id": "18071",
"Score": "5",
"Tags": [
"clojure"
],
"Title": "String-splitting function"
} | 18071 |
<p>So my app needed a cookie store that persists over the app closing, device reboot etc. I decided to use the sharedPreferences for this. The class works pretty well, in both my tests and on the device. However there are couple of things I think can be improved. First is error handling. The problem is I cannot throw t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T12:41:19.187",
"Id": "28811",
"Score": "0",
"body": "It is persistent ... not persistant."
}
] | [
{
"body": "<blockquote>\n <p>First is error handling. The problem is I cannot throw the errors further up in the app as the cookiestore interface doesn't not allow it. </p>\n</blockquote>\n\n<p>You can define a custom <strong>unchecked</strong> exception and throw that. (Or throw an existing unchecked excepti... | {
"AcceptedAnswerId": "18078",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T10:36:42.423",
"Id": "18073",
"Score": "1",
"Tags": [
"java",
"android"
],
"Title": "Persistent Cookie Store"
} | 18073 |
<p>I am fresh at OOP and I am curious if the code below is object oriented and can be improved:</p>
<pre><code>class cTitleBreadcrumb {
public function __construct($sAction, $sItem){
$this->sAction = $sAction;
$this->sItem = $sItem;
}
public function displayAction(){
if($this->checkUrlAction($th... | [] | [
{
"body": "<h2>You are not always returning anything</h2>\n\n<pre><code>private function checkUrlAction($sAction) {\n if(true){ \n return true;\n }\n\n //but else?\n}\n</code></pre>\n\n<h2>Dependency injection</h2>\n\n<p>$objShowPDO = new mShowPDO(); is bad a mShowPDO instance should by ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T12:45:03.887",
"Id": "18077",
"Score": "3",
"Tags": [
"beginner",
"php",
"object-oriented"
],
"Title": "PHP breadcrumb class"
} | 18077 |
<p>I want to make sure <code>find_value_from_key()</code> is safe and efficient. My constraints are language C++, use of standard library ok, but cannot use Boost or any new C++11 features.</p>
<p>Can anyone offer any comments/criticisms/feedback on my implementation of the function here? Any flaws in my test cases ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-01T19:24:41.173",
"Id": "28932",
"Score": "1",
"body": "What is the ultimate goal with this code. Are you being provided with comma separated key value pairs? Are you going to be doing repeated searches of this string of data? Will you... | [
{
"body": "<h2>find_value_from_key</h2>\n<p>The core method <code>find_value_from_key</code> looks functional for the limited specification you have given. I am not a great fan of the specification though, I think the function should try to be a bit smarter about identifying values in the input strings. The two... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T12:52:19.357",
"Id": "18079",
"Score": "7",
"Tags": [
"c++",
"parsing"
],
"Title": "Token-finding function"
} | 18079 |
<p>I'm learning Go at this moment and it is my first program in Go, so I will be thankfull for any suggestion, remarks and observations.</p>
<pre><code>package main
import (
"fmt"
)
const ascii = "abcdefghijklmnopqrstuvwxyz"
var goodness_values = []float32 { .0817,.0149,.0278,.0425,.1270,.0223,.0202, .0609,.0697... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2018-06-06T21:37:21.280",
"Id": "377471",
"Score": "0",
"body": "This question is on-topic, it is \" [concrete code from a project, with sufficient context](https://codereview.meta.stackexchange.com/a/3652) for reviewers to understand how that... | [
{
"body": "<p>It looks like it was written in another language and then translated to Go. It looks complicated. Go is designed to be efficient. Maps are not as efficient as slices and arrays for simple indexing. <code>decode(secret, i)</code> executes 26 times instead of once. Etc.</p>\n\n<p>Here's an alternate... | {
"AcceptedAnswerId": "18102",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T12:57:38.877",
"Id": "18080",
"Score": "6",
"Tags": [
"beginner",
"go",
"caesar-cipher"
],
"Title": "My first Go program: Caesar Cipher"
} | 18080 |
<p>I'm writing out two numbers separated with a dash. The first number is padded with leading zeros until 6 digits, the second number, 4.</p>
<pre><code>string taskNumber = order.ID.ToString("D6") + "-" + task.ID.ToString("D4");
</code></pre>
<p>If I was going to rewrite this using string.Format I would simply say:</... | [] | [
{
"body": "<p>Sure. Simply include the padding specifier directly in the format string:</p>\n\n<pre><code>string taskNumber = string.Format(\"{0:D6}-{1:D4}\", order.ID, task.ID);\n</code></pre>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"C... | {
"AcceptedAnswerId": "18086",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T16:28:38.643",
"Id": "18084",
"Score": "8",
"Tags": [
"c#",
"strings",
"formatting"
],
"Title": "Formatting a number"
} | 18084 |
<p>I currently use this code pattern fairly frequently</p>
<pre><code>if(array_key_exists('possible_key', $array)) {
$my_variable = $array['possible_key'];
} else {
$my_variable = 'my default value';
}
</code></pre>
<p>Is there a better way to be writing this?</p>
| [] | [
{
"body": "<p>One quick change you can do is making use of ternary operator instead of writing if else block.</p>\n\n<pre><code>$my_variable = array_key_exists('possible_key', $array) \n ? $array['possible_key'] \n : 'my default value';\n</code></pre>\n",
"comments": [
{
... | {
"AcceptedAnswerId": "18087",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T16:56:03.823",
"Id": "18085",
"Score": "5",
"Tags": [
"php"
],
"Title": "PHP checking for array key or using default value"
} | 18085 |
<p>Users can define custom controls that are added to an entry form at run-time. The values of these controls are later stored in a MySQL database. Optionally, users can define 'recipes' to auto calculate some controls. </p>
<p>For an example, a user could enter Gross and Tare weight and use a FieldCalc for the Net We... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T19:00:00.253",
"Id": "28823",
"Score": "0",
"body": "any idea where the bottleneck might be?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T19:04:36.947",
"Id": "28827",
"Score": "0",
"bo... | [
{
"body": "<p>Hook up a profiler and measure what exactly is causing the slow down. Everything else is basically stabbing in the dark. That being said, there are a few things you could check:</p>\n\n<ol>\n<li><p>You have a few loops in there checking <code>_metricControls</code> and <code>_timeControls</code> f... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T17:57:20.597",
"Id": "18090",
"Score": "4",
"Tags": [
"c#"
],
"Title": "End User defined Controls and calculations on WinForm. Thoughts on speed?"
} | 18090 |
<p>Please review this for concurrency correctness:</p>
<pre><code>#include <iostream>
#include <queue>
#include "boost\thread.hpp"
#include "boost\timer.hpp"
std::queue<int> itemQ;
boost::mutex m;
boost::condition_variable qFull, qEmpty;
const int max_size_q = 5;
void producer()
{
int i = ... | [] | [
{
"body": "<p>Your usage of the condition variable will probably work but is a-typical.</p>\n\n<p>This is what you basically have:</p>\n\n<pre><code>while (1)\n{\n boost::mutex::scoped_lock lock(m); \n if (<Test OK>)\n {\n <Do Work>\n <Notify Consumer>\n } \n ... | {
"AcceptedAnswerId": "18107",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T19:50:59.377",
"Id": "18094",
"Score": "2",
"Tags": [
"c++",
"multithreading",
"boost",
"synchronization",
"producer-consumer"
],
"Title": "Boost Threads - Producer Con... | 18094 |
<p>Here is my problem. Do I need to give a new identifier to each delegate I write of the following delegate type? like so: or could i use one delegate that accounts for any Datatype I need to use so i don't have to keep repeating the code?</p>
<p>Something that may or may not be relevant: I'm calling these functions... | [] | [
{
"body": "<p>If done cleverly, you can get away with a single method to get the input of any type:</p>\n\n<pre><code>static T GetInput<T>(string message, Converter<string, T> transform)\n{\n Console.WriteLine(message);\n return transform(Console.ReadLine());\n}\n</code></pre>\n\n<p>All you ne... | {
"AcceptedAnswerId": "18097",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-30T21:41:10.023",
"Id": "18095",
"Score": "10",
"Tags": [
"c#",
"generics",
"delegates"
],
"Title": "using <T> in generic delegates?"
} | 18095 |
<p>I was looking for a C function that reads lines of arbitrary length from a file. I didn't find anything absolutely portable and safe from buffer overflows, so I tried writing my own.</p>
<ul>
<li>Does it look like I made any memory management mistakes?</li>
<li>Does it make sense to have this function return <code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-31T02:58:01.853",
"Id": "28840",
"Score": "1",
"body": "Might write a full response later if someone else hasn't already, but the first thing that jumps at me is that there are two possibilities for memory leaks in the function."
},
... | [
{
"body": "<p>You definately have memory leaks.</p>\n\n<pre><code>==92867== Memcheck, a memory error detector\n==92867== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.\n==92867== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info\n==92867== Command: ./a.out test1\n==92867== \n--9... | {
"AcceptedAnswerId": "18103",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-31T01:14:03.277",
"Id": "18100",
"Score": "5",
"Tags": [
"c",
"strings",
"reinventing-the-wheel",
"io"
],
"Title": "C getline function"
} | 18100 |
<p>I've written a small routing system in PHP but I'm not sure if it's done the right way and what changes can they be done to the code and improvements.</p>
<pre><code><?php
namespace Twelve\Router;
use Twelve\Utils\Utils;
class Router
{
public
$routeMaps = [],
$control... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-01T17:21:09.847",
"Id": "28926",
"Score": "0",
"body": "Am i right that you are mapping one route to one specific controller?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T13:54:02.750",
"Id": "289... | [
{
"body": "<p>Here are my observations</p>\n\n<p><strong>NOTE</strong> I did all this via stream-of-conscientiousness and I haven't tested any of these changes (or your original code) so take these as guidance and not exact changes :)</p>\n\n<p><strong>router.php</strong></p>\n\n<pre><code><?php\nclass Route... | {
"AcceptedAnswerId": "19561",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-31T09:46:15.023",
"Id": "18110",
"Score": "3",
"Tags": [
"php",
"php5",
"url-routing"
],
"Title": "Small routing system"
} | 18110 |
<p>I have written the following script which simply:</p>
<ol>
<li>Loops through JavaScript files (either defined in a particular package, or separately with the libraries array)</li>
<li>Reads the files into the script and combines them into one string</li>
<li>Minifies the string and saves the contents to a cached fi... | [] | [
{
"body": "<h2>Don't point at php</h2>\n<p>This script looks like the intention is to point at a php file, that returns the compressed content. Assuming that's the case...</p>\n<p>PHP doesn't belong in-between a user and a static, public file. Webservers are much better for serving static content. Rather than p... | {
"AcceptedAnswerId": "18122",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-31T15:21:38.877",
"Id": "18117",
"Score": "5",
"Tags": [
"javascript",
"php",
"api"
],
"Title": "Loading JavaScript libraries with PHP API"
} | 18117 |
<p>I'm trying to develop a better function and curious what others would suggest I do to it so that its not so robust and still accomplish what I need.</p>
<p>A couple of things I need to account for is when I have a last 5 messages as well as getting just the regular number of messages.</p>
<pre><code>/**
* Gets al... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T16:14:21.883",
"Id": "28996",
"Score": "0",
"body": "Any ideas for me?"
}
] | [
{
"body": "<p>You have a lot of <code>if ($box == 'inbox')</code> statements. Why not bunch them together into one <code>if</code> statement?</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-04T14:51:02.183",
"... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-31T16:31:21.250",
"Id": "18119",
"Score": "1",
"Tags": [
"php",
"codeigniter"
],
"Title": "Getting personal messages function"
} | 18119 |
<p>I'm a brand new JavaScript guy (currently playing with Meteor) and would love some critique of the following:</p>
<p>The goal: I've got two collections </p>
<ol>
<li>Buckets </li>
<li>Widgets. </li>
</ol>
<p>I'm displaying a <code>select</code> for each bucket, populated with an <code>option</code> for each wid... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-16T20:49:27.870",
"Id": "40668",
"Score": "0",
"body": "So `bucket_contains` is a property of Buckets and will be the name of a widget if a widget is assigned to a bucket?"
}
] | [
{
"body": "<p>I've been looking at your code for a few weeks now, the problem is both that there is not a lot to review and there's nothing wrong with it.</p>\n\n<p>Do consider using lowerCamelCasing which is the standard in JS, so <code>bucket_name</code> -> <code>bucketName</code>.</p>\n\n<p>The code seems el... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-31T18:23:26.670",
"Id": "18120",
"Score": "8",
"Tags": [
"javascript",
"html",
"node.js",
"meteor"
],
"Title": "Nested template variable access in Meteor"
} | 18120 |
<blockquote>
<p>Given a string, find its rank among all its permutations sorted
lexicographically. For example, rank of “abc” is 1, rank of “acb” is
2, and rank of “cba” is 6. Assuming there is no duplicated character.</p>
</blockquote>
<p>The following is my code:</p>
<pre><code>#include <iostream>
using... | [] | [
{
"body": "<p>I have a couple of issues with the main function.</p>\n\n<p>First, <code>system(\"pause\")</code> may work for windows but won't elsewhere. You should dump it.</p>\n\n<p>Second, Too many returns at the end.</p>\n\n<p>Third, The hardcoded input makes it kinda hard to test (and doesn't look good). J... | {
"AcceptedAnswerId": "18126",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-01T01:49:40.963",
"Id": "18125",
"Score": "2",
"Tags": [
"c++",
"interview-questions"
],
"Title": "Lexicographic rank of a string"
} | 18125 |
<p>I was surprised that I didn't find this approach to logging anywhere while reading up on the subject. So, naturally, I think I may be doing something wrong. I set up some simple tests, and this seems to work:</p>
<p>First, the source: <code>log.py</code></p>
<pre><code>import datetime
import logging
import os
imp... | [] | [
{
"body": "<p>You can find approach you are looking for in the <a href=\"http://docs.python.org/2/howto/logging-cookbook.html\" rel=\"nofollow\">logging cookbook</a> and <a href=\"http://docs.python.org/2/howto/logging.html\" rel=\"nofollow\">logging howto</a>: Default logging module provides nice configuration... | {
"AcceptedAnswerId": "18562",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-01T13:42:33.667",
"Id": "18132",
"Score": "4",
"Tags": [
"python",
"logging"
],
"Title": "How's my approach to logging?"
} | 18132 |
<p>I have some code that is used to hook into third party code. It goes pretty much like below (mind you CodeWeDontHave can't be posted because we dont have the source). I have an issue where sometimes my code will deadlock on the line commented below. Also, we get a object reference error now and then. </p>
<p>Is... | [] | [
{
"body": "<ul>\n<li>TextBox's ReadOnly flag is for <em>user input</em> only, see <a href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.readonly.aspx\" rel=\"nofollow\">MSDN</a>.</li>\n<li>Update only updates what is Invalidated. If you want to forcefully ensure a control is update... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-01T20:25:33.153",
"Id": "18141",
"Score": "8",
"Tags": [
"c#",
"winforms"
],
"Title": "Is this code to hook into a .NET window that we don't own safe? Can it be made safe?"
} | 18141 |
<p>I'm implementing a version of the mean shift image processing algorithm for color segmentation in Python/NumPy.</p>
<p>I've written a pure NumPy version of the actual mean shifting per pixel (which I imagine is where the majority of time is taking). It slices an array of RGB values to work on out of the parent imag... | [] | [
{
"body": "<p>The following code is a first shot and it is still not vectorized. The major points here are the extraction of the creation of cLow and cUp (don't create arrays in loops, always 'preallocate' memory), the calculation of the tolerance levels can be done in one operation (under the assumption that b... | {
"AcceptedAnswerId": "18911",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-02T08:14:44.973",
"Id": "18149",
"Score": "4",
"Tags": [
"python",
"optimization",
"image",
"numpy"
],
"Title": "Mean shift image processing algorithm for color segmentation"
... | 18149 |
<p>I was trying, just for fun, to solve <a href="http://code.google.com/codejam/contest/dashboard?c=2075486#s=p4" rel="nofollow">http://code.google.com/codejam/contest/dashboard?c=2075486#s=p4</a> </p>
<p>I can easily solve the small set, but I struggle to solve the big one (my implementation would use approx. 30GB or... | [] | [
{
"body": "<pre><code>def solve_maze(case_no):\n case = cases[case_no]\n</code></pre>\n\n<p>It'd make more sense to pass the case here, and operate on that rather then passing in the case number</p>\n\n<pre><code> case_no += 1\n edges = case['edges']\n #quick and dirty check. Can we reach the goal?\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-02T13:14:44.727",
"Id": "18154",
"Score": "2",
"Tags": [
"python",
"search"
],
"Title": "Shifting Paths problem (Code Jam)"
} | 18154 |
<p>Just wondering if anyone can see a way to optimize this piece of code. It is a key piece of my program and needs to run as quickly as possible. The part of the code I am unsure of is the <code>while</code> loop for finding the nearest key -- but any assistance with optimizing the code would be appreciated.</p>
<pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-02T16:35:48.773",
"Id": "28962",
"Score": "0",
"body": "unrelated: I'm curious to know what a method beginning with an underscore means in your codebase."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-02T1... | [
{
"body": "<p>Your loop is pretty well written. The only thing that sticks out to me is your use of a constant in the while loop and manually breaking. I also prefer to use a slightly different version of CompareTo, but it doesn't make much difference:</p>\n\n<pre><code>while ( (lower<=upper))\n{\n int c... | {
"AcceptedAnswerId": "18161",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-02T15:17:18.143",
"Id": "18155",
"Score": "6",
"Tags": [
"c#",
".net"
],
"Title": "C# Code Optimization -- Finding nearest key in a SortedList"
} | 18155 |
<p>First, some background. I have a <code>Payment</code> model that <code>has_many :subscriptions</code>. When a user pays (creates a new payment), I have an <code>after_create</code> callback that adds the newly created <code>@payment.id</code> to <code>@subscriptions.payment_id</code>. Here's what it looks like:</p>
... | [] | [
{
"body": "<p>Considering you have a state machine, you're probably doing the right thing by looping through the records. Although you could change all the subscriptions (including their state) in the database, you'd be bypassing the state machine and whatever checks and callbacks it has in place.</p>\n\n<p>But... | {
"AcceptedAnswerId": "18194",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-02T16:57:51.207",
"Id": "18158",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails",
"callback"
],
"Title": "Update subscription"
} | 18158 |
<p>My application has two parts -- a client and a server. Within this, there are different versions for different platforms. The user specifies this in the args, i.e. "make PLATFORM=x11".</p>
<p>However, I feel like I'm separating the client and server build operations in a very inefficient way, and that I have too ... | [] | [
{
"body": "<p>You can definitely simplify that:</p>\n\n<pre><code>TARGET ?= CLIENT\n\nSRC_FILES := $(wildcard $($(TARGET)_NAME_DIR)*.c)\n\n ^^^^^^^^^^^\n</code></pre>\n\n<p>Here $(TARGET) will expand first (to CLIENT or what is set on the command line) and then $(CLI... | {
"AcceptedAnswerId": "18168",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-02T18:53:02.183",
"Id": "18159",
"Score": "4",
"Tags": [
"c",
"makefile"
],
"Title": "Makefile -- Platform Dependency"
} | 18159 |
<p>I have the following <code>.click()</code> functions:</p>
<pre><code>$('.tab').click(function(){
$('.tab').removeClass('activeTab');
$(this).addClass('activeTab');
});
$('.edit').click(function(){
$(this).hide();
$(this).next().show();
});
$('.cancel').click(function(){
$(this).parent().hide()... | [] | [
{
"body": "<p>I think you're looking for something along the lines of:</p>\n\n<pre><code>$('.tab, .edit, .cancel').click(function(){\n switch(this.className){\n case 'tab' : {\n $('.tab').removeClass('activeTab');\n $(this).addClass('activeTab');\n }break;\n case 'e... | {
"AcceptedAnswerId": "18215",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-02T19:04:01.393",
"Id": "18160",
"Score": "11",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Different way of writing multiple click functions"
} | 18160 |
<p>With some free time, I decided to study artificial neural networks as an academic exercise (not homework). Over the course of my studies, I decided to write a Python application that would allow me to create and train arbitrary feed forward networks so I could see the concrete math. So far, the test harness only inc... | [] | [
{
"body": "<p>Consider breaknig out the training logic from the network so there can be instances of non-trainable perceptrons. Presumably in this case there would be a mechanism for saving and loading weight data (by using pickle for example), which becomes easier without the pollution of the training data.</p... | {
"AcceptedAnswerId": "18243",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-02T22:00:26.067",
"Id": "18164",
"Score": "4",
"Tags": [
"python",
"ai",
"neural-network"
],
"Title": "Academic implementation of artificial neural network"
} | 18164 |
<p>This has taken me months to complete. From what little testing I have done, it seems to work. Let me know what I can do to spruce things up. I can't wait to start learning some more advanced concepts that would have made this easier. </p>
<pre><code># Imports, lots of imports,
from random import randint
from ... | [] | [
{
"body": "<p>The good news - you'll have to totally rewrite your game. But first...</p>\n\n<p><code>gladiator_quips</code> - quips would be better as a global constant, considering that it never changes, although one entry will need to be added after the character is generated.</p>\n\n<p>The training code cont... | {
"AcceptedAnswerId": "18227",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-02T23:08:45.733",
"Id": "18167",
"Score": "6",
"Tags": [
"python",
"game",
"dice",
"role-playing-game"
],
"Title": "LPTHW exercise 36 game"
} | 18167 |
<p>Below is my written code to determine if, based on the hypotenuse, a Pythagorean triple is possible, and what are the lengths. I was wondering if there is a more efficient way of doing so.</p>
<pre><code>#Victor C
#Determines if a right triangle with user inputted hypotenuse is capable of being a Pythagorean Triple... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T01:13:01.627",
"Id": "28988",
"Score": "0",
"body": "please format your code in a readable format"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T01:24:04.630",
"Id": "28989",
"Score": "0",
... | [
{
"body": "<p>First, let's write this with a little style, and go from there:</p>\n\n<pre><code>import math\n\ndef is_triple(hypotenuse):\n \"\"\"return (a, b, c) if Pythagrean Triple, else None\"\"\"\n if hypotenuse < 4:\n return None\n\n c = hypotenuse ** 2\n\n for a in xrange(3, hypoten... | {
"AcceptedAnswerId": "18172",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T01:09:31.610",
"Id": "18171",
"Score": "11",
"Tags": [
"python",
"performance",
"mathematics"
],
"Title": "Determining Pythagorean triples based on the hypotenuse"
} | 18171 |
<p>This code snippet is intended for validating the value of a property of an object. The min and max range is supplied as an .xml file like Nhibernate .hbm files. Since the data-type of the property is also read from the .xml file, we can only know the type of the property at run-time.</p>
<p>Is there any better way ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T07:30:02.830",
"Id": "28992",
"Score": "0",
"body": "You seem to duplicate your switch statements twice. Perhaps using polymorphism might be an approach worth considering here?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"C... | [
{
"body": "<p>Here's an attempt to use a bit of polymorphism. While doing this some things I did note were:</p>\n\n<p>1) The if statement at the end means that !minValueOk and !maxValueOk are irrelevant and will never be true. The first if should be !minValueOk and !maxValueOk rather than !(minValueOk &&a... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T06:13:37.517",
"Id": "18175",
"Score": "3",
"Tags": [
"c#",
"validation",
".net-2.0"
],
"Title": "Validating the value of a property of an object"
} | 18175 |
<p>I am using the Jersey client to make API calls to validate a session. This call is being made at a rate of around 5 calls/second. I want to ensure that the client call doesn't have performance issues.</p>
<pre><code>String sessionUrlPrefix = Config.getInstance().getString(Helper.SESSION_SERVICE_URL);
String urlPara... | [] | [
{
"body": "<p>I'm not familiar with Jersey at all, so just two generic notes:</p>\n\n<ol>\n<li><p>You might want/could use <a href=\"https://stackoverflow.com/questions/7132967/is-the-head-response-faster-than-the-get\">HEAD instead GET which does not download the message body</a>.</p></li>\n<li><p>I don't know... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T09:30:56.307",
"Id": "18178",
"Score": "2",
"Tags": [
"java",
"performance",
"jersey"
],
"Title": "Calling API (with rate of 5 calls/second) using Jersey client"
} | 18178 |
<p>I've written this relatively simple class to help with managing arrays of anonymous objects in my scripts. </p>
<pre><code>/**
* AoHandler - accepts an array of objects or creates a new array
* @param {array} ao
*/
function AOHandler(ao)
{
this.ao = typeof ao === 'object' ? ao : [];
/**
* pluck()
*... | [] | [
{
"body": "<p>To answer your specific concern about jQuery-dependence, the jQuery <code>extend</code> function is basically this:</p>\n\n<pre><code>var key;\nfor(key in objB) {\n objA[key] = objB[key]; // copy each value from objB into objA\n}\n</code></pre>\n\n<p>That's all there is to it really.</p>\n\n<p>Ho... | {
"AcceptedAnswerId": "18192",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T11:26:49.967",
"Id": "18179",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Array of objects handler"
} | 18179 |
<p>I would like to submit my enhanced concatenating function for your review. Originally, its method signature is:</p>
<pre><code>char *concat (const *char1, const *char2);
</code></pre>
<p>but after knowing that <a href="http://en.wikibooks.org/wiki/C%2B%2B_Programming/Code/Statements/Functions" rel="nofollow"><em>t... | [] | [
{
"body": "<p>Chris, you have misunderstood the text quoted about the caller supplying all of the arguments. Your original prototype was okay. I imagine the text you read meant that if a function declares parameters a, b and c, then the caller must supply arguments (ie values of some sort) for all of those para... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T16:59:40.317",
"Id": "18182",
"Score": "1",
"Tags": [
"c",
"strings"
],
"Title": "Enhanced concatenating function"
} | 18182 |
<p>I just wrote this function and am wondering if it's secure enough for storing passwords in a database:</p>
<pre><code>public static function hash($salt, $str) {
$salt = md5($salt);
$salt = '$2y$12$HfuPgoDY94nHJssqQeVLmH' . $salt . '$';
return crypt($str, $salt);
}
</code></pre>
| [] | [
{
"body": "<h2>Yes</h2>\n<p>Blowfish is a great algorithm for storing passwords, it makes generating a hash slow such that brute force attacks are unviable. It's also <a href=\"http://php.net/manual/en/faq.passwords.php\" rel=\"nofollow noreferrer\">php's recommended means of storing passwords</a>.</p>\n<h3>But... | {
"AcceptedAnswerId": "18208",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T18:01:07.580",
"Id": "18183",
"Score": "8",
"Tags": [
"php",
"security"
],
"Title": "Storing passwords in a database"
} | 18183 |
<p>I'm trying to create my user.class.php constructor but I don't know really much about POO so I'm going to tell you what I'm doing and I hope you could help me.</p>
<p><strong>user.class.php</strong></p>
<pre><code>class user {
private $fullname;
private $age;
private $email;
private $sex;
priva... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-11-11T02:54:43.200",
"Id": "126814",
"Score": "0",
"body": "All your instance vars are private, this will not work. echo $user->fullname;"
}
] | [
{
"body": "<p>First of all I recommend you to setup a local webserver to test your php code, if you have not done so jet (I assume you haven't tried your code, since your asking if it's going to work).</p>\n\n<p>Secondly you should abandon mysqli for <a href=\"http://php.net/manual/en/book.pdo.php\" rel=\"nofol... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T18:22:09.223",
"Id": "18187",
"Score": "3",
"Tags": [
"php"
],
"Title": "User function construct user.class"
} | 18187 |
<p>I would appreciate some feedback on my design of a few classes to query the <a href="http://trakt.tv/api-docs" rel="nofollow">Trakt.tv API</a>. </p>
<pre><code>public abstract class TraktQuery
{
private const string baseUrl = "http://api.trakt.tv/";
private const string apiKey = "[API key here]";
prote... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T20:32:01.740",
"Id": "29014",
"Score": "0",
"body": "Could you use generics to turn PerformQuery into PerformQuery<T>() where T: TraktResponse"
}
] | [
{
"body": "<p>Dreza has outlined the correct approach (the same used in <code>IComparable<T></code>). You can make your class generic, with a type constraint:</p>\n\n<pre><code>public abstract class TraktQuery<TResponse> where TResponse : TraktResponse\n</code></pre>\n\n<p>And change every occurence... | {
"AcceptedAnswerId": "18193",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T19:47:20.757",
"Id": "18190",
"Score": "3",
"Tags": [
"c#",
"casting"
],
"Title": "Returning a more specific class"
} | 18190 |
<p>I've been working on my own PHP framework for my projects. I just finished coding my DI container. There is always room for improvement. Any input be it good or bad on my code would be appreciated.</p>
<p>Also, would using exceptions instead of <code>die()</code> be a better approach?</p>
<p>Should I move the high... | [] | [
{
"body": "<p>Throwing Exceptions is better than die(), yes. However, you should consider throwing your own defined Exceptions instead of any built in php ones. For example, you could throw and InvalidService Exception from the getService method.</p>\n\n<p>Using namespaces will help you avoid naming collisions.... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T19:54:17.810",
"Id": "18191",
"Score": "4",
"Tags": [
"php",
"object-oriented",
"dependency-injection"
],
"Title": "Dependency Injector Container"
} | 18191 |
<p>I'd love to improve this code. I know I should put a lot of stuff in another class but I have no idea how.</p>
<pre><code>import java.util.Scanner;
public class UserInteraction {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int choice = 0;
String[] s... | [] | [
{
"body": "<p>Let's go through refactoring your code step by step.</p>\n\n<h1>Get (almost) everything out of main()</h1>\n\n<p><code>main()</code> should consist of the fewest lines to launch the program. In this case you only need one.</p>\n\n<pre><code> new UserInteraction().run();\n</code></pre>\n\n<p>Or... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T23:55:59.553",
"Id": "18196",
"Score": "2",
"Tags": [
"java"
],
"Title": "Displaying grades and calculating average grade"
} | 18196 |
<p>I have a console application that I'm trying to make with minimal redundant code.</p>
<p>I have 4 functions, Create, Read, Update, and Delete.</p>
<ul>
<li>is it possible or practical to combine the four functions into one function that takes different parameters to create, read, update, or delete?</li>
<li>is it ... | [] | [
{
"body": "<p>First off, thank you for the formatting and white space.</p>\n\n<p>To answer your question, having the CRUD operations into one is not possible. Somewhere you have to have different logic to do the operations, which is the standard way of doing thing</p>\n\n<p>Looking through your code, I see a f... | {
"AcceptedAnswerId": "18217",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-03T23:59:57.710",
"Id": "18197",
"Score": "5",
"Tags": [
"c#",
"optimization",
"design-patterns",
"entity-framework"
],
"Title": "combining 4 CRUD functions into 1?"
} | 18197 |
<p>I'm writing some crypto code, and as part of it, we have to implement modular exponentiation.
I have it working, both with the right-to-left binary method and with the Montgomery formula. </p>
<p>While they both work, the Montgomery calculations take three times longer than the right-to-left binary method. This is... | [] | [
{
"body": "<p>Not really an optimization note but I'd be much cleaner if you'd use a separate object to store the result value instead of the <code>BigInteger</code> array. Its keys are magic numbers currently. They could be named fields in the result object. It would also remove the risk of creating arrays wit... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-04T01:53:22.153",
"Id": "18199",
"Score": "3",
"Tags": [
"java",
"optimization",
"homework"
],
"Title": "Optimization of exponentiation"
} | 18199 |
<p>Even though it's simple, I've spent quite a bit of time on it, learning as I go. Is there anyway I can make this code more efficient, more crossbrowser compatible or just generally better?</p>
<p><a href="http://jsfiddle.net/njDvn/113/" rel="nofollow noreferrer">jsFiddle</a></p>
<pre><code><!-- Geocode -->
$... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-04T14:55:30.203",
"Id": "29053",
"Score": "1",
"body": "To get some quick ideas for improvements, you can try putting your code through [jslint](http://jslint.com), or [jshint](http://jshint.com) - jshint is easier to use as it require... | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>When you wrote <br></p>\n\n<pre><code>var latLng = results[0].geometry.location;\n$('#lat').val(results[0].geometry.location.lat());\n$('#lng').val(results[0].geometry.location.lng());\n</code></pre>\n\n<p>you probably meant to write </p>\n\n<pre><code>var lat... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-04T02:04:24.070",
"Id": "18200",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"geospatial",
"google-maps"
],
"Title": "Geocoder form with Google Maps autosuggest"
} | 18200 |
<h2>Summary</h2>
<p>I've created a function that blends tiles on a 2D hexagonal grid with their neighboring tiles based on an image that serves as a "blend mask". It runs, and isn't too intensive, but I feel it can be better / faster. Drawing pixel-by-pixel is very intensive even for the 108x122 (Relatively small) ima... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-04T22:04:10.597",
"Id": "29066",
"Score": "2",
"body": "Excellent, well-formatted, and interesting question. +1! I hope you'll get some helpful answers."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2018-01-17T07... | [
{
"body": "<p>First of all, very nice and interesting question!</p>\n\n<p>Second, <code>drawImage</code> is fast because it's native, compiled code - there's no interpreted JavaScript going on. And since it's native, it can utilize the computer in ways browser-based JavaScript simply can't. For instance, <code>... | {
"AcceptedAnswerId": "18228",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-04T07:05:00.790",
"Id": "18205",
"Score": "5",
"Tags": [
"javascript",
"performance",
"jquery",
"canvas"
],
"Title": "Optimize iterative pixel blending function"
} | 18205 |
<p>I want to give users help in which format they have to enter a date. The <code>label</code> content is: </p>
<blockquote>
<p>Date (YYYY-MM-DD)</p>
</blockquote>
<p>I used the following markup:</p>
<pre><code><label>Date (<kbd><abbr title="four-digit year">YYYY</abbr>-<abbr title="two-... | [] | [
{
"body": "<p>There is little point in using <code>code</code> markup here. Technically, it might not be completely wrong “semantically”, since the YYYY-MM-DD notation is really meant for computers rather than human beings, but what would it achieve? Monospace font by default?</p>\n\n<p>Using <code>kbd</code> i... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-04T19:01:18.460",
"Id": "18222",
"Score": "2",
"Tags": [
"html",
"html5"
],
"Title": "Markup \"YYYY-MM-DD\" as input hint"
} | 18222 |
<p>In ruby, is there a more concise way of expressing multiple AND conditions in an if statement?</p>
<p>For example this is the code I have:</p>
<pre><code> if first_name.blank? and last_name.blank? and email.blank? and phone.blank?
#do something
end
</code></pre>
<p>Is there a better way to express th... | [] | [
{
"body": "<pre><code>if [first_name, last_name, email, phone].all?(&:blank?)\n #do something\nend\n</code></pre>\n\n<p>Caveat: While <code>and</code>/<code>&&</code> short-circuit the expression (that's it, only the needed operands are evaluated), an array evaluates all its items in advance. In yo... | {
"AcceptedAnswerId": "18224",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-04T19:37:43.610",
"Id": "18223",
"Score": "3",
"Tags": [
"ruby"
],
"Title": "Expressing multiple AND conditions in ruby"
} | 18223 |
<p>I had this interview question like a year ago and was asked to code, on a piece of paper, how to reverse each word of a string. Since I am used to Java, I proposed the obvious answer of using split + reverse, which are native commands in Java. I was then told I couldn't use those, so I floundered and ended up with... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T12:19:32.663",
"Id": "29107",
"Score": "1",
"body": "Another thing that you need to consider is that words are not always terminated by a space. Punctuation also counts!.:,;?\nAnd, being awkward, what about numbers?"
}
] | [
{
"body": "<p>I like it; nice and logical and easy to follow.</p>\n\n<p>The only change I would make is the test for space.</p>\n\n<pre><code>*p == ' '\n</code></pre>\n\n<p>I would replace this with</p>\n\n<pre><code>isspace(*p)\n</code></pre>\n",
"comments": [],
"meta_data": {
"CommentCount": "0"... | {
"AcceptedAnswerId": "18249",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T02:14:19.597",
"Id": "18229",
"Score": "11",
"Tags": [
"c",
"beginner",
"strings",
"interview-questions"
],
"Title": "Reverse each word of a string in C"
} | 18229 |
<p>Basically this code is for an upvote/downvote system and I'm basically</p>
<ul>
<li>Incrementing the count by 1 when voting up</li>
<li>Decrementing the count by 1 when voting down</li>
<li>If the number of downvotes > upvotes, we'll assume it's a negative score, so the count stays 0</li>
<li>Reverting the count ba... | [] | [
{
"body": "<p>Don't use an A element for the up/down buttons, use a button or styled span element.</p>\n\n<p>The logic seems way more convoluted than necessary, consider something much simpler. The function below gets the original value, calculates the new value, then works out what to do with it. If it's withi... | {
"AcceptedAnswerId": "18234",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T05:03:21.510",
"Id": "18231",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Tips on how to refactor this unwieldy upvote/downvote code"
} | 18231 |
<p>Here is a class that executes the <code>CreateAPerson</code> use case. It takes a request object (which is a simple data structure), validates the request, creates a new person, and then returns a response object (another simple data structure).</p>
<p>For testability, I've created a setter that allows me to inject... | [] | [
{
"body": "<h2>Constructor injection</h2>\n\n<p>Use constructor injection becouse this is the best way to write well readable and testable code. If you don't need a Doctrine instance in your class then don't use it.</p>\n\n<pre><code>public function __construct($entityManager)\n {\n $this->setEntit... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T05:42:15.353",
"Id": "18232",
"Score": "2",
"Tags": [
"php",
"design-patterns",
"unit-testing",
"doctrine"
],
"Title": "Use case interactor"
} | 18232 |
<p>I'm trying to see if there is a loop I can use in order to pull off this code a little more elegantly. I was previously using a <code>foreach($row as $cell)</code> with <code>$row = mysqli_fetch_row($result)</code> but because of that I couldn't access the data from the 'user' column in order to check it against the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T07:44:26.177",
"Id": "29083",
"Score": "0",
"body": "You have not mentioned the structure of $result. You must be able to iterate the result set using foreach as you already tried before. Inside loop make sure you are pointing to da... | [
{
"body": "<h2>Mysqli_* functions or PDO</h2>\n\n<p>I would recommend you start using <a href=\"http://php.net/manual/en/book.pdo.php\" rel=\"nofollow\">PDO</a>, here is a good <a href=\"http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/\" rel=\"nofollow\">tutorial</a> f... | {
"AcceptedAnswerId": "20540",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T07:14:29.533",
"Id": "18236",
"Score": "1",
"Tags": [
"php",
"mysql"
],
"Title": "Trying to Find a Loop to use for a specific MySQL query"
} | 18236 |
<p>I think my code has too many functions... can it be written better?</p>
<p>Please help reviewing my jQuery functions.</p>
<h1>HTML</h1>
<pre><code><div class="event_owner">
<p>
<label for="xxx">xxx</label>
<input type="radio" name="event_owner" id="xxx">
</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-06T03:13:03.407",
"Id": "29137",
"Score": "3",
"body": "I'm wondering what you're trying to accomplish. You set the value of the text field with the radio buttons, but what if someone just writes something else in the field? Now the fi... | [
{
"body": "<p>There are a few points worth mentioning:</p>\n\n<ol>\n<li><p>Your code does not actually function the way you want it to.<br>\n<code>$(\".event_owner input[type='text']\").length</code> checks for the existence of that element, not whether its value is set.</p></li>\n<li><p>Your radio buttons don'... | {
"AcceptedAnswerId": "18274",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-05T08:37:48.073",
"Id": "18239",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Playing with radio input"
} | 18239 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.