Skip to content

Instantly share code, notes, and snippets.

View kyrylo's full-sized avatar

Kyrylo Silin kyrylo

View GitHub Profile
class Pry
module DefaultCommands
Cd = Pry::CommandSet.new do
create_command "cd" do
group "Context"
description "Move into a new context (object or scope)."
banner <<-BANNER
Usage: cd [OPTIONS] [--help]
# otherwise just pops a binding and stores it as old binding
_pry_.old_binding[:binding] = _pry_.binding_stack.pop
_pry_.old_binding[:append] = true
% pry
[1] pry(main)> cd :foo
# Save 'main' as old_binding; append == false (the next call of `cd -` should not append old_binding to binding_stack)
[2] pry(:foo):1> cd -
# Pull out ':foo' and save it as old_binding; append == true (the next call of `cd -` should append old_binding to binding_stack)
[3] pry(main)> cd -
# All over again...
@kyrylo
kyrylo / gist:2945907
Created June 17, 2012 22:23
xterm256/hex table
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org" />
it 'should keep correct old stack' do
#1
redirect_pry_io(InputTester.new("cd @", "cd -", @cs, "exit-all")) do
Pry.start(@o)
end
Pad.cs.old_stack.should == nil
#2
redirect_pry_io(InputTester.new("cd :mon_dogg", "cd @", @cs, "exit-all")) do
# Ruby
?===?=??===?=:?===?=??===?=:?===?=??===?=:?===?=.iloveyoufowl!? ?===?=:?===?=??===?=:?===?=??===?=:?===?=
@kyrylo
kyrylo / gist:4053280
Created November 11, 2012 01:23
Count digits in an integer number
# (1)
# Meh.
num = 6969
num.to_s.length #=> 4
# (2)
# Hm...
num = 6969
len = 0
( ͡° ͜ʖ ͡°)
@kyrylo
kyrylo / gist:4247435
Created December 9, 2012 23:08
precedence
eval "100 + 1\n (42 + 100)" #=> 142
eval "100 + 1\n + (42 + 100)" #=> 142
# But...
eval "100 +\n (42 + 100)" #=> 242
eval "100 +\n + (42 + 100)" #=> 242
# ...
@kyrylo
kyrylo / gist:4254201
Created December 10, 2012 23:07
Empty or not empty
if [].each do |elem|
puts "NOT EMPTY!"
end.empty?
puts "EMPTY!"
end
#EMPTY!
#=> nil
if [:piglet].each do |elem|
puts "NOT EMPTY!"