Skip to content

Instantly share code, notes, and snippets.

# POST data
# ---------
api_key => ____,
class => "NameError", #*
message => "Unknown symbol",
env => {
HTTP_REFERER => '...',
HTTP_HOST => '...',
# etc. base64-encoded json
# What it does
# ------------
# With any typical Ohm model...
class Post < Ohm::Model
attribute :title
attribute :body
end
# you can have it's sets & lists have extra methods!
# Makes Sinatra support multiple view paths.
# Usage:
#
# class Main < Sinatra::Base
# register Sinatra::MultiView
#
# get '/' do
# locals = { :name => current_user.name }
#
# # Instead of `haml 'home', {}, locals`
# Can't wait for Sinatra 1.1 for SCSS support?
# Just `require` this in your bootstrapper, somewhere right
# after require 'sinatra/base' or something.
# More about SCSS in sass-lang.com.
# lib/tilt_scss.rb
module Tilt
class ScssTemplate < SassTemplate
private
@rstacruz
rstacruz / helpers.rb
Created October 19, 2010 23:28
cc_html.rb
# Implements the world-famous Paul Irish IE conditional comments HTML tag--in HAML.
# http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/
class Main
helpers do
def cc_html(options={}, &blk)
attrs = options.map { |(k, v)| " #{h k}='#{h v}'" }.join('')
[ "<!--[if lt IE 7 ]> <html#{attrs} class='ie6'> <![endif]-->",
"<!--[if IE 7 ]> <html#{attrs} class='ie7'> <![endif]-->",
"<!--[if IE 8 ]> <html#{attrs} class='ie8'> <![endif]-->",
# Usage example:
#
# Main.register Sinatra::UserAgentHelpers
#
# -# haml
# %body{class: browser.body_class}
#
# - if browser.ios?
# %script{:language => 'text/javascript', :src => '/js/jqtouch.js'}
# %p Download our mobile app in the iTunes store!

Deployer thing

Super cheapo Capistrano replacement. Inspired by github.com/cyx/tell.
This is more of a proof-of-concept than production-grade code... be sure you scrutinize it before you use it.

Contents:

  • deploy.yml (the config file)
  • deploy.rb (the deployer itself)

Google closure JavaScript minifier

Super cheapo (and super effective!) minification.

Usage:

In Ruby:

code = 'alert("hello there");'

Coffeeize

I've made a JS -> CoffeeScript compiler. Not releasing it yet (still a lot of things unsupported -- comments, for instance), but to prove that it works, here is Backbone.JS (http://documentcloud.github.com/backbone/) translated with this tool. ;)

GIT ChangeLOG tool - git clog

Makes pretty changelogs

Installation

chmod +x git-clog
cp git-clog /usr/local/bin  # Or whereever that's in your path

Usage