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
# | |
# An Array-like class that's used for a very specific purpose: the `out[]` array | |
# in Pry. MRU stands for most-recently-used.) | |
# | |
# It acts like an array with a maximum size -- if you try to add more elements than | |
# the maximum, the elements at the beginning of the array are discarded. | |
# | |
# Also, it keeps track of which entries are most recently accessed, and throws | |
# out only the oldest entries. | |
# |
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
Pry.plugin("something") do | |
command "amazing" do | |
... | |
end.help do | |
short "blah" | |
long "A long description." | |
end | |
command /more-amazing!*/ do |
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 original idea was to use set operations to help dealing with a method's "options" hash. | |
# | |
# However, since I can't override || and &&, I wasn't able to figure out reasonable semantics. | |
# | |
# Therefore, I implemented `with_defaults`, which is what you want most of the time, and then | |
# wrote some thoughts about how set operations might work. | |
# | |
class Hash |
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 'epitools' | |
class State | |
attr_accessor :fore, :back, :attrs | |
COLORS = [:black, :red, :green, :yellow, :blue, :magenta, :cyan, :white] | |
ATTRS = { | |
0 => :reset, |
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 'epitools' | |
require 'redcarpet' | |
require 'coderay' | |
def indented?(text) | |
indent_sizes = text.lines.map{ |line| if line =~ /^(\s+)/ then $1 else '' end }.map(&:size) | |
indent_sizes.all? {|dent| dent > 0 } | |
end | |
def unwrap(text) |
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
Pry.commands.command(/^wtf([?!]*)/, "show backtrace") do |arg| | |
raise Pry::CommandError, "No most-recent exception" unless _pry_.last_exception | |
output.puts _pry_.last_exception | |
output.puts _pry_.last_exception.backtrace.first([arg.size, 0.5].max * 10) | |
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
Pry.commands.command "ri", "RI it up!" do |*names| | |
# lazy loading | |
require 'rdoc/ri/driver' | |
unless RDoc::RI::Driver.responds_to? :monkeypatched? | |
class RDoc::RI::Driver | |
def page | |
lesspipe {|less| yield less} | |
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
echo -n "with: " | |
time ruby -I. -rfast-require -e 'require "epitools"' | |
echo -n "without: " | |
time ruby -e 'require "epitools"' |
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 'spork' | |
Spork.prefork do | |
require 'rspec' | |
require 'pry' | |
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration | |
RSpec.configure do |config| | |
config.treat_symbols_as_metadata_keys_with_true_values = true | |
config.run_all_when_everything_filtered = 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
<%= easy_table(items, :class=>"table-style1", :tbody_id=>@table_id) do | |
col("Name") {|o| o.drug_price.name} | |
col("Qty", :quantity) | |
col("Price") {|o| number_to_currency(o.price) } | |
col("Actions") do |o| | |
link_to image_tag('small/delete.png'), | |
:action => "return_package_item", | |
:package_item => o.id, |