Skip to content

Instantly share code, notes, and snippets.

@defunkt
defunkt / ruby.sh
Created May 19, 2010 17:53
My Ruby Setup
# directory structure of /ruby
$ tree -L 1 /ruby
/ruby
|-- default -> ree-1.8.7
|-- ree-1.8.7
`-- ruby-1.9.1-p376
3 directories, 0 files
@defunkt
defunkt / sep.rb
Created May 18, 2010 01:19
Section separators in mustache.rb
require 'mustache'
require 'yaml'
class Sep < Mustache
def last?
self[:to_s] == self[:names].last.to_s
end
end
template = <<template
@defunkt
defunkt / rip-readme
Created May 5, 2010 06:02
rip-readme PACKAGE - Print a package's README
#!/usr/bin/env ruby
# Usage: rip-readme package
#
# Prints the contents of the installed package's README.
require 'rip/script'
target = ARGV[0]
rip(:installed).each do |package_path|
package_path = package_path.chomp
@defunkt
defunkt / stack.sh
Created May 4, 2010 05:43
Stacking ripenvs
$ rip-env -c resque
$ rip-install resque
installed redis (1.0.7)
installed redis-namespace (0.4.2)
installed sinatra (0.9.2)
installed vegas (0.1.2)
installed resque (1.8.2)
$ rake
-bash: rake: command not found
$ rip-list
@defunkt
defunkt / rip-rg
Created April 30, 2010 06:58
Drops a rubygems.rb into the current ripenv
#!/bin/sh -e
# Usage: rip-rg
# Drops a rubygems.rb into the current ripenv
touch "$RIPDIR/$(rip-env)/lib/rubygems.rb"
@defunkt
defunkt / rip-gemfile
Created April 30, 2010 02:09
Gemfile => deps.rip
#!/usr/bin/env ruby
# Usage: rip-gemfile Gemfile
#
# Given a Gemfile, prints content that can be used as a deps.rip
# to standard out.
#
# If you want to work with Gemfile.lock check out josh's rip-bundle:
# http://github.com/josh/rip-bundle
module Gemfile
@defunkt
defunkt / rip-dependency-tree
Created April 29, 2010 20:05
rip-dependency-tree(1)
#!/usr/bin/env ruby
# Usage: rip-dependency-tree deps.rip
require 'rip'
packages = Rip::Parser.parse(ARGF.read, ARGF.path)
puts ARGF.filename
def print_package(package, last=false, prefix='')
print prefix
@defunkt
defunkt / question_section.diff
Created April 29, 2010 15:59
Adding {{? question_sections}} to mustache.rb {{/ question_sections}}
diff --git a/lib/mustache/generator.rb b/lib/mustache/generator.rb
index 5e8c067..8943903 100644
--- a/lib/mustache/generator.rb
+++ b/lib/mustache/generator.rb
@@ -128,6 +128,17 @@ class Mustache
compiled
end
+ def on_question_section(name, content)
+ code = compile(content)
@defunkt
defunkt / mm.rb
Created April 29, 2010 15:42
Mustache Existential Operator
require 'mustache'
module ExistentialMethodMissing
def method_missing(method, *args)
return super unless method.to_s =~ /\?$/
val = send(method.to_s.chomp('?'))
val.respond_to?(:empty?) ? !val.empty? : !!val
end
def respond_to?(method)
@defunkt
defunkt / my_view.rb
Created April 27, 2010 22:26
Mustache Markdown Helper
class MyView < Mustache
def markdown(str = nil)
if str
Markdown.new(str.to_s).to_html
else
lambda { |text| markdown(render(text)) }
end
end
end