This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Kernel | |
alias :_require :require | |
def require(feature) | |
_require feature | |
rescue LoadError | |
f = open(feature) rescue open(feature+'.rb') | |
eval f.read.gsub(/\be(n{2,})d\b/) { 'end;'*$1.size } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fib plugin | |
Earthquake.init do | |
fibo = ->m,a=1,b=1 { Enumerator.new { |y| loop{ y << a; a,b = b,a+b } }.take m } | |
command :fib do |m| | |
puts "%d".c(rand(6).+31) % fibo[m[1].to_i].pop | |
end | |
command :fibs do |m| | |
fibs = fibo[m[1].to_i].map { |n| n.to_s.c(rand(6)+31) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
numbers = [13.4, 14.5, 15.0, 23.2, 30.9, 31.3, 32.9, 35.1, 34.3]; | |
drawing = (p) -> | |
p.setup = -> | |
p.size(500,500,p.P3D) | |
p.background(0) | |
p.draw = -> | |
p.background(0) | |
p.lights() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "em-http" | |
require "pp" | |
$stdout.sync = true | |
class KeyboardHandler < EM::Connection | |
include EM::Protocols::LineText2 | |
def post_init | |
print "> " | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def signature(word) | |
word.downcase.chars.sort.join.intern | |
end | |
def build_anagrams(words) | |
words.map { |word| [signature(word), word] } | |
.inject({}) { |h, (sign, word)| h[sign] ||= []; h[sign] << word; h } | |
.select { |sign, words| words.size > 1 } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "mathn" | |
class Integer | |
def ! | |
(1..self).inject(:*) | |
end | |
end | |
f1 = ->a,b,c{ a - b / c } | |
f2 = ->a,b,c{ (a - b) / c } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "word_dictionary" | |
texts = %w(alices_adventures_in_wonderland.txt | |
pride_and_prejudice.txt | |
the_adventures_of_sherlock_holmes.txt | |
frankenstein.txt | |
hamlet.txt | |
peter_pan.txt) | |
bases = %w(english_literature.txt analyze_people_on_sight.txt) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "graphaz" | |
require_relative "anagram" | |
mosts = Anagram.new.most(:size => 5, :sign => true) | |
ga = GraphAz.new("Anagram", :use => "neato") | |
ga.gnode[:shape] = "circle" | |
mosts.each do |sign, words| | |
words.each { |word| ga.add "#{sign} => #{word}" } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "RMagick" | |
include Magick | |
class Integer | |
def to_hex | |
self.to_s(16)[/^../] | |
end | |
end | |
class ImageUtil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Gun | |
class ChamberError < StandardError; end | |
attr_reader :chamber | |
def initialize | |
@chamber = [] | |
end | |
def set_cartridge | |
raise ChamberError, 'The chamber is full' unless @chamber.empty? |