Skip to content

Instantly share code, notes, and snippets.

View chadbrewbaker's full-sized avatar

Chad Brewbaker chadbrewbaker

View GitHub Profile
@chadbrewbaker
chadbrewbaker / avoidence.rb
Created March 17, 2014 18:57
avoidence.rb Transformation pattern avoidence
counting_numbers = Enumerator.new do |yielder|
(0..1.0/0).each do |number| yielder.yield number
end
end
def nilstuff(a,stuff="")
if(a.nil?)
return stuff
else
return a
@chadbrewbaker
chadbrewbaker / fibgen.rb
Created April 16, 2014 03:08
Wrapping an enumerator with a function to pass in parameters
def fibs(base)
fib = Enumerator.new do |y|
a = b = base
loop do
y.yield a
a, b = b, a + b
end
end
fib
end
@chadbrewbaker
chadbrewbaker / tweetstream.rb
Created April 21, 2014 00:39
Twitter stream stats
require 'twitter'
require 'uri'
require 'emoji_data'
smile_emoji = "😄"
def nilstuff(a,stuff="")
if(a.nil?)
return stuff
else
@chadbrewbaker
chadbrewbaker / lasers.rb
Last active August 29, 2015 14:01
Laser maze problem
#Chad Brewbaker May 10, 2014
#Laser maze problem
def get_coords(s)
return s.gsub(/[vVlLrR]/, ' ').strip.split(',').map {|i| i.to_i}.dup
end
get_coords("1,7V") != [1,7] ? abort("ERROR in get_coords") : nil
def laser_paths(line = "")
if(line =~ /RL/)
@chadbrewbaker
chadbrewbaker / life.hs
Created November 17, 2014 05:31
gdocr14 Haskell Life
import Test.QuickCheck
import Data.List
type Height = Integer
type Width = Integer
type Cell = (Height, Width)
type LiveCells = [Cell]
type World = (LiveCells, Height, Width)
type AliveNeighborCount = Integer
type AmIAlive = Bool
@chadbrewbaker
chadbrewbaker / zdist.rb
Created January 6, 2015 02:07
Computes information distance between two files
require "zlib"
if(ARGV.length != 2)
puts "usage: ruby zdist.rb file1 file2"
else
f1 = File.read(ARGV[0])
f2 = File.read(ARGV[1])
f1d = Zlib::Deflate.deflate(f1)
f2d = Zlib::Deflate.deflate(f2)
compressed = Zlib::Deflate.deflate(f1+f2)
@chadbrewbaker
chadbrewbaker / micrioKnap.c
Created March 8, 2015 19:42
Example of a simple brute force solver
#include <stdio.h>
typedef unsigned long long int llu;
llu BUDGET = 542;
const int ITEMS = 11;
llu PRICES[ITEMS] = {100, 100, 400, 23, 64, 39, 18, 39, 29, 39, 28};
#define CHECK_BIT(var, pos) ((var) & (1 << (pos)))
void printItems(llu mask) {
@chadbrewbaker
chadbrewbaker / keylaout.rb
Created May 7, 2015 11:44
Fits law evolutionary algorithm for keyboard layout
def mutation
end
def crossover
end
@chadbrewbaker
chadbrewbaker / zSeven.hs
Created May 14, 2015 00:22
First iteration of endoscope, MVP on Z_7(*)
monogenic :: Int -> Int -> (Int -> Int -> Int) -> [Int]
monogenic size seed mult = take size $ iterate f seed
where
f = mult seed
endoscope :: Int -> (Int -> Int -> Int) -> Graph
endoscope size mult = buildG (0,size) $ concat [ g i | i <- [0..size]]
where
g blar = zip (replicate size blar) (f blar)