Skip to content

Instantly share code, notes, and snippets.

View jvoorhis's full-sized avatar

Jeremy Voorhis jvoorhis

View GitHub Profile
#!/usr/bin/env ruby
require 'webrick'
require 'webrick/httpproxy'
callback = proc do |request, response|
if response.content_type =~ /jpe?g|png|gif/
f = Tempfile.new("upside-down")
f.write(response.body)
f.close
#!/usr/bin/env ruby
require 'webrick'
require 'webrick/httpproxy'
callback = proc do |request, response|
if response.content_type =~ /jpe?g|png|gif/
f = Tempfile.new("upside-down")
f.write response.body
f.close
2010 07 09 10:30
Galois Tech Talk: Requirements and Performance of Data Intensive, Irregular Applications
Iavor S. Diatchki
Pacific NW National Laboratory
Analytics
Security
Anomaly detection
# Bandlimited interpolation simulation, as described by Eq 1 of
# https://ccrma.stanford.edu/~jos/resample/Theory_Ideal_Bandlimited_Interpolation.html
Fs = 44100.0 # sampling rate
Ts = 2.26757369614512e-05 # sampling interval (1/Fs)
def interp(samps, t)
(0...samps.size).inject(0) { |sum, n|
sum + samps[n] * hs(t - n * Ts)
}
def times_for_period(date)
days = work_days_for_period(date)
regular_hours_by_week = Hash.new(0)
out = { :regular_hours => 0, :other_hours => Hash.new(0) }
days.inject(out) { |results, day|
times = day.times
{ :regular_hours => results[:regular_hours] + times[:regular_hours]
:other_hours => results[:other_hours].merge(times[:other_hours]) { |_,a,b| a+b }}
}.merge(:weekly_hours => regular_hours_by_week.values_at(*regular_hours_by_week.keys.sort))
end
class Additive
attr :value
def initialize(value)
@value = value
end
def mappend(m) Additive.new(@value + m.value) end
end
class Multiplicative
attr :value
class Val < Struct.new(:val)
def fold(rules)
rules[self.class].(val)
end
end
class Var < Struct.new(:lbl)
def fold(rules)
rules[self.class].(lbl)
end
require 'audio_toolbox'
include AudioToolbox
player = MusicPlayer.new
sequence = MusicSequence.new
player.sequence = sequence
sequence.midi_endpoint = CoreMIDI.get_destination(ARGV.shift.to_i)
tempo = sequence.tracks.tempo
tempo.add 0.0, ExtendedTempoEvent.new(:bpm => 120.0)
require 'audio_toolbox'
class DrumMachine
include AudioToolbox
def initialize
@player = MusicPlayer.new
@sequence = MusicSequence.new
@track = MusicTrack.new(@sequence)
@track.add 0.0, MIDIProgramChangeMessage.new(:channel => 10, :program => 26)
~ % sudo gem1.9 install ffi
Password:
Building native extensions. This could take a while...
ERROR: Error installing ffi:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby1.9 extconf.rb install ffi
checking for ffi_closure_alloc() in -lffi... no
creating Makefile
creating extconf.h