Skip to content

Instantly share code, notes, and snippets.

View adamsanderson's full-sized avatar
Hi there!

Adam Sanderson adamsanderson

Hi there!
View GitHub Profile
# From PragDave:
require 'ripper'
# This class handles parser events, extracting
# comments and attaching them to class definitions
class BabyRDoc < Ripper::Filter
def initialize(*)
#!/usr/local/bin/ruby -ws
# Quick Hack to show which methods are not explicitly called within a class.
# This is only with regard to the class itself.
require 'pp'
begin require 'rubygems' rescue LoadError end
require 'parse_tree'
require 'sexp_processor'
require 'set'
require 'jruby'
import org.jruby.ast.Node
import org.jruby.ast.DefnNode
import org.jruby.ast.ClassNode
# Quick test of the JRuby AST, actually much easier to work with than
# ParseTree
code = <<-END
class Feline::Cat
name: "bus-schedule",
takes: {"route": noun_arb_text},
icon: "",
homepage: "",
author: {name: "Adam Sanderson", email: ""},
license: "MPL",
description: "Look up King County Metro bus route",
help: "Select a bus route",
adamsanderson / dot.rake
Created February 18, 2009 05:45
Quick and dirty dot file for ActiveRecord models
# Quick and dirty dot file for ActiveRecord models
namespace :dot do
task :load_models => :environment do
Dir.glob("#{RAILS_ROOT}/app/models/**/*rb").each{|p| require p}
desc 'Generates a dot file of the models'
task :models => :load_models do
models = Object.subclasses_of ActiveRecord::Base
#! /usr/bin/env jruby
include Java
import java.lang.System
import javax.swing.JFrame
import javax.swing.JLabel
import javax.swing.JTextField
import javax.swing.event.DocumentListener
import java.awt.GridLayout
adamsanderson / throw_catch_test.rb
Created May 17, 2009 23:35
This does not do what I expected at all.
# throw catch test
class Thingy
def loop
value = catch(:cake) do
(0..7).each do |i|
puts "Looking at #{i}"
throw(:cake, i) if i == 3
adamsanderson / object_space_filter.rb
Created May 27, 2009 16:59
little rails filter to track down object creation
around_filter do |controller, action|
delta ={|h,k| h[k] = 0}
ObjectSpace.each_object{|o| delta[o.class] -= 1}
ObjectSpace.each_object{|o| delta[o.class] += 1}
delta.sort_by{|cls, count| -count}[0...25].each do |cls, count|"%6d: %s\n" % [count,cls.to_s])
# Track down where requirements are coming from.
# ruby -r require_inspector.rb <file>
def require path
puts "require: (#{path}) #{caller[0]}"
def gem(*args)
puts "gem: #{args.inspect} #{caller[0]}"
# Be lazy and restart your node.js app when you change things.
# Screenshot:
# $ gem install watchr
# $ wget
# $ watchr node_runner.rb