body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I am defining a subclass of a the python dictionary object <code>mpCmd</code> where every item is converted to a lambda. The intended usage is that every item in the dictionary can be called with a single list argument (<code>row</code>) that will return a value based on <code>row</code>. Integers and optionally s... | [] | [
{
"body": "<p>I have a few points I would like to suggest.</p>\n\n<p>Firstly, I would rename the <code>name_to_index</code> function to fit the verb-first function naming convention. Based on your other naming conventions, I would use something like <code>convert_name_to_index</code>.</p>\n\n<hr>\n\n<p>The next... | {
"AcceptedAnswerId": "51296",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T19:54:35.480",
"Id": "51247",
"Score": "17",
"Tags": [
"python",
"hash-map",
"lambda"
],
"Title": "Python Dictionary Black Magic"
} | 51247 |
<p>I started learning Haskell to see if I can use it at my job. A lot of my work is processing text files for data extraction and analysis.</p>
<p>For my first test, I added a counter at the end of each line from a .csv text file (currently I don't care about the format management).</p>
<p>My current code in Haskell ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-10-25T14:23:43.030",
"Id": "199801",
"Score": "0",
"body": "@ChriX (if you're still around), if your job includes a lot of text processing and data extraction, you should really learn the tools for the job: `sed`, `awk` and `perl`, in ord... | [
{
"body": "<p>An obvious bottleneck is the conversion to <code>String</code> and back. Try changing the type signatures to</p>\n\n<pre><code>addRecordId :: L.ByteString -> String -> Int -> L.ByteString\n\naddIncrementalId :: String -> [L.ByteString] -> [L.ByteString]\n\nidentifyFile :: FilePath -... | {
"AcceptedAnswerId": "51253",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-17T20:18:00.203",
"Id": "51251",
"Score": "10",
"Tags": [
"performance",
"haskell",
"comparative-review"
],
"Title": "Processing text files for data extraction and analysis"
} | 51251 |
<p>I have given an assignment where I have to escape a labyrinth. The goal is to find the shortest way. I have done some research and there seem to be two strategies to solve the problem: the <a href="http://en.wikipedia.org/wiki/Depth-first_search" rel="noreferrer">Depth-first search</a> and <a href="http://en.wikiped... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T21:27:59.373",
"Id": "88501",
"Score": "3",
"body": "Welcome to Code Review! You have a quite nice question here, but it would be even more amazing and awesome if you could provide a short and simple compilable example with an examp... | [
{
"body": "<p>Reviewing Code:</p>\n\n<p><strong>Names</strong></p>\n\n<p>When naming classes in hierarchies, share the naming conventions used in the standard libraries. Therefore, your top level interface should be Maze, not IMaze. Likewise, IMazePosition.</p>\n\n<p><strong>Repetition</strong></p>\n\n<p>You ... | {
"AcceptedAnswerId": "51263",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T20:54:33.840",
"Id": "51254",
"Score": "8",
"Tags": [
"java",
"algorithm",
"graph",
"pathfinding"
],
"Title": "Escaping the prison - finding the shortest way"
} | 51254 |
<p>The problem I have is to find the sum of 2 linked lists. Each linked list node contains 1 digit that represents a number.</p>
<p>My algorithm works but I was wondering if there is a more efficient (speed and memory wise) to solve this problem OR maybe some minor tweaks I can do to reduce space and runtime.</p>
<p>... | [] | [
{
"body": "<h2>Don't repeat yourself</h2>\n\n<p>Your method has the same code duplicated twice in it. You should always try to eliminate this kind of duplication, for example like this:</p>\n\n<pre><code>def addlists(LL1, LL2):\n return sumlist(LL1) + sumlist(LL2)\n\ndef sumlist(LL1):\n storage = []\n ... | {
"AcceptedAnswerId": "51261",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T21:44:14.237",
"Id": "51258",
"Score": "4",
"Tags": [
"python"
],
"Title": "Adding 2 linked lists"
} | 51258 |
<p>I'm using C# in .NET 4. The class holds an array of <code>double</code> that represents a 2-D rectangular matrix but (due to business requirements) must be stored flattened (i.e. a <code>double[]</code>). The class also stores the dimensions of the array. I wish to sort the array by the (virtual) first column. Obvio... | [] | [
{
"body": "<p>You can improve the code for 3 or more columns and at the same time use it for 1 or 2 columns, by using LINQ:</p>\n\n<pre><code>public partial class FlattenedArray\n{\n public int rows;\n public int cols;\n public double[] array;\n public void sort()\n {\n array = (from i in ... | {
"AcceptedAnswerId": "51276",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T21:55:09.613",
"Id": "51259",
"Score": "4",
"Tags": [
"c#",
"sorting"
],
"Title": "Sorting a flattened array"
} | 51259 |
<p>I created a script to hide a menu during user inactivity and when the position of my page is left < 2.</p>
<p>I would like to know if I use a good method regarding the performances. It's not too heavy ? Should I optimize my code ?</p>
<pre><code>var interval = 1;
setInterval(function(){
var posx=$("#page")... | [] | [
{
"body": "<p>Hmmm... polling at regular intervals instead of using a handler... not good. It means that the interval between the event (<code>mousemove</code>, etc) and the call to <code>fadeOut</code> is variable. It also means that the script continues to use up a small amount of CPU while nothing is happeni... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T22:40:01.437",
"Id": "51264",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Hide menu during user inactivity with jQuery, setInterval performance"
} | 51264 |
<p>I have made a small game in Javascript, while simultaneously learn about the ever so popular model view controller. The game is this, there are 3 players(green, purple, yellow) and they have to try and build a path of arrows to the blue square. The first player to make the path go to the blue square wins. When the p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T07:13:09.790",
"Id": "89560",
"Score": "0",
"body": "\"Never\" name your model `Model`. Usually there is not the ONE model in a given context. You have a model of your board. You have a model of your player. You may even have a mode... | [
{
"body": "<p>Work In Progress,</p>\n\n<p>interesting code, I had to try a few times to understand how to win the game. Please dont change the code again, since I made a copy and I am working on that copy.</p>\n\n<p><strong>UI</strong></p>\n\n<p>While not typically part of CodeReview, the UI should give you all... | {
"AcceptedAnswerId": "51851",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T22:51:37.487",
"Id": "51266",
"Score": "7",
"Tags": [
"javascript",
"jquery",
"mvc",
"backbone.js",
"mvvm"
],
"Title": "MV* Pattern for a board game"
} | 51266 |
<p>I have to list the number of documents related to items in a hierarchical tree. </p>
<p>The specification states:
The tree will only ever be 2 levels deep.
The higher level items will list not only the number of documents in it's folder, but also the total count of documents in the child folders. They want this ... | [] | [
{
"body": "<p>You can create lookup for children. That will involve single enumeration over items collection instead of enumerating all items for each calculation of each item.</p>\n\n<p>I.e. you currently have <strong>2 * N * N</strong> iterations for calculating child count and child item count. With lookup y... | {
"AcceptedAnswerId": "51268",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T23:25:42.120",
"Id": "51267",
"Score": "4",
"Tags": [
"c#",
"linq",
"lambda"
],
"Title": "Sum(), ForEach() with Lambda in a hierarchical List Collection"
} | 51267 |
<p>I am working on a socket HTTP post request. Here is one method that I come up with. It looks dirty and is in C instead of C++.</p>
<pre><code>bool SendBasicInfo(USER* user, SOCKET sock)
{
char FormBuffer[1024];
char DataType1[] = "a=";
char DataType2[] = "&b=";
char DataType3[] = "&c=";
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T00:55:51.497",
"Id": "88522",
"Score": "2",
"body": "Is there any reason you're using C strings instead of using `std::string` and then simply using `c_str`? Are there some forms of restrictions or something?"
}
] | [
{
"body": "<blockquote>\n <p>This was working fine, but it just seems hard-coded and wrong.</p>\n</blockquote>\n\n<p>It's a monolythic monster. It works, but if you have the time, you could benefit from re-writing it (using c++ alternatives).</p>\n\n<blockquote>\n <p>How can I make the size of FormBuffer to b... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T00:34:30.573",
"Id": "51270",
"Score": "6",
"Tags": [
"c++",
"http",
"socket"
],
"Title": "Socket HTTP post request"
} | 51270 |
<p>I've started coding about 3 weeks ago, just for fun and maybe practical uses later. My GF dared me to make a PGM that would replace this dice game where you roll two dice, one with body parts and one with actions, then resulting in stuff like 'kiss, lips'.</p>
<p>All I know is off of YouTube and sites such as Stack... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-05-23T17:24:23.673",
"Id": "166178",
"Score": "1",
"body": "[Follow-up question](http://codereview.stackexchange.com/q/52228/9357)"
}
] | [
{
"body": "<p>Many things need improvement I'll edit this answer as the day goes</p>\n\n<h2>print() and strings.</h2>\n\n<p>You are using <code>print</code> redundantly. consider the <code>menu</code> function. You can use block text with either <code>\"\"\" \"\"\"</code> or <code>''' '''</code>. </p>\n\n<p>Wi... | {
"AcceptedAnswerId": "51303",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T02:46:37.493",
"Id": "51272",
"Score": "26",
"Tags": [
"python",
"beginner",
"game",
"python-3.x",
"dice"
],
"Title": "Spin-the-bottle-like game"
} | 51272 |
<p>I'm trying to figure out a better way to structure some of my code so that I don't have a ton of conditionals here. I have a series of checkboxes that someone authors on the backend and if they are checked I set a variable with a specific value. I then use that variable and set options in my jQuery plugin. This work... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T03:01:45.303",
"Id": "51273",
"Score": "2",
"Tags": [
"javascript",
"html",
"jstl"
],
"Title": "Series of checkboxes"
} | 51273 |
<p>This is my very-first-ever run at TDD. How did I do?</p>
<p>In keeping with <a href="http://butunclebob.com/ArticleS.UncleBob.TheThreeRulesOfTdd" rel="nofollow">Uncle Bob's Three Rules</a>, I wrote every test first, starting in order from the top down as you see here (below). Here's the sequence I used:</p>
<ol>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T06:41:29.863",
"Id": "88537",
"Score": "1",
"body": "Actually I'm not sure what your code should do at all. Just a general hint for starting with TDD: Start with a [CodeKada](http://content.codersdojo.org/code-kata-catalogue/roman-n... | [
{
"body": "<p><code>Assert.IsNotNull(oSession)</code> is in general a really weak test. Maybe you want to test anything in the session or the history etc.</p>\n\n<p>Testing <code>Assert.IsTrue(UpdateHistoryReader.Main.EnumerateHistory)</code> is usually also not enough. What if your <code>success</code> return ... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T04:39:10.810",
"Id": "51274",
"Score": "2",
"Tags": [
".net",
"unit-testing",
"vb.net"
],
"Title": "This TDD code seems noisy"
} | 51274 |
<p>I am working on a project in which I construct a URL with a valid hostname (but not a blocked hostname) and then execute that URL using <code>RestTemplate</code> from my main thread. I also have a single background thread in my application which parses the data from the URL and extracts the block list of hostnames f... | [] | [
{
"body": "<p>When I looked first I was thinking you don't need it cause <code>ConcurrentHashMap</code> has <code>atomic</code> operations.</p>\n\n<p>But when I read your full <code>ClientData</code> I see that you create a map where the key is the same as your value.</p>\n\n<h2>Next thinking of me :</h2>\n\n<p... | {
"AcceptedAnswerId": "51277",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T04:41:04.173",
"Id": "51275",
"Score": "7",
"Tags": [
"java",
"performance",
"multithreading",
"thread-safety",
"atomic"
],
"Title": "Constructing a URL for execution"
... | 51275 |
<p>I have an n-tier solution which consist of DAL,BL and a ASP.net WebAPI project. I'm new with <strong>Asynchronous Pattern</strong> and I'm trying to add it to my Framework. Am I using the asynchronous pattern correctly? I'm not convinced with my implementation of it. Could you give me a recommendation on how to use ... | [] | [
{
"body": "<p>I can see your implementation as a nice example of async programming. Being async enables you to keep your UI responsive while waiting for the response. You may not be so convinced as you just need to make a call and why do you need to wait for it? But the reason is responsiveness of the UI that g... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-05-21T06:23:00.903",
"Id": "51278",
"Score": "5",
"Tags": [
"c#",
"multithreading",
"asynchronous",
"async-await"
],
"Title": "Asynchronous Pattern"
} | 51278 |
<p>I have the following linq statement that is ordering a list of assets by the sort order of a child item:</p>
<pre><code> Assets.OrderBy(a => a.GalleryItems != null &&
a.GalleryItems.FirstOrDefault(gi => gi.ProductItemCode == productId) != null
? a.GalleryItems.Firs... | [] | [
{
"body": "<p>You're correct, it <em>can</em> be costly.</p>\n\n<p>You can just expand the lambda expression:</p>\n\n<pre><code>Assets.OrderBy(a => {\n var item = a.GalleryItems != null \n ? a.GalleryItems.FirstOrDefault(gi => gi.ProductItemCode == productId)\n : null;\n ... | {
"AcceptedAnswerId": "51288",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T09:33:13.073",
"Id": "51287",
"Score": "2",
"Tags": [
"c#",
"linq"
],
"Title": "Is there a better way to do this linq sort?"
} | 51287 |
<p>I've been working on a new project and I've found myself needing to make multiple Ajax calls, often on the same page and at the same time. I decided rather than repeating code that I would try and make a reusable object that to handle these calls. </p>
<p>I'm very new to Object Orientated JavaScript so I'm looking ... | [] | [
{
"body": "<p>From a quick once over:</p>\n\n<ul>\n<li>JsHint.com has very little feedback, good!</li>\n<li>Consider using <code>use strict</code> to activate strict mode</li>\n<li>Avoid console.log</li>\n<li>Both <code>beforeSend</code> , <code>error</code> and <code>complete</code> should be customizable by t... | {
"AcceptedAnswerId": "51295",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T10:28:48.903",
"Id": "51289",
"Score": "7",
"Tags": [
"javascript",
"object-oriented",
"ajax"
],
"Title": "Reusable Ajax object"
} | 51289 |
<p>I want to show how to interact with C from C++ and chose a simple and small library to demonstrate. zlib's <code>gzopen</code>, <code>gzwrite</code> and <code>gzclose</code> looked like a reasonably closed set of funtions.</p>
<p>Does anyone see anything fundamentally wrong with my presentaion? The main code I pres... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T11:40:23.860",
"Id": "88560",
"Score": "0",
"body": "Could you specify more precisely which kind of interaction of C and C++ you want to show? For example I am missing `extern \"C\" {}` which might be necessary for non C++ compatibl... | [
{
"body": "<p>This example is mostly about making and using a RAII wrapper, not about calling C from C++ (which is trivial).</p>\n\n<p>If you want to show how to call C-like interfaces, then use zlib directly, without wrapping it.</p>\n\n<p>If you want to show the native C++ way to wrap a C interface, then the ... | {
"AcceptedAnswerId": "51328",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T11:23:18.577",
"Id": "51292",
"Score": "6",
"Tags": [
"c++",
"c",
"compression"
],
"Title": "C++ demo code for interaction with C"
} | 51292 |
<p>I've wrote this CoffeScript function to compare values in a table, but it turned out to be a HUGE function.</p>
<p>Since the code is really really long, you can find it <a href="https://gist.github.com/emisfera/394c12af055e0239e2f2">here</a> as well.</p>
<p>Code explanation:</p>
<p>The code searches for all the v... | [] | [
{
"body": "<p>You don't seem to have a representation of your table as data, just in the DOM.\nThat's making this a really cumbersome job. This will be more legible if you\nfollow the <a href=\"http://www.faqs.org/docs/artu/ch01s06.html\">Rule of Representation</a>.\nRepresent your table as an array of objects.... | {
"AcceptedAnswerId": "51326",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T11:48:04.697",
"Id": "51293",
"Score": "10",
"Tags": [
"optimization",
"coffeescript"
],
"Title": "Optimize CoffeeScript comparison function"
} | 51293 |
<p><strong>Context:</strong></p>
<p>I have to create an interface between devices and a client.
My package is composed of:</p>
<ul>
<li>Device.py</li>
<li>Error.py</li>
<li>DeviceA.py (for example)</li>
<li>DeviceB.py</li>
<li>...</li>
</ul>
<p>Basically each <code>DeviceA</code>, <code>DeviceB</code>, ... inherit D... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T06:34:58.680",
"Id": "88709",
"Score": "0",
"body": "You mention \"each device follow his own FSM\", but the code you posted does not include that. Could you expand the code to better illustrate what goes on in there?"
},
{
... | [
{
"body": "<p>You <strong>could</strong> simply have if-statements in each method of your class. This would probably result in (slightly) lesser lines of code than my suggestions. However, I think that solution has a lot of repeated code and is quite static. What if you wanted a device that simply simulates? Or... | {
"AcceptedAnswerId": "51323",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T13:23:36.083",
"Id": "51298",
"Score": "1",
"Tags": [
"python",
"simulation"
],
"Title": "Implement operation and simulation mode in an interface"
} | 51298 |
<p>For the server of which this is part, it makes a request to one of our web servers to validate whether the PHP Session ID is actually valid. The location <code>this._options.url</code> is a URL that, given a <code>PHPSESSID</code> as a cookie, will return the user ID that is attached.</p>
<p>One of the issues that... | [] | [
{
"body": "<p>Interesting question, I would rewrite </p>\n\n<pre><code>try{\n var arr = JSON.parse(data);\n}catch(e){\n callback(e, false);\n}\ncallback(null, arr.uid);\n</code></pre>\n\n<p>as </p>\n\n<pre><code>try{\n var arr = JSON.parse(data);\n callback(null, arr.uid);\n}catch(e){\n callback(... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T13:51:09.463",
"Id": "51300",
"Score": "4",
"Tags": [
"javascript",
"node.js",
"http",
"socket.io"
],
"Title": "Socket.IO handshake module"
} | 51300 |
<p>In the following code I'm trying to calculate Net Wage of employees and classes <code>Earning</code>, <code>Deduction</code> and <code>WageBalance</code> has a composition relationship with <code>WageInfo</code>. And there is a class called <code>WageManager</code> which is having a association with <code>WageInfo</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T06:39:15.117",
"Id": "88710",
"Score": "0",
"body": "Does `Deduction` have `employeeID` also? And how do you know `GetEarningsList()` and `GetDeductionList()` return matching elements? How do you know they will stay that way?"
},
... | [
{
"body": "<h2>Formatting</h2>\n\n<p>formatting inside your <code>foreach</code> should be indented</p>\n\n<p>This:</p>\n\n<pre><code> foreach (Earning e in earningList)\n {\n\n// Sum all earnings...\n\n var totalEarnings = earningList[i].AmountForEPF + earningList[i].OverTimeAmount + earni... | {
"AcceptedAnswerId": "51443",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T14:09:50.730",
"Id": "51302",
"Score": "16",
"Tags": [
"c#",
"object-oriented",
"mvp"
],
"Title": "Calculate balance wages"
} | 51302 |
<p>I've been writing a small library that allows for easy querying of the Stack Exchange websockets.</p>
<p>I'm going to add an <code>enum</code> to replace the manual <code>SiteId</code> at every <code>RequestParameter</code> so you can let that one slide (unless you have something else in mind).</p>
<p>A few though... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-29T13:38:37.177",
"Id": "89968",
"Score": "0",
"body": "Are you not `using System;`? Why is `System.Console` fully qualified?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-29T14:06:54.113",
"Id": "899... | [
{
"body": "<p>I will look at this again in a couple of days or maybe even later today, but here is something I saw right at the end of the question</p>\n\n<pre><code> WebSocketReceiveResult response;\n\n while (true)\n {\n response =\n await _s... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T14:22:23.627",
"Id": "51304",
"Score": "12",
"Tags": [
"c#",
"async-await",
"stackexchange",
"websocket"
],
"Title": "Stack Exchange websockets wrapper"
} | 51304 |
<p><a href="http://en.wikipedia.org/wiki/WebSockets" rel="nofollow">WebSockets</a> (or WebSocket) is an API and a protocol for bi-directional, full-duplex communication over TCP sockets. The WebSockets API was originally part of the <a href="http://whatwg.org/html5" rel="nofollow">HTML5</a> standard, but it has been sp... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T14:30:50.633",
"Id": "51305",
"Score": "0",
"Tags": null,
"Title": null
} | 51305 |
WebSocket is an API and a protocol for bi-directional, full-duplex communication that is closely associated with HTML5 and implemented in recent versions of most web browsers. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T14:30:50.633",
"Id": "51306",
"Score": "0",
"Tags": null,
"Title": null
} | 51306 |
<p>I would like to develop a student management system with repository pattern using ado.net (no EF or MVC).</p>
<p>I decided to create the model (business objects) and interfaces as one project "StudentModel". Implementing the interfaces to fetch data from DB as one project "StudentImpl" and the third will be the web... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T15:00:56.463",
"Id": "88585",
"Score": "0",
"body": "If someone can guide me to achieve the same through MVC and EF, it would be great."
}
] | [
{
"body": "<p>The only thing I'd say about your repository, is that <code>FindAll</code> shouldn't return an <code>IList<T></code>, but an <code>IEnumerable<T></code>. And you're probably missing a method like <code>GetById</code> that returns only a single record - right now the only way to fetch a... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T14:55:20.473",
"Id": "51308",
"Score": "11",
"Tags": [
"c#",
"object-oriented",
"design-patterns",
"ado.net"
],
"Title": "3 tier architecture ado.net application"
} | 51308 |
<p><a href="http://en.wikipedia.org/wiki/WebSockets" rel="nofollow noreferrer">WebSockets</a> (or WebSocket) is an API and a protocol for bi-directional, full-duplex communication over TCP sockets. The WebSockets API was originally part of the <a href="http://whatwg.org/html5" rel="nofollow noreferrer">HTML5</a> standa... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-05-21T15:13:54.903",
"Id": "51310",
"Score": "0",
"Tags": null,
"Title": null
} | 51310 |
WebSocket is an API and a protocol for bi-directional, full-duplex communication that is closely associated with HTML5 and implemented in recent versions of most web browsers. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T15:13:54.903",
"Id": "51311",
"Score": "0",
"Tags": null,
"Title": null
} | 51311 |
<p>I'm working through SICP and have implemented exercise 1.11 (Pascal's Triangle). What I'm curious about here is performance considerations by defining functions within the main function. I would assume they get reassigned with each invocation of the function. In saying that, this style appeals to me, as the function... | [] | [
{
"body": "<p>Yes, those inner functions do get reassigned at each invocation, but that's cheap. In sane implementations, the inner function bodies are compiled just once, with a new lexical environment attached each time.</p>\n\n<p>(In other sane implementations, the inner functions could be inlined into the o... | {
"AcceptedAnswerId": "51315",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T15:56:08.683",
"Id": "51314",
"Score": "3",
"Tags": [
"performance",
"beginner",
"scheme",
"sicp"
],
"Title": "This snippet of scheme calculates a value in pascal's triangl... | 51314 |
<p>Just for the fun of it, I decided I would try to create sort of an intermediate DNS system for the <a href="https://code.google.com/p/oddsock/" rel="nofollow">oddsock SOCKS proxy</a>. With this, the domain name extension .unet is statically resolved when requested. All of this is hooked into the oddsocks proxy syste... | [] | [
{
"body": "<ul>\n<li><p>I'd recommend staying consistent with curly brace usage for conditionals. It can help with readability and also ease maintainability if you end up needing to add additional lines.</p>\n\n<pre><code>if (someCondition)\n{\n // do something...\n // can still do something else...\n}\n... | {
"AcceptedAnswerId": "51342",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T16:26:16.673",
"Id": "51316",
"Score": "11",
"Tags": [
"c",
"linked-list",
"networking",
"library",
"curl"
],
"Title": "Dynamic library to intercept oddsock hostname lo... | 51316 |
<p>As a test of my C# skills, I have been asked to create a simple web service which will take a message from a queue table in a SQL database and send it to a web application when a button is pressed on the application. I have never written a web service before so I am going in a little blind here so was after some ad... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T18:48:12.663",
"Id": "88630",
"Score": "1",
"body": "What is the nature of this \"skills test\"? Seems like asking the internet for a better solution won't be a good indicator of *your* skills."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>LINQ is a good choice. You're querying something, so it lends itself to the task.</p>\n\n<p>That being said, the exception handling is atrocious. Making your return values <code>null</code>, some command's value from the database or some big honkin' exception text is abusing the <code>string</code... | {
"AcceptedAnswerId": "51336",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T17:04:52.753",
"Id": "51321",
"Score": "6",
"Tags": [
"c#",
"beginner",
"linq",
"asp.net",
"web-services"
],
"Title": "Web service getting value using LINQ from queue t... | 51321 |
<p>Let's say I have a configuration file with a property in it:</p>
<pre><code><add key="LoadedCode" value="L" />
</code></pre>
<p>I know I can reference this using the ConfigurationManager:</p>
<pre><code>System.Configuration.ConfigurationManager.AppSettings["LoadedCode"];
</code></pre>
<p>This has some draw... | [] | [
{
"body": "<p>You shouldn't have to use the fully qualified name, you should be able to do something like this</p>\n\n<pre><code>using System.Configuration;\n\npublic static string LoadedCode\n{\n get { return ConfigurationManager.AppSettings[\"LoadedCode\"]; }\n}\n</code></pre>\n\n<p>I think you can even go... | {
"AcceptedAnswerId": "51325",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T17:23:22.263",
"Id": "51322",
"Score": "7",
"Tags": [
"c#",
"asp.net",
"properties"
],
"Title": "How to Make Strongly-typed References to Web.Config?"
} | 51322 |
<pre><code><!DOCTYPE html>
<html>
<script>
////////////////////////////
// Code by Zachary Holmes //
////////////////////////////
// This program determines the number of boxes that can fit into the back of a truck
// Declaring box size in centimetres, and converting it into metres
var boxHe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T18:40:01.670",
"Id": "88629",
"Score": "6",
"body": "Welcome to Code Review! What are you looking for with this post? Style recommendations? Performance tweaks? Having a question (or several questions) we can respond to goes a **lon... | [
{
"body": "<p>I guess I would change your box variable names to something a little more descriptive maybe something like:</p>\n\n<pre><code> var boxHeightInMeters;\n</code></pre>\n\n<hr>\n\n<p>Like I said in the comments, this is a super simple script that doesn't really do a whole lot, there isn't much to twe... | {
"AcceptedAnswerId": "51333",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T18:35:59.430",
"Id": "51327",
"Score": "10",
"Tags": [
"javascript",
"mathematics"
],
"Title": "Finding the number of boxes that can fit into a truck using JavaScript"
} | 51327 |
<p>I am building an ASP.NET MVC 5 application and, for reasons which are irrelevant at this point, I am attempting to build my own means of authenticating users. I'm still very new to programming, especially to this sort of thing, and I realize that what looks fine to me may be full of problems. Thus, I present my code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T19:25:06.827",
"Id": "88639",
"Score": "3",
"body": "I would only have 1 question for you : Why didn't you want to use the one that come with a new tutorial program. Rolling your own authentication system is one hell of a job."
},... | [
{
"body": "<p>I fear that the credentials could be sniff by some attacker if they are listening to during the connection process. If https is not enabled, the password (if there is no protection) could be seen by any attacker during the HTTP requests.</p>\n\n<p>This point is not directly related as to how you i... | {
"AcceptedAnswerId": "51334",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T19:22:58.977",
"Id": "51331",
"Score": "12",
"Tags": [
"c#",
"beginner",
"reinventing-the-wheel",
"authentication",
"asp.net-mvc-5"
],
"Title": "Simple authentication i... | 51331 |
<p>I've written a working web crawler in Java that finds the frequencies of words on web pages. I have two issues with it. </p>
<ul>
<li><p>The organization of my code in <strong>WebCrawler.java</strong> is terrible. Is there a way I could refactor the class to make it more readable? Perhaps splitting it into multiple... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T00:24:37.570",
"Id": "88676",
"Score": "3",
"body": "Apart from the obvious code-review, you could consider using Lucene with a RAMDirectory for indexing the documents, and that will 'stem' the words for you (pages -> page), as well... | [
{
"body": "<ol>\n<li><p>If I'm right you could eliminate most of the threading-logic with an <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ExecutorService.html\" rel=\"nofollow noreferrer\"><code>ExecutorService</code></a> and an <a href=\"http://docs.oracle.com/javase/7/docs/api/java/... | {
"AcceptedAnswerId": "55496",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T00:17:53.043",
"Id": "51347",
"Score": "5",
"Tags": [
"java",
"web-scraping"
],
"Title": "Web Crawler in Java"
} | 51347 |
<p>This code works as I intended, but I am definitely a JS noob (C++ background), so I'm not sure if this is the best way to do it (for example using <code>.each</code> instead of some kind of a <code>for</code> loop was completely new to me).</p>
<p><a href="https://github.com/TaylorHuston/menuBreak/blob/master/menuB... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>You could have used a <code>loop</code> instead of <code>.each()</code>, it would be marginally faster</li>\n<li>Your indenting is off, I assume you had trouble pasting the code</li>\n<li><code>.9</code> and <code>.7</code> are magic constants, you should declare... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T00:18:02.673",
"Id": "51348",
"Score": "6",
"Tags": [
"javascript",
"jquery",
"beginner"
],
"Title": "Breaking up a navigation menu"
} | 51348 |
<p>Which of these three methods is better?</p>
<pre><code>import java.util.* ;
public class anycode{
public static void print_digits3(int num){
//this method converts integer to string and parses it
int digit = 0 ;
String num_str = new Integer(num).toString() ;
int counter = 0 ;
while(count... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T15:20:41.950",
"Id": "88815",
"Score": "1",
"body": "What makes you think `Integer.toString()` isn't the most efficient math possible for this use case? Did you look to see how it converts a number to a string, and then try to adapt... | [
{
"body": "<p>The trick you are missing here is the logarithm. What you want to do is \\$\\log_{10}{value}\\$ to get the scale.</p>\n\n<pre><code>private static void printDigits(int val) {\n int base = (int)Math.pow(10, (int)Math.log10(val));\n while (base > 0) {\n System.out.print(\" \" + (val ... | {
"AcceptedAnswerId": "51393",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T00:20:19.527",
"Id": "51349",
"Score": "5",
"Tags": [
"java",
"strings",
"parsing",
"integer",
"comparative-review"
],
"Title": "Printing every digit of a number"
} | 51349 |
<p>I have made a lot of changes to the code over the course of the evening, but after making most of the suggested changes, the variable that the answer is returning is showing up as "undefined". Could someone please help me find my errors in this code? I have tried and have not been able to find the errors due to my l... | [] | [
{
"body": "<p>This is an interesting pattern:</p>\n\n<pre><code>var heightA = boxHeight > 0 ? ((truckHeight / boxHeight) | 0) : 0;\n</code></pre>\n\n<p>I assume you intend to be using integer division here? Ie, <code>5/2 | 0 = 2</code>? </p>\n\n<p>Also.. why are you repeatedly declaring different variables w... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T00:46:43.353",
"Id": "51353",
"Score": "1",
"Tags": [
"javascript",
"mathematics"
],
"Title": "Finding the number of boxes that fit into a truck using JavaScript (Followup Q)"
} | 51353 |
<p>For example, given the string "xyz", return the string "xxyyzz".</p>
<p>I was given this as a part of a test. I would really appreciate if you can help me to find a better way of doing it.</p>
<p>I came up with two methods to do the same thing but one was an extension method.</p>
<p>I have a couple more questions... | [] | [
{
"body": "<p>No reason to write anything when string is empty. </p>\n\n<pre><code>public string RepeatAString(string sInputString, int repeatCount)\n{\n StringBuilder sOutputString = new StringBuilder();\n\n foreach (char c in sInputString)\n sOutputString.Append(new String(c, repeatCount));\n\n ... | {
"AcceptedAnswerId": "51391",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T00:56:00.400",
"Id": "51354",
"Score": "4",
"Tags": [
"c#",
"strings"
],
"Title": "Given a string, return a string where every character in the original is doubled"
} | 51354 |
<p>I'm looking for a review of my code for better design (to make sure it's more readable and legible).</p>
<pre><code><?php
// define variables and set to empty values
$nameErr = $phoneErr = $streetErr = $cityErr = $stateErr = $zipErr = "";
$name = $phone = $street = $city = $state = $zip = "";
// start script i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T01:45:23.867",
"Id": "88687",
"Score": "1",
"body": "Welcome. Could you please describe this code for better context? Does it work as intended? If it does work, what type(s) of review are you seeking?"
},
{
"ContentLicens... | [
{
"body": "<ol>\n<li><p>you should be using arrays to store your variable.</p></li>\n<li><p>your coding <code>if</code> syntax are not indented and formatted well.<br> \n<a href=\"https://stackoverflow.com/questions/253030/best-way-to-format-if-statement-with-multiple-conditions\">https://stackoverflow.com/ques... | {
"AcceptedAnswerId": "51358",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T01:40:30.467",
"Id": "51356",
"Score": "4",
"Tags": [
"php",
"beginner",
"html"
],
"Title": "Validating various input HTML forms"
} | 51356 |
<p><strong>Context:</strong></p>
<p>I am using XNA to create a simple game / learning project.</p>
<p><strong>Problem:</strong></p>
<p>I have three interfaces, each with a different purpose in mind. However, the way I use them, as well as their implementations, makes me feel as if my code is overdesigned and poorly ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-07-08T21:28:44.013",
"Id": "175866",
"Score": "0",
"body": "I'm voting to close this question as off-topic because this is mostly a design review."
}
] | [
{
"body": "<blockquote>\n <p><em>Is my code overdesigned?</em></p>\n</blockquote>\n\n<p>I think so ;)</p>\n\n<hr>\n\n<blockquote>\n <p><code>IChunk<T></code> is intended to be a grid object with a predetermined size.</p>\n\n<pre><code>public interface IChunk<T> : IGrid<T>\n{\n}\n</code></pre... | {
"AcceptedAnswerId": "51753",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T01:52:56.397",
"Id": "51357",
"Score": "2",
"Tags": [
"c#",
"design-patterns",
"inheritance",
"xna"
],
"Title": "Is my code overdesigned? Does it rely too heavily on interf... | 51357 |
<p>Use recursion in the solution.</p>
<p>I would really appreciate if you can help me to find a better way to do it.</p>
<pre><code>public class AppendCharacterAfterEachCharacterInString
{
int index =0;
StringBuilder outputString = new StringBuilder();
public string AppendInputCharacterAfterEachCharacter... | [] | [
{
"body": "<p>Well, you've <em>used</em> recursion, but I wouldn't say that's a recursive solution because you have variables outside your functions that control what your functions do. </p>\n\n<p>A recursive solution will have a function that is repeatedly called with smaller and smaller sub-problems, terminat... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T02:10:57.600",
"Id": "51359",
"Score": "6",
"Tags": [
"c#",
"strings"
],
"Title": "A method which, given a string, returns a string in which each character is separated by an asterisk... | 51359 |
<p>I would really appreciate if you can help me to find a better way to do it.</p>
<pre><code>public class SplitArray
{
public SplitArray() { }
public bool CanArrayBeSplit(int[] intArray)
{
foreach(var pair in GeneratePairs(intArray))
{
if (pair.Item1 == pair.Item2)... | [] | [
{
"body": "<ol>\n<li>You do not need to re-caclcute sum on every iteration in your <code>GeneratePairs()</code> method. You can simply create two varaibles which would hold the sums of two \"sides\" of your array. Then on every iteration you can simply add the item value to the first variable and subtract it fr... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T02:22:23.687",
"Id": "51361",
"Score": "5",
"Tags": [
"c#",
"array"
],
"Title": "Split the array so that the sum of the numbers on one side of the split equals the sum of the numbers ... | 51361 |
<p>which of the following code you prefer and why?</p>
<p>The scenario is, I need to pass the recent folder path to folder browser dialog and if user selects any folder, need to save it back. The value is stored in Application settings.</p>
<p>My settings class.</p>
<pre><code> internal sealed class Settings : A... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T03:10:43.570",
"Id": "88693",
"Score": "1",
"body": "The answer to A vs B questions is often C... which one are you using?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-21T15:47:35.520",
"Id": "959... | [
{
"body": "<p>Extensions are good when you want to re-use this logic in multiple places. As it seems to be the case, i would go with the second method. Generally it is a good practice to avoid code duplication where possible.</p>\n\n<p>The only possible issue i see is that those two methods have different behav... | {
"AcceptedAnswerId": "51374",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T02:58:50.203",
"Id": "51363",
"Score": "4",
"Tags": [
"c#",
"extension-methods"
],
"Title": "Folder browser dialog to remember recent folder. Which method is better?"
} | 51363 |
<p>I'm creating a small project, but in the past I've used a Repository pattern for it, and it just seemed too bloated. I ended up having repo classes with huge amounts of queries. I'm trying to move away from that. I invite you to critique/help/guide me on my journey to less abstraction:</p>
<p><strong>Note</strong>:... | [] | [
{
"body": "<p>I realize you said</p>\n\n<blockquote>\n <p>my naming/style is inspired by them.</p>\n</blockquote>\n\n<p>But I would still point out some of your naming conventions which don't align with C#s. </p>\n\n<ul>\n<li><p>Method/Function level variables should be <code>camelCase</code> instead of <code>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T03:17:40.147",
"Id": "51364",
"Score": "5",
"Tags": [
"c#",
"design-patterns"
],
"Title": "UnitOfWork, removing abstraction of abstraction (Repository)"
} | 51364 |
<p>I was trying to get my computer information and I came up with this code. It is working but I need opinions on how I am doing it. It is my first time to using <code>std::string</code> to return strings. Is it good or is there another way around?</p>
<pre><code>struct USER
{
std::string ID;
std::string Usern... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T04:03:49.220",
"Id": "88696",
"Score": "0",
"body": "Your `struct USER` name doesn't seem to match `User* u`, but I am assuming that's an oversight and they're really the same type."
}
] | [
{
"body": "<p>Looks perfectly fine to me, except you probably only need one <code>return Version;</code> at the end of the <code>GetOSVersion()</code> function. Also, I would consider a <code>return;</code> at the end of a <code>void</code> function unnecessary.</p>\n",
"comments": [
{
"Conten... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T03:47:17.723",
"Id": "51367",
"Score": "3",
"Tags": [
"c++",
"windows"
],
"Title": "Getting computer info"
} | 51367 |
<p>In my application, a notification should be displayed when a chat message arrives. <br> There are some rules which decide what notification message is to be displayed. </p>
<p>I have created a helper method which takes a <code>ChatMessage</code> object and returns the message to be displayed in the notification. </... | [] | [
{
"body": "<p>Some simple pointers...</p>\n\n<ul>\n<li><p>You have <code>boolean</code> assignments that are only used once, for conciseness it may be preferable to inline them:</p>\n\n<pre><code>// old\nboolean isUpdateMessage = (chat.getTag().equals(TAG_UPDATE_MSG));\nif (isUpdateMessage) \n\n// new\nif (chat... | {
"AcceptedAnswerId": "51394",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T03:49:47.430",
"Id": "51368",
"Score": "5",
"Tags": [
"java"
],
"Title": "Helper function to return a string based on passed object and some defined rules"
} | 51368 |
<p>The purpose: an express node.js server which can be launched using naught, with an integration test using supertest. Each worker naught runs will test itself on a unique port, and only if passes it will listen in on the main port and join the pool. </p>
<p>Major concerns are - no idea what I'm doing. How I provisi... | [] | [
{
"body": "<p>I think you should write more code before submitting, the fun part to review is the code that you wrote after the prototype ;)</p>\n\n<p>From a quick once over:</p>\n\n<ul>\n<li>JsHint finds no fault except for some mixed use of tabs and space</li>\n<li>Consider <code>'use strict'</code>, it can s... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T06:25:27.200",
"Id": "51376",
"Score": "1",
"Tags": [
"javascript",
"unit-testing",
"node.js",
"express.js"
],
"Title": "Testing individual nodes launched by naught using supe... | 51376 |
<p>I have big search method in my model that corresponds to search a proper Car. </p>
<p>It looks like this:</p>
<pre><code> def self.search(params)
cars = joins(:reservations).where.not("reservations.reception_time <= ? AND reservations.return_time >= ?",
params[:return_date], params[:handover_dat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T07:29:54.350",
"Id": "88715",
"Score": "0",
"body": "Does this help? http://stackoverflow.com/a/4480285/188031"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T07:48:17.917",
"Id": "88719",
"Sc... | [
{
"body": "<p>Some notes on your code:</p>\n\n<ul>\n<li>As you know, in Rails, <code>params</code> usually refers to query strings in a request. In a model I'd use something like <code>attributes</code> or simply <code>options</code> to avoid confussion.</li>\n<li>Variable <code>cars</code> reused multiple time... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T07:21:44.993",
"Id": "51378",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Ruby on Rails: refactor big search method"
} | 51378 |
<p>Please tell me how I can improve the structure of this simple tool (depends on <code>MissingH</code>):</p>
<pre><code>module Main (main) where
import Data.List(isInfixOf)
import Data.String.Utils(replace)
import System.Environment(getArgs)
import System.Directory(renameFile, getDirectoryContents)
pathsContaining ... | [] | [
{
"body": "<p>That seems pretty good. I would probably not write pathsReject and pathsContaining since you only use them once and their definition is as short as their name and very easy to understand (I don't see how naming <code>map (replace r \"\") ps</code> makes code easier to understand, the name is not o... | {
"AcceptedAnswerId": "51590",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T07:22:24.073",
"Id": "51379",
"Score": "1",
"Tags": [
"beginner",
"haskell",
"file-system"
],
"Title": "Batch file renamer"
} | 51379 |
<p>I am moving a project from Python to C++, partly in order to achieve a speed up. </p>
<p>This part of the code reads large .txt data files (well only about 2MB per file, but quite a lot of files), and needs to convert the data to floating point.</p>
<p>This C++ code does is not faster than Python bytecode (.pyc). ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T07:52:57.030",
"Id": "88720",
"Score": "2",
"body": "First thing to do is to profile the code. What you'll probably find is that almost all the time is spent in I/O operations. Reading data off a hard-drive is almost always going to... | [
{
"body": "<p>The first principle of optimization is: \"measure don't guess\". So the first step is to use a profiler on your platform to measure the most consuming steps in your algorithm. It may depend on compilation options (optimization turned on/off). On my platform (x86-64 Linux/g++ 4.8.1 with -O3), the m... | {
"AcceptedAnswerId": "51385",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T07:46:39.217",
"Id": "51381",
"Score": "4",
"Tags": [
"python",
"c++",
"beginner",
"performance"
],
"Title": "Large ASCII file data read"
} | 51381 |
<p>I am currently working on a piece of legacy code that I inherited. <strong>The current Java version is 6, but this will change in the next few weeks to Java 7.</strong> I think I might have been working on it for too long as I get the impression that it can be made much more readable as I have many byte-wise operati... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T13:14:18.050",
"Id": "88789",
"Score": "0",
"body": "A better measure of \"too long\" is number of local variables rather than actual LOC. By that measure this code really isn't a red flag just based on the sheer size of the method... | [
{
"body": "<p>Just three short points I want to get done with:</p>\n<h3>Instantiating CmdDef:</h3>\n<blockquote>\n<pre><code>CmdDef cmdBbc = new CmdDef(SfRecordType.BBC);\nCmdDef cmdBog = new CmdDef(SfRecordType.BOG);\n//and the other similar calls.\n</code></pre>\n</blockquote>\n<p>While this code Is nice and ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T07:49:41.713",
"Id": "51382",
"Score": "5",
"Tags": [
"java"
],
"Title": "Creating a barcode bytewise"
} | 51382 |
<p>I am parsing a text file (UTF-8) and checking for several conditions that need to be satisfied for the code to be happy. If not, then there is no point to continue and the program should die. </p>
<p>At the moment I am catching exceptions and if caught, throw <code>RuntimeException</code> to signal the user that so... | [] | [
{
"body": "<p>I don't think you are using a correct approach here unfortunately.<br>\nDue to time constraints I'll focus only on your main question, while the rest of the code may be worthwhile to review aswell.</p>\n\n<p>You have a method called <code>readMazeFromFile</code>, it is expected to either return a ... | {
"AcceptedAnswerId": "51395",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T09:17:22.860",
"Id": "51386",
"Score": "9",
"Tags": [
"java",
"file",
"error-handling"
],
"Title": "Proper way of handling exceptions while reading user input from file"
} | 51386 |
<p>I'm wondering if providing default behavior is ever worth the confusion caused by ignoring generic type passed in. <a href="https://stackoverflow.com/questions/23798679/java-generics-seem-to-work-differently-for-classes-than-for-methods">Another question</a> brought up this issue: </p>
<pre><code>public class Activ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T10:46:44.217",
"Id": "88745",
"Score": "0",
"body": "Welcome to Code Review! Unfortunately I don't find this a good question for this site because of one main reason: I don't think you're going to use this exact code in a real proje... | [
{
"body": "<p>No, this is all broken. The basic issue is the cast-to-D in the following line:</p>\n\n<blockquote>\n<pre><code>this.d = (D)new MyWaterFowl();\n</code></pre>\n</blockquote>\n\n<p>That gives the warning:</p>\n\n<blockquote>\n<pre><code>Type safety: Unchecked cast from MyWaterFowl to D\n</code></pre... | {
"AcceptedAnswerId": "51398",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T09:18:31.110",
"Id": "51387",
"Score": "0",
"Tags": [
"java",
"generics"
],
"Title": "Interface Segregation Principle in constructor"
} | 51387 |
<p>I have created a class called <code>CommandMessages</code></p>
<pre><code> public class CommandMessages
{
public string CommandType { get; set; }
public string Command { get; set; }
public DateTime? SendDateTime { get; set; }
public CommandMessages()
{
}
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T13:02:22.023",
"Id": "88788",
"Score": "0",
"body": "You have a value object and a database query. There is not much to do here. If you get many request, you might want to share the database connection, instead of creating new ones.... | [
{
"body": "<p>This code here is not good</p>\n\n<pre><code>using (SqlDataReader reader = command.ExecuteReader())\n{\n while (reader.Read())\n result.CommandType = reader.GetString(0);\n result.Command = reader.GetString(1);\n result.SendDateTime = reader.GetDateTime(2);\n reader.... | {
"AcceptedAnswerId": "51410",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T09:24:59.923",
"Id": "51388",
"Score": "2",
"Tags": [
"c#",
"asp.net",
"converting",
"web-services",
"object"
],
"Title": "Web service - getting data from SQL and addin... | 51388 |
<p>I'm not sure if my lock usage is correct and safe. I wanted to know what will be best approach to deal with situation when one thread have to wait for being initialized by another so I written this test:</p>
<pre><code>import java.util.concurrent.locks.ReentrantLock
import java.util.{TimerTask, Timer, Date}
import ... | [] | [
{
"body": "<p>A completely different approach to your answer is a concept called <strong>Actors</strong>.</p>\n\n<p>Rather than having multiple threads, and having these threads await each other, <strong>Actors</strong> are like tiny little processes that communicate with each other by sending <strong>messages<... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T10:56:30.150",
"Id": "51397",
"Score": "2",
"Tags": [
"performance",
"scala",
"locking",
"concurrency",
"promise"
],
"Title": "Testing Promises vs Lock performance"
} | 51397 |
<p>I'm looking for a review on my code. I am also looking for ways to transform this function into something more Pythonic. I'm fairly new to Python, so any advice would be appreciated. </p>
<pre><code>def get_rsi(self, period):
rsi = []
for i in xrange(1, len(self.hist_d) - period + 1):
gains = 0.0
... | [] | [
{
"body": "<p>It looks like you want a moving window of length <code>period</code> over <code>self.hist_d</code> (and then a moving window of length <code>2</code> over each of those windows, to get pairs of consecutive years). An efficient way of doing that is provided in the old version of <a href=\"https://d... | {
"AcceptedAnswerId": "51416",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T13:26:54.610",
"Id": "51406",
"Score": "5",
"Tags": [
"python",
"beginner",
"finance"
],
"Title": "Calculating relative strength index over a period"
} | 51406 |
<p>I wrote a "foreach" implementation for <code>std::tuple</code>:</p>
<pre><code>#pragma once
#include <tuple>
/**
* Callback example:
struct Call{
float k=0;
template<typename T, int Index> // lambda function not efficient than this. Tested -O2 clang, gcc 4.8
inline void call(T &am... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T19:33:11.807",
"Id": "88856",
"Score": "1",
"body": "I used to use recursion a lot with templates. But I have moved from recursion to using `std::integer_sequence` and `std::tuple` to get the equivalent of a loop (though underneath ... | [
{
"body": "<p>I used to use recursion a lot with templates. But I have moved from recursion to using <a href=\"http://en.cppreference.com/w/cpp/utility/integer_sequence\"><code>std::integer_sequence</code></a> and <a href=\"http://en.cppreference.com/w/cpp/utility/tuple\"><code>std::tuple</code></a> to get the ... | {
"AcceptedAnswerId": "67394",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T13:29:22.443",
"Id": "51407",
"Score": "17",
"Tags": [
"c++",
"c++11",
"template",
"template-meta-programming"
],
"Title": "std::tuple foreach implementation"
} | 51407 |
<p>So I have this rather large function, which adds to an array. What it also does is searches the array to see if the item already exists and adds to the quantity if it does. If <code>has_options == 1</code> then it will search the <code>oid</code> instead of the <code>pid</code>. </p>
<p>Is there any better way to w... | [] | [
{
"body": "<p>Yes, you are right. There is A LOT of repeated code ;) Your code is a prime example on why it is <strong>essential</strong> to have correct indentation. Personally, it was very tough to tell where I was in this mammoth of an if-statement.</p>\n\n<p>Your code also is a shining example of why I <str... | {
"AcceptedAnswerId": "51436",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T14:23:46.067",
"Id": "51411",
"Score": "2",
"Tags": [
"javascript",
"angular.js"
],
"Title": "Adding to an array, adding to an existing index if it exists"
} | 51411 |
<p>I've not done JavaScript in quite a while, but I wanted to make it so that I can circle (in many different ways) around the bounding box of a tagged item.</p>
<p>Is this a good way of doing what I'm wanting?</p>
<p>Is there a better way? E.g. can this be done with only CSS?</p>
<p>Or better style? E.g. can I use... | [] | [
{
"body": "<p>The <code>data-*</code> attributes are saved in the <code>Element.prototype.dataList</code> property, you can retrieve them like <code>element.dataList['width']</code>. Furthermore, since you use jQuery you can simply use the <code>.data()</code> method of jQuery:</p>\n\n<pre><code>var rect = obj... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T14:23:52.280",
"Id": "51412",
"Score": "3",
"Tags": [
"javascript",
"canvas"
],
"Title": "Is this a good way of writing custom tag attributes and rendering code?"
} | 51412 |
<p>Following advice to "Make good use of <code>toString()</code> for all Domain classes", I made what I thought was the most useful <code>toString</code> for my class. I found that certain operations happen before there are values for the components of the <code>toString</code>. I wonder if there is a cleaner way to... | [] | [
{
"body": "<p>You could do:</p>\n\n<pre><code>String toString(){\n \"${ass?.app?.appName ?: ''} ${step?.stepName ?: 'null'}\"\n}\n</code></pre>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T16:06:15.893",
... | {
"AcceptedAnswerId": "51422",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T15:34:46.080",
"Id": "51419",
"Score": "1",
"Tags": [
"beginner",
"null",
"groovy",
"grails"
],
"Title": "Domain object toString null check"
} | 51419 |
<p>I am creating a social sharing counter plugin for my WordPress blog. I want to fetch the counts of number of likes, shares, Facebook comments (I am using Facebook comment box), twitter tweet counts and a count of how many users have added a particular article to reading list.</p>
<p>The way I have implemented is th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T19:13:31.367",
"Id": "89224",
"Score": "0",
"body": "Are the values passed via AJAX the new total for that field? Can you explain \"weird behavior\"?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T19... | [
{
"body": "<p>One improvement you can make for DRYness is to replace the <code>switch</code> with a simple <code>if</code>. This is possible because the AJAX call passes the field name in the <code>type</code> parameter (they all seem to match).</p>\n\n<pre><code>static $FIELD_TYPES = array(\n 'comment' =>... | {
"AcceptedAnswerId": "51647",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T15:38:08.330",
"Id": "51420",
"Score": "2",
"Tags": [
"php",
"locking",
"wordpress"
],
"Title": "Social sharing counter plugin"
} | 51420 |
<p>What do I need to do to prevent injections? In addition, if I have any statement/parameter errors, please tell me.</p>
<pre><code> <?
$username = 'username';
$pass = 'pass';
$cpass = 'cpass';
$email = 'email';
$gender = 'gender';
$firstname = 'firstname';
$lastname = 'lastname';
$phone... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T16:21:01.117",
"Id": "88823",
"Score": "2",
"body": "What if I set my user name to `0 OR <> 0; DELETE FROM users;` ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T16:28:46.193",
"Id": "88825",
... | [
{
"body": "<p>Let me offer at least a partial answer in regards to MySQL and prepared statements. Someone else can address PHP once your code is cleaner. </p>\n\n<p>You would exec the following code within your MySQL instance. This needs done only once.</p>\n\n<pre><code>-- start creating procs\n\nDELIMITER // ... | {
"AcceptedAnswerId": "51455",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T16:05:50.493",
"Id": "51421",
"Score": "6",
"Tags": [
"php5",
"mysqli",
"sql-injection"
],
"Title": "How is my injection protection?"
} | 51421 |
<p>I'm currently working on a Qt project writing Excel files through a third party DLL.
As the third party DLL has a COM interface, I have to do lots of conversions between QString and BSTR...</p>
<p>I wrote the following two methods to do the conversions:</p>
<pre><code>QString ExcelClass::bstrToQString(const BSTR &... | [] | [
{
"body": "<p>why not use the <a href=\"http://qt-project.org/doc/qt-5/qstring.html#toWCharArray\" rel=\"nofollow\">toWcharArray</a>?</p>\n\n<pre><code>BSTR ExcelClass::qstringToBstr(const QString &qstring) const\n{\n WCHAR* const pBuffer = new WCHAR[qstring.size()+1]; //large enough to hold the stri... | {
"AcceptedAnswerId": "51431",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T16:29:30.730",
"Id": "51424",
"Score": "2",
"Tags": [
"c++",
"qt",
"com"
],
"Title": "Conversion between QString and BSTR"
} | 51424 |
<p>I'm making a JSON call and receiving data and inputting the data received into some HTML. However I don't think this is the best way to return the data. It's seems like a bit of a hack as I'm injecting a bunch of HTML in my jQuery. I'm also adding an image inside of my jQuery cause I want it to appear between some o... | [] | [
{
"body": "<p>A much more maintainable solution would be using templates, like <a href=\"http://handlebarsjs.com/\" rel=\"nofollow\">Handlebars</a>. This is to primarily avoid HTML in the JS, which can get messy in the long run:</p>\n\n<p>Assuming your data looks like:</p>\n\n<pre><code>{\n media : [\n {\"d... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T16:33:05.553",
"Id": "51425",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"json"
],
"Title": "Restructuring data received from JSON call"
} | 51425 |
<pre><code>class ReportFormat(object):
PDF = 0
TEXT = 1
class Report(object):
"""Strategy context."""
def __init__(self, format_):
self.title = 'Monthly report'
self.text = ['Things are going', 'really, really well.']
self.format_ = format_
class Handler(object):
def __... | [] | [
{
"body": "<p>In my opinion, this is abuse of the <a href=\"http://en.wikipedia.org/wiki/Chain-of-responsibility_pattern\" rel=\"nofollow\">Chain-of-responsibility Pattern</a>. It is completely surprising that <code>pdf_handler.handle(report)</code> would generate a text report instead.</p>\n\n<p>The Wikipedia... | {
"AcceptedAnswerId": "51432",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T16:48:16.860",
"Id": "51429",
"Score": "4",
"Tags": [
"python",
"design-patterns",
"python-2.x"
],
"Title": "Chain of responsibility pattern"
} | 51429 |
<p>I came across Java like Scala code that I am trying to refactor to make it functional and immutable. The first obvious flaw is that it's violating thread safety by using mutable public class level collections.</p>
<p>Those methods (<code>insText</code>, <code>insInt</code>, etc) look unnecessary and can be removed... | [] | [
{
"body": "<p>You are mixing a repository with a classifier. The classifier is not doing anything except separating out keys from non-keys. The repository doesn't do anything with what it holds. You convert strings to a particular type and then store them back as strings, without gaining any real value along th... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T18:10:16.240",
"Id": "51435",
"Score": "3",
"Tags": [
"object-oriented",
"functional-programming",
"scala",
"immutability"
],
"Title": "Functional SaveObject in Scala"
} | 51435 |
<p>I'm coming from Backbone and trying to wrap my head around Angular for a new project and would like to get some feedback on whether I'm using it correctly or not.</p>
<p><a href="http://plnkr.co/edit/59hj2WJfjV6Bl8kNmNZw" rel="nofollow">Plunker</a></p>
<p>What I'm trying to accomplish is this: I have a list of ite... | [] | [
{
"body": "<p>If the only reason is to avoid a few more DOM elements, this sounds like an overkill to me. It is so much easier to use <code>ng-show</code> or hiding/showing depending on the class like it is done in <a href=\"https://github.com/tastejs/todomvc/tree/gh-pages/architecture-examples/angularjs\" rel=... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T18:46:21.280",
"Id": "51438",
"Score": "4",
"Tags": [
"javascript",
"html",
"angular.js"
],
"Title": "Am I using Angular directives correctly?"
} | 51438 |
<p>I have one container <code>div</code> which contains some children <code>div</code> members. From time to time, I need to run a custom blinking effects on some of the child <code>div</code> members. The effect steps are as follows:</p>
<ol>
<li>Change font color to Yellow </li>
<li>Pause for 0.5 secs</li>
<li>Chang... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T20:38:44.200",
"Id": "88866",
"Score": "1",
"body": "Hi, and welcome to Code Review. Your question would benefit from having a [JSFiddle](http://jsfiddle.net/) to illustrate your task. Have you considered putting one together?"
},... | [
{
"body": "<p>It would probably be more efficient to simply put all the logic into a loop rather than calling it recursively. You end up with a million copies of that function running until the page closes otherwise.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense... | {
"AcceptedAnswerId": "51459",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T20:14:02.697",
"Id": "51440",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"animation"
],
"Title": "jQuery animation/blinking code?"
} | 51440 |
<p>On my machine it runs in about 60 seconds and about 2-3 minutes live.</p>
<p>The criteria needed are:</p>
<ul>
<li>Current month only (from first of month until current day)</li>
<li>I need the rank of the currently logged in person based on total sales.</li>
<li><p>I have two tables across two databases where thi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T23:20:12.427",
"Id": "88902",
"Score": "3",
"body": "I just rolled back your recent edit, because it invalidated parts of an answer. Have a look at this meta post [about why invalidating edits are rolled back, and what to do instead... | [
{
"body": "<p>To make things short as I am on my mobile right now:</p>\n\n<p>Calculate start- and enddate outside of the foreach loop. This is the most obvious step to performance here.</p>\n\n<p>On a related note.. drop the hungarian Notation. Prefixing str and dt respectively adds no meaning to the name of th... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T20:59:48.643",
"Id": "51444",
"Score": "5",
"Tags": [
"c#",
"performance",
"datetime"
],
"Title": "Speed up query to rank team sales by aggregating data from two databases"
} | 51444 |
<p>I'm using the Observer pattern to notify my UI that the object they're representing has changed. Also, I'm refreshing this object from the interwebs. Therefore, I'm ending up with two instances representing the same object. One with old values, one with refreshed values.</p>
<p>I have written this util class that r... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T00:29:30.213",
"Id": "88908",
"Score": "1",
"body": "Welcome to Code Review! Could you provide some example use-cases of this code? I'm trying to see the bigger picture here..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [
{
"body": "<pre><code> if (receivers.isEmpty() && providers.isEmpty()) {\n return;\n }\n\n if (providers.isEmpty()) {\n receivers.clear();\n return;\n }\n</code></pre>\n\n<p>You can remove the first if statement, it's not necessary. Clearing a list that has no elements i... | {
"AcceptedAnswerId": "59481",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T21:39:52.043",
"Id": "51451",
"Score": "11",
"Tags": [
"java",
"optimization",
"performance"
],
"Title": "Recursively using reflection to merge fields"
} | 51451 |
<p>I've started caring about standards and the beauty of my code. I doubt whether I've written it correctly and aesthetically. Can you please judge this simple, exemplary program? I want to know of any mistakes I've made. It converts an integer number given in the argument to binary, hexadecimal and octal number. Ignor... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T22:10:11.580",
"Id": "88883",
"Score": "3",
"body": "can you use lib funcs instead cause then it's just `std::cout << std::hex << num;` for hex"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T22:14:55... | [
{
"body": "<p>I'll just address several things regarding good practice. This can probably be simplified greatly overall, but I won't try to focus on that particularly.</p>\n\n<p><strong><code>main()</code>:</strong></p>\n\n<ul>\n<li><p>I don't see the need for <code>if (number == 0)</code>, especially in relat... | {
"AcceptedAnswerId": "51464",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T21:50:05.683",
"Id": "51453",
"Score": "9",
"Tags": [
"c++",
"converting",
"integer"
],
"Title": "Converting an integer to binary, hex, and octal"
} | 51453 |
<p>This code determines the maximum number of boxes (one size) that can fit into the back of a truck, checking all possible orientations to ensure maximum Bin Packing excitement. This is (hopefully) the final version of this code. Please share any modifications that you would make to this code below.</p>
<pre><code>&... | [] | [
{
"body": "<p>I think a big first improvement for you will be to start <a href=\"http://en.wikipedia.org/wiki/Don%27t_repeat_yourself\" rel=\"nofollow\">DRYing</a> out your code. You should create a function which returns the ratio of two sides -- there is much too much repetition in your code. Something like:<... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T21:53:01.803",
"Id": "51454",
"Score": "7",
"Tags": [
"javascript",
"mathematics",
"combinatorics"
],
"Title": "Simplified Bin Packing using JavaScript"
} | 51454 |
<p>I am working on a project that will allow developers to create a console application using a dependency injection service container. Both the console and container are Symfony components with some glue code to make it all work together.</p>
<p>The project can be found <a href="https://github.com/kherge/php-shell" r... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T22:10:34.540",
"Id": "51457",
"Score": "3",
"Tags": [
"php",
"console",
"dependency-injection",
"symfony2"
],
"Title": "Building a console application using a DI service conta... | 51457 |
<p>This is a Python script I made to download a URL from the clipboard.</p>
<p>When a new URL is copied to a clipboard it adds the URL to a download queue, then on a separate thread it downloads the URL to a file. </p>
<p>I am new to multithreading. Is my script properly using multithreading? It needs to download th... | [] | [
{
"body": "<ul>\n<li><p>You maintain <code>old_url</code> as well as <code>past_links</code>. You probably don't need <code>old_url</code> at all because everything you process will be added to <code>past_links</code>.</p>\n</li>\n<li><p>You are reading <code>past_links</code> as one giant string with embedded ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T23:13:31.523",
"Id": "51460",
"Score": "4",
"Tags": [
"python",
"multithreading",
"url"
],
"Title": "Download URL from clipboard"
} | 51460 |
<p>I feel that this implementation can still be simplified. I've tried to keep variable scopes low and have used as much of the standard library as I could.</p>
<p>It currently works with a hard-coded word or phrase, but I eventually plan on having it work with random words or phrases from a file.</p>
<p>My main con... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T23:42:47.037",
"Id": "88903",
"Score": "0",
"body": "My personal preference is that main should try as hard as possible to do nothing but utilize other classes or functions. (preprocessor, selection, and loop constructs notwithstand... | [
{
"body": "<p>My personal preference is that main should try as hard as possible to do nothing but utilize other classes or functions; preprocessor, selection, and loop constructs notwithstanding.</p>\n\n<p>Because of this policy (it's a little to simple to warrant the use of classes):</p>\n\n<ol>\n<li>The read... | {
"AcceptedAnswerId": "51489",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-22T23:21:39.180",
"Id": "51461",
"Score": "10",
"Tags": [
"c++",
"game",
"console",
"hangman"
],
"Title": "Hangman game with hard-coded word or phrase"
} | 51461 |
<p>I'm trying to create some helper functions that will allow me to convert from one unit of measurement to another. I eventually will need to be able to do speeds and temperatures as well, but so far, I've only implemented lengths. I'm not using C++11 for this solution.</p>
<p>Here are my <code>struct</code>s. My <co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T00:27:06.727",
"Id": "88907",
"Score": "0",
"body": "@GregHewgill Unless I'm misunderstanding your comment, there would not be a \"zeptomile\"."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T01:02:06... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T00:22:59.247",
"Id": "51467",
"Score": "2",
"Tags": [
"c++",
"converting",
"c++03"
],
"Title": "Length Conversions"
} | 51467 |
<p>I'm trying to figure out if there's a way I can simplify this code which is used to generate a robots.txt file with numerous rules. Different files/folders are separated in separate arrays because they're applied differently but in some cases they are applied the same. In these cases, rather than write out a separ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T03:01:14.547",
"Id": "89380",
"Score": "0",
"body": "There's a couple of syntax errors in this; `\"User-agent: '` uses the wrong quote types and a bracket in `__PS_BASE_)URI__`"
}
] | [
{
"body": "<p>If number of lines is your primary concern, then really all we can do with this is merge your array creation lines, and use <a href=\"http://php.net/array_merge\" rel=\"nofollow\"><code>array_merge()</code></a> to create temporary arrays which you can loop around, like so:</p>\n\n<pre><code>public... | {
"AcceptedAnswerId": "51730",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T00:23:25.453",
"Id": "51468",
"Score": "1",
"Tags": [
"php",
"array"
],
"Title": "Robots files generation - simplifying foreach code"
} | 51468 |
<p>I wrote a script that would change example.jpg to example-color.jpg (.png, .gif would work too) on mouse hover and changes it back on mouse leave. I'm making a portfolio, and I have examples of my work in black and white thumbnails, on hover they switch to colored ones. </p>
<p>I'm just wondering if I did this in a... | [] | [
{
"body": "<p>On another approach, you could do spriting. One problem you'll encounter with that approach, where you change src is that the image will take some time to load before the hover image appears. That's annoying. With sprites, you have one image just positioned differently on a container. There's no l... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T02:08:29.843",
"Id": "51471",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"performance"
],
"Title": "Change example.jpg to example-color.jpg on hover"
} | 51471 |
<p>A script which scans a local filesystem and writes to a file a list of world-writable files found on the filesystem.</p>
<p>I ran it on a server with a couple terabytes of storage; not all of it used. In fact, only 195GB have been used. I'm not sure how many files there are, though.</p>
<p>The script takes 23 minu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T03:01:23.833",
"Id": "88927",
"Score": "0",
"body": "You might try rearranging the filters so that you determine if a file is interesting AFTER you determine if it is world-writable. Also, your test for basic directory will work imp... | [
{
"body": "<p>here are my suggestions:</p>\n\n<p>Your hash <code>%excludes</code> would use less memory, if you would set the value to <code>undef</code> instead of <code>1</code>.</p>\n\n<p>You could set <code>$File::Find::prune=1</code> in those cases where the whole directory is to be excluded. This shortcu... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T02:47:19.400",
"Id": "51473",
"Score": "1",
"Tags": [
"optimization",
"security",
"perl",
"file-system"
],
"Title": "Optimizing Perl script which looks for world-writable file... | 51473 |
<p>I have faced this question in an interview:</p>
<blockquote>
<p>If we enter a number it will convert into individual strings and display in same order.</p>
<p><strong>Ex:</strong> If I enter <code>564</code> then the output should be <code>FIVE SIX FOUR</code>.</p>
</blockquote>
<p>I have written the following worki... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-04-04T18:41:56.607",
"Id": "232659",
"Score": "0",
"body": "what about -1? how would you handle it?"
}
] | [
{
"body": "<p>This code:</p>\n\n<pre><code>int i,j;\nj=0;\nwhile(no>0){\n i = no%10;\n no /= 10;\n word[j] = words[i];\n j++;\n}\nfor(int k= word.length;k>0;k--)\n{\n System.out.println(word[k-1]+\" \");\n}\n</code></pre>\n\n<p>can be drastically simplified to:</p>\n\n<pre><code>String numb... | {
"AcceptedAnswerId": "51476",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T03:41:02.887",
"Id": "51475",
"Score": "15",
"Tags": [
"java",
"interview-questions",
"converting",
"numbers-to-words"
],
"Title": "Number to words in left to right directi... | 51475 |
<p>I have a <code>WPF</code> application (using <code>MVVM</code> pattern) that allows users to perform a search for a record/records based on their selection choices and entries into the different UI controls (<code>TextBox</code>, <code>CheckBox</code>, <code>RadioButton</code>, <code>DatePicker</code>, <code>TimerPi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T14:46:49.413",
"Id": "89035",
"Score": "0",
"body": "Seems like your method/database would be highly susceptible to SQL injection if you just concatenate SQL into it."
}
] | [
{
"body": "<p>My initial thought is that since view models are only (or should only be) concerned with presentation logic, it shouldn't know how to construct an SQL string. I would move the code which builds up the query into a separate <a href=\"http://lostechies.com/jimmybogard/2012/10/08/favor-query-objects-... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T04:09:09.770",
"Id": "51477",
"Score": "1",
"Tags": [
"c#",
"sql",
"ms-access"
],
"Title": "C# to Access SQL query based on UI controls"
} | 51477 |
<p>I just started a new project which reads in a video file and splits it up into frames. I started by just throwing everything in the GUI, but decided I wanted to make this a more well designed program, backed with unit tests. So I started to split out functionality into its own class and have a few questions on best ... | [] | [
{
"body": "<p>As a general statement, Python convention uses <code>underscores_in_names</code> instead of <code>camelCase</code>.</p>\n\n<h2>Class Structure</h2>\n\n<p>This implementation is really up to you. Without a little more detail on your program structure its hard to suggest how the classes should be ar... | {
"AcceptedAnswerId": "51538",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T05:10:04.823",
"Id": "51479",
"Score": "4",
"Tags": [
"python",
"unit-testing"
],
"Title": "File validation and unit testing"
} | 51479 |
<p>Just over half way through in K&R, came across an exercise to convert from postfix ("reverse-Polish") notation to infix (standard) notation. </p>
<p>Basically I'm posting here to see if there is anything excessive in my code, or any way to reduce the amount of storage it takes up. It runs extremely fast and doe... | [] | [
{
"body": "<p>Since you are using end-of-line commands, I will assume that you are using at least C99 in this review (it may be a compiler extension to C89 though).</p>\n\n<h1><code>main</code></h1>\n\n<p>There are too many things in your <code>main</code> function. It shouldn't handle the expression parsing, b... | {
"AcceptedAnswerId": "51488",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T06:12:52.533",
"Id": "51483",
"Score": "4",
"Tags": [
"algorithm",
"c",
"beginner",
"converting"
],
"Title": "Conversion from postfix to infix in C"
} | 51483 |
<p>I am working on a project in which I construct a URL with a valid hostname (but not a blocked hostname) and then execute that URL using <code>RestTemplate</code> from my main application thread. I also have a single background thread in my application which parses the data from the URL and extracts the block list of... | [] | [
{
"body": "<p>Even if in 1 line </p>\n\n<pre><code>public static void blockHost(String hostName) {\n blockedHosts.get().put(hostName, hostName);\n }\n</code></pre>\n\n<p>effectively consists of 2 operations, so if you want your methods to be atomic you still need synchronization. You could have an int... | {
"AcceptedAnswerId": "51784",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T06:15:04.450",
"Id": "51484",
"Score": "6",
"Tags": [
"java",
"performance",
"multithreading",
"rest",
"atomic"
],
"Title": "Executing a URL using RestTemplate"
} | 51484 |
<p><strong>Problem Statement</strong>:</p>
<blockquote>
<p><em>T<sub>1</sub></em>, <em>T<sub>2</sub></em> to <em>T<sub>n</sub></em> threads prints numbers up to <em>N</em> such that each threads
prints number in circular sequential fashion. <em>T<sub>1</sub></em> prints 1, <em>T<sub>2</sub></em> prints
2, <em>T<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T10:48:17.163",
"Id": "88962",
"Score": "0",
"body": "actually you could have moved the `index.incrementAndGet()` to before the print statement"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T11:26:33.... | [
{
"body": "<p>the first issue I see is that <code>i++;</code> is not thread safe. Instead use an AtomicInteger</p>\n\n<p>second is that the thread gets into a spin lock when it is awake and it's not its turn. the solution to this is to do:</p>\n\n<pre><code>while(!Thread.currentThread().getName().equalsIgnoreCa... | {
"AcceptedAnswerId": "51493",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T06:53:48.150",
"Id": "51486",
"Score": "4",
"Tags": [
"java",
"multithreading"
],
"Title": "Sequential Thread Execution using wait() and notifyAll()"
} | 51486 |
<p>I have designed a generic method to convert list of array of Objects to result into single map. This is working fine, but I want to check weather a key object is valid key (whether it is overriding equals and hashcode method or immutable instance). Am I missing anything else in my code?</p>
<pre><code>/**
@parms
o... | [] | [
{
"body": "<p>There is not much \"generic\" here, the code is as type safe as with raw types. Further, <code>throws Exception</code> usually isn't a good idea. Last but not least, method arguments should be written lower-case.</p>\n\n<p>Here my attempt (off the top of my head, couldn't test it):</p>\n\n<pre><co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T06:55:02.707",
"Id": "51487",
"Score": "2",
"Tags": [
"java",
"generics",
"collections",
"hibernate",
"hash-map"
],
"Title": "Generic util method to convert in single map ... | 51487 |
<p>I have an input with numbers 1, 2, 3, 4 and I want to change the order of this number dynamically according to users input. You can find my code below and also a running example <a href="http://jsfiddle.net/mEwrd/3/" rel="nofollow">here</a>.</p>
<p><strong>HTML</strong></p>
<pre><code><input type="text" name="n... | [] | [
{
"body": "<p>Interesting question,</p>\n\n<p>I cant understand why you would need this functionality. It does not seem to sort at all, but in same cases it will remove dupes.</p>\n\n<p>This code is so bad, you should first use the built in tools in JsFiddle and then come back.</p>\n\n<p><img src=\"https://i.st... | {
"AcceptedAnswerId": "51549",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T08:17:26.170",
"Id": "51490",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"beginner",
"sorting"
],
"Title": "Method for sorting numbers from user input"
} | 51490 |
<p>I have the following code. I was wondering if anyone can give me any pointers on how to make this more concise and neater? Should I be splitting this down into smaller functions?</p>
<pre><code> private void ReturnValue()
{
//create our WebService object
var sample = new TestProjectService... | [] | [
{
"body": "<p>I would basically write a method wherever you've written a comment on what a block of code does. This allows you to hide the specifics of a particular operation and makes it clearer which code paths are taken and what they do at a high level:</p>\n\n<pre><code>private Service1 GetService()\n{\n ... | {
"AcceptedAnswerId": "51494",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T09:10:29.940",
"Id": "51492",
"Score": "4",
"Tags": [
"c#",
"asp.net",
"layout"
],
"Title": "Should I split code into smaller functions? Advice on layout"
} | 51492 |
<p>In my real life example I am at a layout stage and before I actually move any further I would like to review my current approach. I am still learning about UI, XAML on WPF technology and I guess I haven't gotten my head around all the possible approaches yet.</p>
<p>I have built this very simple SSCCE to better dem... | [] | [
{
"body": "<h2>WPF readability</h2>\n\n<p>To keep your xaml looking clean, I reccommend using self closing tags</p>\n\n<pre><code><RowDefinition />\n</code></pre>\n\n<p>vs</p>\n\n<pre><code><RowDefinition></RowDefinition>\n</code></pre>\n\n<hr>\n\n<p>Explicitly set properties instead of using ... | {
"AcceptedAnswerId": "51506",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T11:45:31.397",
"Id": "51499",
"Score": "6",
"Tags": [
"xml",
"wpf",
"xaml",
"layout"
],
"Title": "Alternative to a Grid in a StackPanel form for an easier way of inserting ... | 51499 |
<p>The more I consider object oriented JavaScript the more I am confused. There are so many different ways and concepts and I simply do not know any longer what fits best for my purposes.</p>
<p>I like the constructor pattern but I have the feeling that I've mixed different concepts:</p>
<pre><code>Subclass.prototype... | [] | [
{
"body": "<p>These are the general rules I follow:</p>\n\n<ol>\n<li><p>If using actual private variables in my class, create get/set properties for those I want accessible to the outside world:</p>\n\n<pre><code>function Point(x, y) {\n var _x = x || 0,\n _y = y || 0,\n _foo = \"bar\";\n\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T11:53:26.373",
"Id": "51500",
"Score": "4",
"Tags": [
"javascript",
"beginner"
],
"Title": "Simple JavaScript (sub) class [properties, getters, methods]"
} | 51500 |
<h2>Situation</h2>
<p>I've written a simple black and white image filter application with JavaScript using html5 canvas. I have take two approaches, one with websockets and the other normally, the code is hosted on <a href="https://github.com/argentum47/JustBnW/" rel="nofollow noreferrer">github</a> </p>
<p>On my des... | [] | [
{
"body": "<p>Interesting question, I wish you had posted more code.</p>\n\n<p>Some observations:</p>\n\n<ul>\n<li><p>Do not use <code>parseInt</code>, use the unary plus so instead of <code>i = parseInt(s)</code> do <code>i = +s;</code> This does not help with readability, but it does help with speed</p></li>\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T11:55:49.997",
"Id": "51501",
"Score": "5",
"Tags": [
"javascript",
"algorithm",
"image"
],
"Title": "Image Processing codes running too slow"
} | 51501 |
<p>This is taken from my post at Stack Overflow <a href="https://stackoverflow.com/questions/23827684/android-background-web-service-issue?noredirect=1#comment36662501_23827684">here</a>.</p>
<p>I need your help to review my code for improvement and best practice.</p>
<pre><code> private void logSessionToServer() {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T14:03:46.910",
"Id": "89014",
"Score": "2",
"body": "To make life easier for reviewers, please add sufficient context to your question. The more you tell us about what your code does and what the purpose of doing that is, the easier... | [
{
"body": "<p>Have descriptive, intuitive variable names. (Example: what is <code>etUsername</code>? No clue.)</p>\n\n<p>You have a <code>List</code> of a <code>NameValuePair</code>. It looks like the your custom <code>NameValuePair</code> class is much like a key-value pair in a <code>Map</code>. I think i... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T12:08:03.413",
"Id": "51503",
"Score": "5",
"Tags": [
"java",
"beginner",
"multithreading",
"android"
],
"Title": "Multiple background tasks"
} | 51503 |
<p>Little backstory: I'm trying to write code that will read messages from <code>INetworkConnection</code> that the <code>INetworkConnection</code> publishes and then send those up to the <code>NetworkController</code> which should do some processing and then send that off to an injected <code>IObserver<IMessage>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T15:44:35.180",
"Id": "89068",
"Score": "0",
"body": "Is `_networkConnectionStreamSubscription` used at all?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T15:50:27.623",
"Id": "89072",
"Score... | [
{
"body": "<p>I don't think your approach is fundamentally wrong: Rx is all about exposing and responding to streams of data. I do wonder though if any of this is necessary; doesn't the <a href=\"http://msdn.microsoft.com/en-us/library/hh244306%28v=vs.103%29.aspx\" rel=\"nofollow\">Observable.Select</a> method ... | {
"AcceptedAnswerId": "67020",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T12:19:21.237",
"Id": "51504",
"Score": "4",
"Tags": [
"c#",
"system.reactive"
],
"Title": "Is this an ugly/incorrect usage of subscriptions?"
} | 51504 |
<p>I was wondering if it is the proper way to always put the return statement of a function with a <code>try-catch</code> clause in the <code>finally</code> clause.</p>
<p>I have for example this function which returns the version of an sql server:</p>
<pre><code>public String getVersion() {
String version = ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T13:52:34.387",
"Id": "89007",
"Score": "0",
"body": "In the 'getVersion()' method, are you sure you want the return-value to be \"\" when there is a connection error?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | [
{
"body": "<p>Return statement in the finally block is almost always a very bad idea.....</p>\n\n<p>The sematics of the finally block are complicated, but, if there is a return statement the <code>try</code> block, or in a <code>catch</code> block, then those will be called, and then the finally block will run,... | {
"AcceptedAnswerId": "51517",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T12:43:33.917",
"Id": "51509",
"Score": "15",
"Tags": [
"java",
"exception-handling",
"exception",
"null"
],
"Title": "Using finally with return statement or not"
} | 51509 |
<p>I just wrote the session class below. I humbly request for a review on how to make this even more secured/ how sessions are normally written. The code below works, but I would love to make it even more secure and robust.</p>
<pre><code><?php
session_start();
require_once('classes/function.php');
require_once('... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T15:07:01.867",
"Id": "89059",
"Score": "2",
"body": "Don't change the Question to match the answers. when the code is done being reviewed post a follow up question with all the changes"
}
] | [
{
"body": "<p>First thing to do is use proper indentation for your class.</p>\n\n<hr>\n\n<p>Remove indentation on the code after your second if statement in your <code>login</code> function.</p>\n\n<hr>\n\n<p>you probably don't need to start the session in the <code>logout</code> function</p>\n\n<blockquote>\n<... | {
"AcceptedAnswerId": "51814",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T12:45:37.450",
"Id": "51510",
"Score": "9",
"Tags": [
"php",
"security",
"session"
],
"Title": "Making a simple session class more secured"
} | 51510 |
<p>I've got a jQuery/JavaScript script for a menu that uses icons as well as label text. When the icon or text is clicked, it turns blue, until such time as another icon is clicked.
Also, the page scrolls down to the relevant div on the page, but the menu bar still stays fixed along the top of the screen.</p>
<p>I've... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-12T23:42:57.723",
"Id": "94294",
"Score": "0",
"body": "Did any of the answers have the data you were looking for?"
}
] | [
{
"body": "<p>I am happy you posted your best script, you can still see a ton of repetition here.. If you were to always name the navbutton after the scroll target and title ( <code>\"aboutnav\"</code> -> <code>about</code> & <code>abouttitle</code> ) then this can be much shorter. For now I can only see <c... | {
"AcceptedAnswerId": "51524",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T12:59:24.603",
"Id": "51511",
"Score": "5",
"Tags": [
"javascript",
"jquery"
],
"Title": "Menu script efficiency"
} | 51511 |
<p>I am trying to make the fastest <code>#to_struct</code> method in Ruby's Hash.</p>
<p>I am including a use case and benchmark so you can run and see if you have really improved the code.</p>
<p>This is my implementation and the benchmark is included. The time at the bottom is the time it takes on my machine. How c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T22:44:01.890",
"Id": "89245",
"Score": "0",
"body": "The benchmark is testing the time it takes to run #to_struct together with the time it takes to access the structure's attributes. Is that correct?"
},
{
"ContentLicense"... | [
{
"body": "<h1>Use OpenHash and Ruby >= 2.3.0</h1>\n\n<p>Starting with MRI 2.3.0, your benchmark using OpenHash gets fast. Very fast:</p>\n\n<pre><code>ruby-2.2.5: ruby 2.2.5p319 (2016-04-26 revision 54774) [x86_64-linux]\n user system total real\n#to_struct 1.780000 0.000000 1.78000... | {
"AcceptedAnswerId": "169000",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T06:57:49.450",
"Id": "51513",
"Score": "10",
"Tags": [
"performance",
"ruby"
],
"Title": "Hacking Ruby Hash: Fastest #to_struct method"
} | 51513 |
<p>I have a navigation bar that when the list elements are clicked their respective body container appears and the other body containers disappear. </p>
<p>navigation</p>
<pre><code><ul>
<li><a id="home" href="#"><img src="img/home-icon.png" alt="Home">HOME</a></li>
<li&... | [] | [
{
"body": "<p>You could put one event on all the anchor tags and determine which one is clicked inside the function then show the container.</p>\n\n<pre><code>$(document).ready(function(){\n $('#nav li a').click(function(){\n event.preventDefault();\n $(\"#aboutBodyContainer\").hide();\n ... | {
"AcceptedAnswerId": "51522",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T13:12:00.597",
"Id": "51514",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "jQuery click handlers to show one of four containers"
} | 51514 |
<p>I'm really tired of having to type</p>
<pre><code>for (int iSomething = rangeBegin; iSomething < rangeEnd; ++iSomething)
{
...
}
</code></pre>
<p>whenever I want to iterate over an integer range (most IDEs help with the typing, but still it looks so verbose, naming the integer 3 times!)</p>
<p>I wanted some... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T14:27:57.687",
"Id": "89027",
"Score": "2",
"body": "Take a look at my implementation at [klmr/cpp11-range](https://github.com/klmr/cpp11-range). Needless to say, I think my implementation has a few good ideas which set it apart fro... | [
{
"body": "<p>If you have <code>operator!=</code>, you should also have <code>operator==</code> for symmetry:</p>\n\n<pre><code>bool operator==(LoopRangeIterator const& other) const\n{\n return value == other.value;\n}\n</code></pre>\n\n<p>In addition, it's more common to overload <code>operator!=</code>... | {
"AcceptedAnswerId": "52217",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T13:52:10.560",
"Id": "51523",
"Score": "51",
"Tags": [
"c++",
"c++11"
],
"Title": "Simple integer range for C++11 range-based for loops"
} | 51523 |
<p>I have many sets of 2 strings. I'm trying to determine the number of matching elements in these 2 strings. The rules are if the strings share a common letter, that's a point, order does matter, but each letter in the first string can only match one of the letters in the second string. So in the strings <code>'aaaab'... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T14:37:15.613",
"Id": "89032",
"Score": "0",
"body": "Your code does not work"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T14:49:13.600",
"Id": "89039",
"Score": "0",
"body": "I think yo... | [
{
"body": "<p>Not quite an answer but too big for a comment and it seems important to let you know that your examples do not work - at least not on my config.</p>\n\n<p>Here's what I have (string1, string2, actual result, expected result)</p>\n\n<pre><code>aaabb bbaaa\n5 5\naabbb bbbaa\n5 4\naaabb aabbb\n4 4\na... | {
"AcceptedAnswerId": "51546",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T13:54:17.133",
"Id": "51525",
"Score": "5",
"Tags": [
"python",
"optimization",
"performance",
"python-2.x"
],
"Title": "Number Of Matching Elements In Two Lists"
} | 51525 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.