Skip to content

Instantly share code, notes, and snippets.

View aalin's full-sized avatar

Andrés Alin aalin

  • Colombia
View GitHub Profile
@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 / .irbrc
Created October 8, 2010 10:05
Show rails environment in the rails console
class IRB::Irb
alias :original_prompt :prompt
def prompt(prompt, ltype, indent, line_no)
prompt = prompt.call if prompt.respond_to?(:call)
original_prompt(prompt, ltype, indent, line_no)
end
end
IRB.conf[:PROMPT_MODE] = :RAILS_ENV
IRB.conf[:PROMPT][:RAILS_ENV] = IRB.conf[:PROMPT][:CLASSIC].merge(:PROMPT_I => lambda { (defined?(Rails) ? "#{Rails.env} " : "") + "%N(%m):%03n:%i> " })
@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]]]
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
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
require 'rubygems'
require 'glapp'
require 'text_draw'
class EyeTest
include GLApp
class Chooser
ALPHABET = ('A'..'Z').to_a + [' ']
# watch for new files in /tmp/
def clear
puts "\e[H\e[2J"
end
hostname = `hostname`.strip
loop do
clear
class String
COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white]
def colorize(color)
value = case color
when Symbol
COLORS.index(color) || 0
else
color
end
"\e[9#{ value }m#{ self }\e[0m"
class CharacterDrawer
CHARACTERS = {
'A' => [[ [0,0], [2,5], [4,0] ], [ [1,2], [3,2] ]],
'B' => [[ [0,0], [0,5], [2,5], [3,4], [2,3], [3,2], [3,1], [2,0], [0,0] ], [ [0,3], [2,3] ]],
'C' => [[ [4,1], [3,0], [1,0], [0,1], [0,4], [1,5], [3,5], [4,4] ]],
'D' => [[ [0,0], [0,5], [2,5], [3,4], [3,1], [2,0], [0,0] ]],
'E' => [[ [3,0], [0,0], [0,5], [3,5] ], [ [0,3], [2,3] ]],
'F' => [[ [0,0], [0,5], [3,5] ], [ [0,3], [2,3] ]],
'G' => [[ [2,2], [4,2], [4,1], [3,0], [1,0], [0,1], [0,4], [1,5], [3,5], [4,4] ]],
'H' => [[ [0,0], [0,5] ], [ [3,0], [3,5] ], [ [0,3], [3,3] ]],