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:
# http://pragdave.blogs.pragprog.com/pragdave/2008/04/babydoc.html
require 'ripper'
# This class handles parser events, extracting
# comments and attaching them to class definitions
class BabyRDoc < Ripper::Filter
def initialize(*)
super
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
#!/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'
CmdUtils.CreateCommand({
name: "bus-schedule",
takes: {"route": noun_arb_text},
icon: "http://transit.metrokc.gov/favicon.ico",
homepage: "http://endofline.wordpress.com",
author: {name: "Adam Sanderson", email: "netghost@gmail.com"},
license: "MPL",
description: "Look up King County Metro bus route",
help: "Select a bus route",
@adamsanderson
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}
end
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
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
end
end
@adamsanderson
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 = Hash.new{|h,k| h[k] = 0}
ObjectSpace.each_object{|o| delta[o.class] -= 1}
action.call
GC.start
ObjectSpace.each_object{|o| delta[o.class] += 1}
delta.sort_by{|cls, count| -count}[0...25].each do |cls, count|
logger.info("%6d: %s\n" % [count,cls.to_s])
end
true
# Track down where requirements are coming from.
# ruby -r require_inspector.rb <file>
def require path
puts "require: (#{path}) #{caller[0]}"
super
end
def gem(*args)
puts "gem: #{args.inspect} #{caller[0]}"
##
# Be lazy and restart your node.js app when you change things.
# Screenshot: http://img.skitch.com/20100606-mbi52g6knk3n83b6m3eqxr4pa4.png
# INSTALL:
# $ gem install watchr
# $ wget http://gist.github.com/raw/427720/2aae1f3b43a256f5ca07a603025d455aa92560e1/node_run
# $ cd YOUR_NODE_APP
# $ watchr node_runner.rb
#
# NOTES: