Skip to content

Instantly share code, notes, and snippets.

View aalin's full-sized avatar

Andreas Alin aalin

  • Peru
View GitHub Profile
# watch for new files in /tmp/
def clear
puts "\e[H\e[2J"
end
hostname = `hostname`.strip
loop do
clear
require 'rubygems'
require 'glapp'
require 'text_draw'
class EyeTest
include GLApp
class Chooser
ALPHABET = ('A'..'Z').to_a + [' ']
class Scale
IONIAN_HALF_STEPS = [2, 2, 1, 2, 2, 2, 1]
class << self
[
:ionian,
:dorian,
:phrygian,
:lydian,
:mixolydian,
def find_spec_helper(path)
spec_helper = File.join(path, 'spec_helper.rb')
if File.exists?(spec_helper)
spec_helper
elsif path == "/"
raise "No spec helper found"
else
find_spec_helper(File.dirname(path))
end
end
begin
raise LoadError.new('haxhax so we dont get wirble output in CruiseControl') if (ENV['USER'] == 'cruise' || ENV['USER'] == 'jenkins')
require 'wirble'
rescue LoadError
module Wirble
module Colorize
def self.colorize(str)
str
end
end
@aalin
aalin / figure_out_chord.rb
Created April 14, 2010 20:23
Figure out chord intervals
# Program output:
#
# Chord: [0, 4, 7]
# [:major, [[0, :unison], [4, :third], [7, :fifth]]]
# [:minor, [[0, :unison], [3, :third], [8, :sixth]]]
# [:major, [[0, :unison], [5, :fourth], [9, :sixth]]]
# Chord: [0, 4, 7, 11]
# [:major, [[0, :unison], [4, :third], [7, :fifth], [11, :seventh]]]
# [:minor, [[0, :unison], [3, :third], [7, :fifth], [8, :sixth]]]
# [:major, [[0, :unison], [4, :third], [5, :fourth], [9, :sixth]]]
@aalin
aalin / bellevue.rb
Created October 8, 2010 13:11
Prints the menu from restaurangbellevue.se
#!/usr/bin/env ruby
require 'iconv'
require 'open-uri'
class String
COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
def colorize(color)
value = case color
when Symbol
@aalin
aalin / runonupdate
Created October 18, 2010 09:50
Run a command when a file has been changed
#!/usr/bin/env ruby
# Usage:
# runonupdate "spec spec/models/cat_spec.rb -O spec/spec.opts" app/models/cat.rb app/models/dog.rb
#
# This will run cat-specs whenever cat.rb or dog.rb is updated.
class RunOnUpdate
attr_reader :cmd
attr_reader :files
@aalin
aalin / multibench.rb
Created October 26, 2010 09:52
multibench: useful for benchmarking columns in html tables for example.
class Multibench
def initialize
@benches = Hash.new { 0 }
end
def bench(title)
start = Time.now
yield.tap do
@benches[title] += Time.now - start
end
@aalin
aalin / pivotalstatus.rb
Created June 22, 2011 13:06
Pivotal tracker git status thing...
#!/usr/bin/env ruby
require 'rubygems'
require 'pivotal-tracker'
class String
ANSI_COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
def colorize(color)
num = ANSI_COLORS.index(color) or raise("Bad color #{ color }")
"\e[3#{ num }m" + self + "\e[0m"