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
Node(1) | |
Node(2) | |
Node(3) | |
Node(4) | |
Node(5) | |
Node(6) | |
Node(7) | |
Node(8) |
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 Object | |
def self.enumerable *meths | |
meths.each do |meth| | |
alias_method "#{meth}_without_enumerator", meth | |
class_eval %{ | |
def #{meth}(*args, &block) | |
return Enumerable::Enumerator.new(self, #{meth.inspect}, *args, &block) unless block_given? | |
#{meth}_without_enumerator(*args, &block) | |
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
s = "1100100001100001110111101110110011111010010000100101011110010110" | |
def rle(s) | |
s.gsub(/(0{3,9}|1{3,9})/) { "#{$1.size}#{$1.chars.first}" } | |
end | |
def rld(s) | |
s.gsub(/([3-9])([01])/) { $2 * $1.to_i } | |
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
[02:04 PM] epi@fizz :: ~/code/pry $ ./go | |
(in /home/epi/code/pry) | |
NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed on or after 2011-10-01. | |
Gem::Specification#has_rdoc= called from /home/epi/code/pry/Rakefile:26 | |
. | |
NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed on or after 2011-10-01. | |
Gem::Specification#has_rdoc= called from /home/epi/code/pry/Rakefile:26 | |
. | |
NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed on or after 2011-10-01. | |
Gem::Specification#has_rdoc= called from /home/epi/code/pry/Rakefile:26 |
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
command "require", "Require gem(s)" do |*gems| | |
gems = gems.join(' ').gsub(',', '').split(/\s+/) | |
gems.each do |gem| | |
begin | |
if require gem | |
output.puts "#{gem.yellow} loaded" | |
else | |
output.puts "#{gem.white} already loaded" | |
end | |
rescue LoadError => e |
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
command "gems", "List/search installed gems. (Optional parameter: a regexp to limit the search)" do |arg| | |
gems = Gem.source_index.gems.values.group_by(&:name) | |
if arg | |
query = Regexp.new(arg, Regexp::IGNORECASE) | |
gems = gems.select { |gemname, specs| gemname =~ query } | |
end | |
gems.each do |gemname, specs| | |
versions = specs.map(&:version).sort.reverse.map(&:to_s) | |
versions = [bright_green(versions.first)] + |
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
# | |
# The result is an anonymous module (named "name") that can be mixed into the | |
# Commands class. | |
# | |
Pry.plugin "name" do | |
## Settings | |
settings do | |
bool :make_awesome, :default => true |
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
# | |
# Creates a new CommandSet and automatically mixes it into Pry::Commands. | |
# | |
Pry.plugin :test do | |
settings do | |
bool :make_awesome, :default => true | |
enum :goat_type, :default => "plain", :options => %w[ plain mountain billy ] | |
string :favorite_goat, :default => "Super Dave the Goat", :validate => proc { goat[/super/i] } | |
int :expire_goats, :default => 5.minutes |
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
def req(mod) | |
puts " |_ #{mod}" | |
require mod | |
yield if block_given? | |
rescue Exception => e | |
p e | |
end | |
## Fancy Require w/ Modules |
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 'curses' | |
def init_screen | |
Curses.noecho # do not show typed keys | |
Curses.init_screen | |
Curses.start_color | |
Curses.stdscr.keypad(true) # enable arrow keys | |
Curses.curs_set(0) | |
Curses.ESCDELAY = 0 |