All Questions
77,248
questions
254
votes
14
answers
51k
views
Calculating entropy of a string
We're calculating entropy of a string a few places in Stack Overflow as a signifier of low quality.
I whipped up this simple method which counts unique characters in a string, but it is quite ...
221
votes
4
answers
24k
views
Calculate SHA1 hash from binary and verify with a provided hash
I applied for a job and they asked me to write code with the following requirements:
Get a "toolbar offer" description from
http..update.utorrent.com/installoffer.php?offer=conduit. Parse the
...
204
votes
5
answers
35k
views
Dijkstra path finding in C# is 15x slower than C++ version
I'm implementing Dijkstra's algorithm with a priority queue for a game I'm developing in Unity with C#. I was a bit disappointed with the performance, so I decided to port the code to C++ and see if ...
169
votes
15
answers
65k
views
Remove Last Comma
I want to join strings together, but when doing this it often happens that there is a comma too many, and therefore I need to remove that comma. In this code, I use the ...
155
votes
20
answers
32k
views
Searching an element in a sorted array
I was applying for a position, and they asked me to complete a coding problem for them. I did so and submitted it, but I later found out I was rejected from the position. Anyways, I have an eclectic ...
150
votes
17
answers
19k
views
Disproving Euler proposition by brute force in C
I wrote a little bit of code to brute force disprove the Euler proposition that states:
$$a^4 + b^4 + c^4 = d^4$$
has no solution when \$a\$, \$b\$, \$c\$, \$d\$ are positive integers.
I'm no ...
129
votes
3
answers
13k
views
Down with FizzBuzz... LOL
This post is the result of reading through and following the LOLCODE Specification 1.2 ("smoking the manual", right?), and writing and executing my code on compileonline.com.
My "hello world" was ...
126
votes
6
answers
17k
views
How clean is my snow?
I just wrote a snow animation in Python. I think this is fairly clean but I have a few things that I don't like.
...
124
votes
4
answers
24k
views
Celebratory fireworks animation
To celebrate an important event, I hastily cobbled together an HTML canvas-based animation.
A few concerns I have include:
Performance: Does it run reasonably smoothly on most modern machines? How ...
117
votes
5
answers
30k
views
Basic Pokedex in C++
I recently started learning C++ about a week ago, and I made a bit of progress. In honor of Pokemon Go releasing, I decided to make a Pokedex with the original 151 Pokemon. So far I have 120 or so of ...
117
votes
11
answers
51k
views
Fastest way to clamp an integer to the range 0-255
I'm working on some image processing code that can generate pixel values outside of the normal range of 0 to 255, and I'd like to clamp them back into the valid range. I know that there are saturating ...
109
votes
16
answers
240k
views
Generate random numbers without repetitions
I want to generate a list of N different random numbers:
...
107
votes
2
answers
14k
views
FizzBuzz in Brainfuck
Inspired a bit by a previous Brainfuck question and the recent fizzbuzz invasion, I decided to make FizzBuzz in Brainfuck.
The code is entirely my own, except for the inclusion of the Printing a ...
99
votes
16
answers
9k
views
Outputting the names of cars, without repetitions, with the number of occurrences in order of decreasing repetitions
A short while ago, I have submitted a coding exercise to a
potential employer. The response came back the next
morning and you can guess what it was from the subject
of this post.
I am not ...
99
votes
9
answers
32k
views
'100' is a magic number
Magic numbers are bad... I totally agree. But there's one magic number I find hard to fix:
'100' is a magic number.
Consider this code:
...
97
votes
9
answers
179k
views
Generating all combinations of an array
I'm generating all combinations of an array, so for instance, ["a", "b", "c", "d"] will generate:
...
97
votes
6
answers
66k
views
File Browser GUI
FileBro is a basic GUI based File Browser.
FileBro Functionality
Directory tree - shows the file system roots at start-up, but is otherwise built lazily as the user browses around the file system. ...
97
votes
3
answers
6k
views
Shielding your CodeReview on GitHub
In response to a feature-request on meta, I spent a few hours today creating the feature in php.
This application adds a review shield to your GitHub repository (or wherever else you want it).
It ...
95
votes
5
answers
19k
views
Load fifty million integers as quickly as possible in Java
I am working my way through Project Euler. Many of the problems deal with prime number calculations: this is the type of code that can be extracted into a separate class and reused.
While calculating ...
92
votes
7
answers
185k
views
Convert object array to hash map using lodash
The use case is to convert an array of objects into a hash map where one property is the key and the other property is the value. Common case of using this is converting a "link" object in a ...
90
votes
9
answers
9k
views
Mutually exclusive properties
The question is probably quite simple, but I would like to hear what drawbacks we will have with our code.
So, we had a simple implementation and interface for it:
...
88
votes
6
answers
7k
views
You hate h̶a̶t̶s̶ reputation? Click here to get rid of it
Soo... I recently read a meta-post about the inherent problems of reputation. It listed some things like:
Confirmation bias.
Demotivating for low-rep users.
Hubris and elitism of high-rep users over ...
85
votes
11
answers
12k
views
Nesting versus GOTO: which is better to avoid?
In Java they're not really known as GOTO statements and are rather referred to as Branching Statements, but I find that the former term is a bit more indicative of ...
85
votes
5
answers
25k
views
SudokuSharp Solver with advanced features
Even though it's the first time I'm writing something this "big", it feels like I know C# quite well (it is very similar to Java after all). It's been nice to learn LINQ also and I am very impressed ...
84
votes
5
answers
8k
views
Guessing a number, but comments concerning
I always get marked down for my comments and I just wanted to see if these comments are acceptable or what I should include/where I should include them.
...
84
votes
1
answer
4k
views
Siamese neural network
I have been studying the architecture of the Siamese neural network introduced by Yann LeCun and his colleagues in 1994 for the recognition of signatures ("Signature verification using a Siamese ...
83
votes
4
answers
22k
views
Function to print command-line usage for a program [closed]
The following function works well to print out a help message for the program I have written. It prints a multi-line string message that describes the command line usage with some examples:
...
79
votes
6
answers
231k
views
Design a chess game using object-oriented principles
I would like to know if my approach is correct and how could it could be improved? Also, is there a way to get rid of the relation between the Piece and the ...
79
votes
8
answers
226k
views
Getting/setting default values from my App.config
Imagine that I need a color palette for my Winforms application to have a consistent look.
What I did was create a static helper class and helper methods that I can call from anywhere in my code, and ...
79
votes
2
answers
10k
views
Brainfuck Interpreter written in x86 Assembly
Story time: A week ago I found a question about optimizing Assembly code, then I remembered how awesome Brainfuck was, and the match was made very quickly. I decided to write a Brainfuck Interpreter ...
77
votes
16
answers
5k
views
BOOL×BOOL→ENUM mapping
Does this part look clean enough? Any suggestions on how to make it cleaner?
...
76
votes
1
answer
6k
views
NUMAH LITTERS OV KITTEHS ON TEH NETZ
It's not fair that 1% of the users hold 75% of the lolcode questions. #OccupyMatsMug
~ user2296177
I agree. Without further ado, here's the LOLCODE version of 99 bottles of beer on the wall:
...
74
votes
8
answers
14k
views
Open, write and close a file
I have a small 10-liner function that writes some data to a file using an std::ofstream. I did not explicitly call .close() at ...
73
votes
5
answers
11k
views
Send a tweet to ISP when internet speed drops
I have written an app in Python 3 which monitors internet speed and will send a tweet to an ISP when the speed drops too low. The app has a config file where the ISP and target speeds can be ...
73
votes
3
answers
20k
views
Monopoly simulator
I was advised by a Reddit user to get my code reviewed on this site.
The complete code is on GitHub.
...
72
votes
2
answers
5k
views
I HAZ A FIBO, RLY
First LOLCODE program, run here. This program inputs a Fibonacci number from the user, then determines and prints whether the number is in the Fibonacci series. What do you think?
...
71
votes
6
answers
3k
views
infix_iterator code
I've previously posted this on Stack Overflow, and am considering submitting it to Boost for wider distribution, but thought perhaps it would be best to put it up here for peer review first, and see ...
70
votes
2
answers
93k
views
Redirecting subprocesses' output (stdout and stderr) to the logging module
I'm working on a Python script and I was searching for a method to redirect stdout and stderr of a subprocess to the logging ...
70
votes
1
answer
2k
views
Printing binary trees
After writing this answer, I was inspired to try to design a more elegant solution to the problem of printing binary trees. And what better tool with which to seek elegance than Clojure?
Overall ...
68
votes
4
answers
56k
views
Flappy Bird game clone for a beginners' programming class
I'll soon begin teaching a beginners' programming class. It's voluntary, so I thought I'd make it interesting by teaching Python programming and then introduce the kids to Pygame, so that they can ...
68
votes
4
answers
58k
views
EF Code First with Repository, UnitOfWork and DbContextFactory
I am about to >explode< :) due to amount of reading on this subject...
My head hurts, and I need some honest opinions...
There is a similar question/review that I noticed, but I believe my approach ...
67
votes
9
answers
29k
views
Implementing a Singleton pattern in C#
Is this the best way to implement this pattern in C#?
...
67
votes
2
answers
3k
views
You are being watched! - Comments of Interest
You are being watched
Code Review has an open system
A machine that spies on you on every hour of every day
I know because I built it.
I designed the machine to detect suggestions to post on ...
66
votes
4
answers
225k
views
Grouping elements in array by multiple properties
During work, I was given this task: to group elements with similar properties in the array.
In general, the problem is as follows:
...
66
votes
3
answers
107k
views
Delete folder if it exists in PowerShell
In my PowerShell script I'm trying to delete a folder, but only if it exists:
if (Test-Path $folder) { Remove-Item $folder -Recurse; }
I find myself repeating ...
63
votes
5
answers
284k
views
Removing elements on a List while iterating through it
I needed a way to remove elements on a List while iterating through it.
Supposedly something like this (illegal code):
...
62
votes
10
answers
175k
views
Given an array of integers, return the smallest positive integer not in it
Write a function:
function solution(A);
that, given an array A of N integers, returns ...
62
votes
3
answers
51k
views
Trait accessing variables of classes using it
I just tried PHP Traits for the first time, to keep my code DRY :
...
61
votes
10
answers
4k
views
Using separate functions for Project Euler 1
I started programming with Java and C++, so I'm used to having a 'main' function that calls other functions that do the actual work. At university I was always told that doing actual computation in ...
61
votes
6
answers
5k
views
Accurate email syntax validation (no seriously)
So a friend happened to show me how odd and specific the general email syntax rules are. For instance, emails can have "comments". Basically you can put characters in parentheses that are just ignored....