Skip to content

Instantly share code, notes, and snippets.

class Dot
class Node
attr_reader :children, :name, :started
attr_accessor :finished
def initialize name, fields = [], started = Time.now
@name = name
@fields = fields
@children = []
@started = started
diff --git a/lib/middleware/visitor.rb b/lib/middleware/visitor.rb
new file mode 100644
index 0000000..fdfb96d
--- /dev/null
+++ b/lib/middleware/visitor.rb
@@ -0,0 +1,100 @@
+module Middleware
+ class Visitor
+ class Node < Struct.new(:id, :name)
+ end
@benolee
benolee / ugh.rb
Created April 25, 2013 01:30 — forked from tenderlove/ugh.rb
####
# It must output this:
#
# hello one two
# world one two
#
class Filter
def initialize name
@name = name
end
def future # :block:
thread = Thread.new do
Thread.current.abort_on_exception = false
yield
end
lambda { thread.value }
end
def compose(proc) # :block:
@benolee
benolee / fbr.rb
Created April 23, 2013 02:34 — forked from tmm1/fbr.rb
# Poor Man's Fiber (API compatible Thread based Fiber implementation for Ruby 1.8)
# (c) 2008 Aman Gupta (tmm1)
unless defined? Fiber
require 'thread'
class FiberError < StandardError; end
class Fiber
def initialize

N.B. to run his examples in emacs, you'll want these aliases:

(defalias 'plus #'+)
(defalias 'quotient #'/)
(defalias 'times #'*)
(defalias 'difference #'-)

Lisp: Atoms and Lists

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

Ruby 2.0.0 in detail

Keyword arguments

def wrap(string, before: "<", after: ">")
  "#{before}#{string}#{after}" # no need to retrieve options from a hash
end

# optional
.DS_Store
tmp/
#!/usr/bin/env PeanutButterJellyTime
# -----------------------------------------------------------------------------
# keyword => C equiv (description)
# -----------------------------------------------------------------------------
# peanut => ++*ptr (increase value of cell)
# PEANUT => ++ptr (move to next cell)
# butter => --*ptr (decrease value of cell)
# BUTTER => --ptr (move to previous cell)
# jelly => putchar(*ptr) (print character value of cell)
# JELLY => *ptr=getchar() (store numeric value of char input in cell)