This file contains hidden or 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
# If you like f'ing around with people using your code, you can do | |
def stupid(arg, newval, b) | |
lvars = eval("local_variables",b) | |
relevant = lvars.find { |lvar| eval(lvar, b).equal?(arg) } | |
Thread.current[:stupid] = newval | |
relevant.each do |lvar| eval("#{lvar} = Thread.current[:stupid]", b) end | |
end | |
a = 1 | |
stupid(a, 2, binding) |
This file contains hidden or 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
Last Run States: | |
================ | |
* run | |
* success | |
* aborted | |
* manually (? better term ?) | |
* skip | |
* skip-tagged | |
* component missing (:use => foo, foo was not found) |
This file contains hidden or 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 | |
# usage: | |
# require 'irb_drop' | |
# ...do some stuff... | |
# irb_drop(binding) # irb will open here with the current local variables | |
# ...continue doing stuff... | |
def irb_drop(context=nil, *argv) | |
require 'irb' | |
require 'pp' | |
require 'yaml' |
This file contains hidden or 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 String | |
Base32Alphabet ||= ('A'..'Z').to_a+%w[2 3 4 5 6 7] | |
def base32 | |
binary = unpack("B*").first | |
binary << "0"*(5-(binary.length % 5)) | |
decoded = binary.scan(/.{1,5}/).map { |r| Base32Alphabet[r.to_i(2)] }.join('') | |
decoded << "="*(8-(binary.length.div(5) % 8)) | |
decoded | |
end | |
end |
This file contains hidden or 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
## reversesortby.rb | |
class ReverseSortBy | |
include Comparable | |
attr_reader :value | |
def initialize(value) | |
@value = value | |
end | |
def <=>(other) |
This file contains hidden or 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
# form_for @model, :builder => FormBuilderExtension do |f| ... | |
module FormBuilderExtension | |
def new(*a) | |
builder = ActionView::Base.default_form_builder.new(*a) | |
builder.extend(self) | |
builder | |
end | |
end |
This file contains hidden or 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 'thread' | |
class Thread | |
# Example: | |
# pool = Thread::Pool.new(10) do |exception| handle(exception) end | |
# pool.execute(1,2,3) do |x,y,z| whatever(x,y,z) end | |
# pool.join | |
class Pool |
This file contains hidden or 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
unless YAML.respond_to?(:dump_file) then | |
def YAML.dump_file(path, content) | |
File.open(File.expand_path(path), 'wb') do |fh| | |
fh.write(content.to_yaml) | |
end | |
end | |
class Object | |
def to_y(path=nil) | |
path ? YAML.dump_file(path, self) : to_yaml |
This file contains hidden or 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 | |
# Terminate the current process - the hard way | |
def t! | |
`kill -9 #{$$}` | |
end | |
module_function :t! | |
end | |
This file contains hidden or 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
(1..Bigger).first(5) # => [1, 2, 3, 4, 5] |