Skip to content

Instantly share code, notes, and snippets.

@seaneshbaugh
seaneshbaugh / multikey_hash.rb
Created April 14, 2014 20:01
multikey_hash.rb
class MultikeyHash
include Enumerable
def initialize(initial_values = nil)
@outer_hash = {}
@inner_hash = {}
@next_inner_key = 1
@seaneshbaugh
seaneshbaugh / terrain.rb
Created May 29, 2014 19:29
Noisy terrain tile generator
require 'rmagick'
class Color
attr_accessor :red, :green, :blue
def initialize(red, green, blue)
@red = red
@green = green
@seaneshbaugh
seaneshbaugh / hammingDistance.hs
Created June 20, 2014 03:01
Haskell Hamming Distance
import Data.Bits
numberOfSetBits :: Int -> Int
numberOfSetBits x
| x == 0 = 0
| otherwise = 1 + (numberOfSetBits (x .&. (x - 1)))
hammingDistance :: [Char] -> [Char] -> Int
hammingDistance a b
| (length a) == (length b) = sum (map (\ (x, y) -> numberOfSetBits (xor (ord x) (ord y))) (zip a b))
@seaneshbaugh
seaneshbaugh / mega.rb
Created June 30, 2014 03:33
Zip and upload to Mega
# encoding: utf-8
require 'zip'
require 'rmega'
require 'clipboard'
email_address = ''
password = ''
@seaneshbaugh
seaneshbaugh / graphicsprogrammingresources.txt
Created July 3, 2014 07:29
Resources for learning graphics programming
Saving this for later. Because I'm too lazy to visit them all now and bookmark the good ones.
http://en.wikipedia.org/wiki/List_of_3D_graphics_libraries
>Tutorials
ClanLib
http://www.clanlib.org/examples.html
SDL
http://lazyfoo.net/SDL_tutorials/
http://www.programmersranch.com/p/sdl2-tutorials.html
Allegro (4?)
# http://programmingpraxis.com/2012/10/12/birthday-paradox/
trials = 10000
1..64.times do |number_of_people|
matches = 0
trials.times do
people = Array.new(number_of_people) { rand(365) }
@seaneshbaugh
seaneshbaugh / directory_compare.rb
Last active August 29, 2015 14:03
Compare the contents of two directories.
require 'digest'
if ARGV.length != 2
puts 'Error: expected two directories to compare.'
exit 1
end
directory_a = ARGV[0]
@seaneshbaugh
seaneshbaugh / scrolling-title.js
Created December 11, 2014 14:47
Scrolling Title
var text;
text = "This is a very long title. ";
setInterval(function() {
var letters;
letters = text.split("");
letters = letters.concat([letters.shift()]);
@seaneshbaugh
seaneshbaugh / fibonacci.exs
Last active August 29, 2015 14:16
turing-complete-notes.txt
defmodule Fibonacci do
def fibonacci_numbers(n) do
fibonacci_numbers(n, [1, 0]) |> Enum.reverse
end
defp fibonacci_numbers(n, [h | t]) do
[a | _] = t
if length([h | t]) < n do
fibonacci_numbers(n, Enum.concat([a + h], [h | t]))
@seaneshbaugh
seaneshbaugh / dead_letter_exchange_test.rb
Created March 8, 2015 04:50
Bunny dead letter exchange test
require 'bunny'
number_of_messages = 10
queue_name = 'contact'
connection = Bunny.new
connection.start