Skip to content

Instantly share code, notes, and snippets.

View corbanbrook's full-sized avatar

Corban Brook corbanbrook

  • Horizon Blockchain Games
  • Toronto, Canada
  • X @corban
View GitHub Profile
@corbanbrook
corbanbrook / spell_correct.py
Created October 26, 2009 18:06
Spell Correct by Peter Norvig
# Didn't realize this but Brian Adkins wrote a ruby version as well, code is almost identical to my own.
def words text
text.downcase.scan(/[a-z]+/)
end
def train features
model = Hash.new(1)
features.each {|f| model[f] += 1 }
return model
@corbanbrook
corbanbrook / metaclass_eval.rb
Created October 27, 2009 19:28
Metaclass Eval
@variables = Object.new
def @variables.metaclass
class << self; self; end
end
def @variables.meta_eval &block
metaclass.instance_eval &block
end
@corbanbrook
corbanbrook / list_comprehension-1d.rb
Created October 27, 2009 21:00
1 dimensional list comprehension
# 1 dimensional list comprehension
module Kernel
def list &block
Comprehension::List.new &block
end
end
module Comprehension
class List
@corbanbrook
corbanbrook / list_comprehension-Nd.rb
Created October 28, 2009 00:14
N-Dimensional list comprehension
# N-Dimensional list comprehension
module Kernel
def list &block
Comprehension::List.new &block
end
end
module Comprehension
class List
@corbanbrook
corbanbrook / list_comprehension-eval.rb
Created October 28, 2009 17:20
Better list comprehension in ruby
# better list comprehension by Corban Brook
module Kernel
def list &block; Comprehension::List.new &block; end
end
module Comprehension
Dimension = Struct.new(:for, :in, :if)
class Context; end
var path = "";
var activeSubworkers = 0;
if ( typeof(options.workerpath) == 'string' || options.workerpath instanceof String ) {
path = options.workerpath;
}
var worker = new Worker(path + "metaworker.js");
worker.onmessage = function(event) {
# is a discrete fourier transform in ruby by corban http://en.wikipedia.org/wiki/Discrete_Fourier_transform
require 'complex'
TWO_PI = 2 * Math::PI
N = ARGV.first.to_i || 256
x = Array.new(N, rand)
X = Array.new(N, 0)
zetagun:~ corban$ ruby DFT.rb 200 square 1720Hz
user system total real
DFT: 0.050000 0.000000 0.050000 ( 0.055424)
[DFT] 1720Hz squarewave / 44100.0Hz samplerate / 200 sample timesize
. - 0.6
.
. - 0.5
.
. - 0.4
zetagun:~ corban$ ruby FFT.rb 128 square 1720Hz
user system total real
FFT: 0.020000 0.000000 0.020000 ( 0.022661)
64
[FFT] 1720Hz squarewave / 44100.0Hz samplerate / 128 sample timesize
. - 41.9
.
. - 33.5
.
<html>
<head>
<script language="javascript" src="processing.min.js"></script>
<script language="javascript" src="init.js"></script>
</head>
<body>
<script type="application/processing" target="demo">
// Global variables
float radius = 50.0;