Skip to content

Instantly share code, notes, and snippets.

# download and git methods swiped from http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
exit!
require 'rack'
# sudo gem install tilt --source http://gemcutter.org/
require 'tilt'
# A simple Rack middleware which makes it super easy
# have a shared layout rendering system used across
# different rails applications.
#
# Examples:
#
class NoWWW
STARTS_WITH_WWW = /^www\./i
def initialize(app)
@app = app
end
def call(env)
if env['HTTP_HOST'] =~ STARTS_WITH_WWW
!!!
%html
%head
%style(type="text/css")
:plain
body {
color: blue;
background: yellow;
}
%body
@bhauman
bhauman / minidress.rb
Created February 11, 2010 03:28 — forked from stephencelis/minidress.rb
Minidress a lightweight factory_girl which will work outside of Rails(I use it with jruby_appengine/Sinatra)
# the more proper miniskirt who doesn't have to walk the rails
class Minidress
@@factories = {}
class << self
def define(name, &block)
@@factories[name.to_s] = block
end
def build(name, attrs = {})
@bhauman
bhauman / hack.sh
Created March 31, 2012 19:50 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
# run with: god -c /path/to/config.god [add -D if you want to not-deamonize god]
# This is the actual config file used to keep the delayed_job running
APPLICATION_ROOT = "/var/www/application"
RAILS_ENV = "production"
God.watch do |w|
w.name = "delayed_job_production"
w.interval = 15.seconds
w.start = "/bin/bash -c 'cd #{APPLICATION_ROOT}/current; /usr/bin/env RAILS_ENV=#{RAILS_ENV} #{APPLICATION_ROOT}/current/script/delayed_job start > /tmp/delay_job.out'"
(defn partition-chan
([start-pred in] (partition-chan start-pred (complement start-pred) in))
([start-pred end-pred in]
(let [out (chan)]
(go
(loop []
(if-let [val (<! in)]
(if (start-pred val)
(let [next-chan (chan)]
(>! out next-chan)
(defn partition-chan
([start-pred in] (partition-chan start-pred (complement start-pred) in))
([start-pred end-pred in]
(let [out (chan)]
(go
(loop []
(if-let [val (<! in)]
(if (start-pred val)
(let [next-chan (chan)]
(>! out next-chan)
(require 'tubular.core)
(tubular.core/connect "127.0.0.1" REPL_PORT)