All Questions

Filter by
Sorted by
Tagged with
256 votes
14 answers
53k 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 ...
Jeff Atwood's user avatar
  • 3,655
222 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 ...
user26614's user avatar
  • 2,209
205 votes
5 answers
36k 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 ...
Overv's user avatar
  • 1,972
170 votes
15 answers
66k 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 ...
Jonas's user avatar
  • 1,827
156 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 ...
user avatar
151 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 ...
Aidenhjj's user avatar
  • 2,373
130 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 ...
Mathieu Guindon's user avatar
127 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. ...
J Atkin's user avatar
  • 1,800
125 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 ...
200_success's user avatar
120 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 ...
Dylan Black's user avatar
  • 1,461
118 votes
11 answers
53k 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 ...
Mark Ransom's user avatar
  • 1,876
110 votes
16 answers
243k views

Generate random numbers without repetitions

I want to generate a list of N different random numbers: ...
Kao's user avatar
  • 2,434
108 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 ...
Simon Forsberg's user avatar
100 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 ...
Jozin S Bazin's user avatar
98 votes
9 answers
33k 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: ...
janos's user avatar
  • 111k
98 votes
9 answers
182k views

Generating all combinations of an array

I'm generating all combinations of an array, so for instance, ["a", "b", "c", "d"] will generate: ...
Incognito's user avatar
  • 1,307
98 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. ...
Andrew Thompson's user avatar
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 ...
Simon Forsberg's user avatar
96 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 ...
user avatar
93 votes
7 answers
186k 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 ...
Pete's user avatar
  • 2,284
91 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: ...
kyrylomyr's user avatar
  • 995
89 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 ...
Vogel612's user avatar
  • 25.2k
86 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 ...
asteri's user avatar
  • 4,899
86 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 ...
Simon Forsberg's user avatar
85 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. ...
Eric Irwin's user avatar
85 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 ...
DavideChicco.it's user avatar
84 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: ...
noisy's user avatar
  • 1,001
81 votes
8 answers
227k 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 ...
user avatar
80 votes
6 answers
233k 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 ...
SummerCode's user avatar
80 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 ...
skiwi's user avatar
  • 10.6k
78 votes
16 answers
6k views

BOOL×BOOL→ENUM mapping

Does this part look clean enough? Any suggestions on how to make it cleaner? ...
vorou's user avatar
  • 989
78 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: ...
Mast's user avatar
  • 13.4k
75 votes
8 answers
15k 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 ...
dreamlax's user avatar
  • 1,128
74 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. ...
ohjuny's user avatar
  • 843
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 ...
Sir_Steadman's user avatar
73 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? ...
user avatar
72 votes
6 answers
4k 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 ...
Jerry Coffin's user avatar
  • 33.6k
71 votes
2 answers
96k 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 ...
DracoJem's user avatar
  • 811
71 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 ...
Sam Estep's user avatar
  • 1,767
69 votes
4 answers
57k 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 ...
Timo's user avatar
  • 797
69 votes
4 answers
59k 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 ...
zam6ak's user avatar
  • 801
67 votes
9 answers
29k views

Implementing a Singleton pattern in C#

Is this the best way to implement this pattern in C#? ...
Aim Kai's user avatar
  • 772
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 ...
Simon Forsberg's user avatar
66 votes
4 answers
227k 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: ...
Saike's user avatar
  • 833
66 votes
3 answers
109k 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 ...
Jeroen's user avatar
  • 1,441
63 votes
5 answers
285k 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): ...
lxcky's user avatar
  • 785
62 votes
10 answers
178k 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 ...
Philip Kirkbride's user avatar
62 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....
SuperBiasedMan's user avatar
62 votes
3 answers
52k views

Trait accessing variables of classes using it

I just tried PHP Traits for the first time, to keep my code DRY : ...
Marcel Burkhard's user avatar
62 votes
3 answers
4k views

Analyzing Minesweeper Probabilities

Calculating probabilities in Minesweeper might sound like an easy task, but I've seen so many probability calculators that's either incorrect, horribly slow, or with ugly code (or all of them) so I ...
Simon Forsberg's user avatar

15 30 50 per page
1
2 3 4 5
1556