View omnomnivore.rb
module Omnomnivore
def omnomname(name_extension)
define_method "name" do
@name + name_extension
end
end
end
##
# Usage:
View wait_for_odds.rb
require './dice_game'
class WaitForOdds
include DiceGame
def winner?
@rolls ||= []
if @rolls.size >= 3
@rolls[-3..-1].all?{|r| r % 2 == 1}
else
View wait_for_7.rb
require './dice_game'
class WaitFor7
include DiceGame
def winner?
last_roll == 7
end
end
View dice_game.rb
module DiceGame
def roll
die1 = rand(1..6)
die2 = rand(1..6)
@rolls ||= []
@rolls << die1+die2
end
def last_roll
View panda.rb
require './animal'
class Panda < Animal
def initialize
super(2)
puts "Panda#initialize"
end
def speak
View animal.rb
class Animal
attr_reader :legs
attr_accessor :name
def initialize(legs = 4)
@legs = legs
puts "Animal#initialize in #{__FILE__}"
end
def self.classname_from_filename
View github_light.user.js
/* Instructions
1. Open chrome://extensions
2. Drag this file into the chrome window
*/
// ==UserScript==
// @match https://*.github.com/*
// ==/UserScript==
function fixHeader() {
el = document.getElementsByClassName("header-dark")[0]
View caceable.rb
module Cacheable
def self.extended(base)
@@unaliased_methods = {}
@@cacheable_methods = Module.new
end
def method_added(m)
if @@unaliased_methods[m]
cache_method(m)
View meteor_galaxy_login.expect
#!/usr/bin/env expect
set timeout 5
spawn meteor login
expect "Username:" { send "$env(METEOR_USERNAME)\r" }
expect "Password:" { send "$env(METEOR_PASSWORD)\r" }
View wp_domain_count.rb
#!/usr/bin/env ruby
## Dependencies:
## * curl
## * jq (not really needed, but I like it)
## * sqlite
## * quit chrome before running this since the History file is locked
require 'uri'