Skip to content

Instantly share code, notes, and snippets.

@1995eaton
1995eaton / hash.cc
Created August 12, 2014 22:35
C++ Hash Table
#include <iostream>
#include <vector>
using std::vector;
using std::pair;
using std::string;
uint8_t pearsonDigits[] = {106, 15, 244, 74, 82, 236, 14, 57, 224, 61, 241, 204, 26, 54, 30, 12, 18, 214, 166, 87, 107, 253, 152, 111, 79, 7, 27, 70, 147, 56, 75, 170, 231, 230, 248, 92, 63, 157, 1, 239, 154, 185, 20, 249, 175, 177, 250, 84, 80, 127, 150, 234, 211, 139, 11, 125, 4, 229, 138, 117, 247, 155, 196, 101, 120, 173, 25, 93, 186, 180, 128, 72, 17, 76, 77, 198, 116, 8, 134, 151, 91, 86, 113, 254, 251, 33, 135, 67, 118, 215, 89, 183, 189, 213, 90, 94, 78, 5, 129, 55, 97, 233, 193, 45, 226, 232, 212, 217, 66, 37, 109, 227, 209, 143, 181, 100, 35, 162, 133, 69, 58, 81, 195, 223, 132, 19, 240, 252, 71, 9, 190, 73, 148, 200, 153, 203, 110, 21, 163, 62, 222, 46, 38, 164, 50, 207, 103, 51, 192, 60, 96, 119, 41, 122, 136, 28, 165, 124, 242, 176, 114, 208, 156, 65, 184, 140, 39, 121, 174, 228, 34, 243, 182, 216, 188, 99, 115, 210, 172, 145, 225, 29, 142, 105, 83, 10, 42, 206, 235, 199, 85, 219, 160, 88, 168, 238, 141
@1995eaton
1995eaton / fizzbuzz.js
Created August 15, 2014 23:05
FizzBuzz Benchmarks
var FizzBuzz = {
'switch': function(N) {
var result = [];
for (var i = 1; i <= N; i++) {
switch (i % 15) {
case 0:
result.push('FizzBuzz');
break;
case 3:
@1995eaton
1995eaton / bf.cc
Created August 19, 2014 23:08
Brainfuck interpreter in C++
#include <iostream>
#include <cstring>
#include <fstream>
#define MAX_LINE 2048
#define DATA_ALLOC 30000
using namespace std;
void fuck(char *start, char *end) {
@1995eaton
1995eaton / png.c
Created August 23, 2014 04:42
A simple wrapper for libpng
/* gcc -O2 -Werror -I/usr/include/libpng16 -lpng png.c -o png */
#include <stdio.h>
#include <stdlib.h>
#include <png.h>
typedef struct PNG {
int width;
int height;
int depth;
@1995eaton
1995eaton / trie.c
Created August 27, 2014 03:59
C Trie
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct Node {
struct Node *children;
size_t child_count;
char value;
} Node;
@1995eaton
1995eaton / array.c
Last active November 18, 2015 13:09
Dynamic arrays in C
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define ARRAY_STRING
#if defined ARRAY_STRING
#define ARRAY_PRINT "s"
typedef char* array_t;
#else
@1995eaton
1995eaton / reddit.css
Created September 10, 2014 23:20
Subreddit Code CSS
.usertext-body pre {
margin: 10px 0;
color: #f8f8f2 !important
}
.usertext-body pre, .usertext-body p > code {
background: #f7f7f7;
border: 1px solid #ccc;
-moz-border-radius: 0;
-webkit-border-radius: 0;
@1995eaton
1995eaton / isprime.cc
Created September 12, 2014 03:39
Is prime
#include <iostream>
#include <cmath>
template<typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
bool is_prime(T n) {
if (n < 2) {
return false;
}
for (T i = 2, sq = sqrt(n) + 1; i != sq; i++) {
if (n % i == 0) {
@1995eaton
1995eaton / range.cc
Created September 12, 2014 10:59
Range Iterator C++
#include <iostream>
#include <stdexcept>
struct RangeIterator {
int64_t i, s = 1;
const RangeIterator &operator++() {
i += s;
return *this;
}
const bool operator!=(const RangeIterator &it) {
@1995eaton
1995eaton / snake.html
Created September 16, 2014 18:00
Classic snake game in JavaScript + HTML5 Canvas
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="author" content="">
<style>
#canvas {
border: 1px solid;