Skip to content

Instantly share code, notes, and snippets.

View jasonLaster's full-sized avatar

Jason Laster jasonLaster

View GitHub Profile
@jasonLaster
jasonLaster / dd.py
Created July 3, 2012 16:35
Dynamic Dispatch in Python
class FlexiDict(dict, DDispatch):
def get_gt(self, key):
return [v for k,v in d.iteritems() if k > key]
def __getattr__(self, name):
if name.startswith("find_"):
params = name.split("_")
if len(params) == 3:
def func():

hello

example 1

html
  head
  body
@jasonLaster
jasonLaster / gist:3171027
Created July 24, 2012 16:28
pry-debugger 1.9.2 segfault
➜ pry-debugger git:(master) ✗ bundle exec ruby examples/example_basic.rb
/Users/quintessentialbum/src/_projects/debugger/lib/ruby_debug.bundle: warning: already initialized constant VERSION
From: examples/example_basic.rb @ line 2 :
1: require 'pry'
=> 2: binding.pry
3:
4: a = 2
5: b = 3
@jasonLaster
jasonLaster / tree.md
Created July 28, 2012 19:10
Pry Initialization tree

how are plugins initialized

  • bin/pry
    • require "pry"
      • load helpers
      • require classes
        • require pry_class
          • adds pry method to Pry
          • calls Pry.init
            • initializes plugin_manger,
  • initializes config
@jasonLaster
jasonLaster / tree.md
Created July 28, 2012 19:10
Pry Initialization tree

how are plugins initialized

  • bin/pry
    • require "pry"
      • load helpers
      • require classes
        • require pry_class
          • adds pry method to Pry
          • calls Pry.init
            • initializes plugin_manger,
  • initializes config
@jasonLaster
jasonLaster / tree.md
Created July 28, 2012 19:11
Pry Initialization tree

how are plugins initialized

  • bin/pry
    • require "pry"
      • load helpers
      • require classes
        • require pry_class
          • adds pry method to Pry
          • calls Pry.init
            • initializes plugin_manger,
  • initializes config
@jasonLaster
jasonLaster / fizz.rb
Created July 30, 2012 16:04
fizz buzz
@i = 0
1.upto(100) {|i| @i = i}
on ->(frame) { frame.var("i") == 15 } do puts "fizz buzz" end
on ->(frame) { frame.var("i") == 3 } do puts "fizz" end
on ->(frame) { frame.var("i") == 5 } do puts "buzz" end
@jasonLaster
jasonLaster / func.rb
Created July 30, 2012 19:18
anonymous function fun
# why can a proc be passed to an instance_eval and not a lambda?
b = binding
b.instance_eval {@x = 5}
b.instance_eval &(proc {puts @x})
b.instance_eval &(lambda {puts @x})
@jasonLaster
jasonLaster / Fibers.md
Created July 30, 2012 22:01
Dave Thomas's Fibers post

Users of the command line are familiar with the idea of building pipelines: a chain of simple commands strung together to the output of one becomes the input of the next. Using pipelines and a basic set of primitives, shell users can accomplish some sophisticated tasks. Here's a basic Unix shell pipeline that reports the ten longest .tip files in the current directory, based on the number of lines in each file:

 wc -l *.tip | grep \.tip | sort -n | tail -10

Let's see how to add something similar to Ruby. By the end of this set of two articles, we'll be able to write things like

puts (even_numbers | tripler | incrementer | multiple_of_five ).resume and a palindrome finder using blocks:

```
debugger.rb:21
a
(rdb:1) s
debugger.rb:4
b
(rdb:1)
debugger.rb:8
c
(rdb:1)