Skip to content

Instantly share code, notes, and snippets.

@peterc
peterc / on_update.task.rb
Created May 17, 2009 23:55
Rake task to automatically run something (i.e. specs) when code files are changed
# Rake task to automatically run something (i.e. specs) when code files are changed
# By Peter Çoopér
#
# Motivation: I couldn't get autotest to run on my Sinatra project for some reason but realized
# it didn't require overengineering. Just detect when a file is changed and then re-run the specs!
#
# Examples:
# # rake on_update "rake"
# # rake on_update "spec spec/user_spec.rb"
#
require 'rubygems'
require 'nokogiri'
require 'activesupport'
class NokoHash
def self.from_s(str)
self.new(Nokogiri::XML(str))
end
def initialize(doc)
@mikiobraun
mikiobraun / autoreload.rb
Created January 15, 2010 15:14
autoreloading of ruby files which have changed in the meantime
# This file extends the Kernel's require function and adds the
# AutoReload module which allows to reload files once they have changed
# on the disk.
#
# Basically, you just require your files as usual, and if you want to update
# the files, either call AutoReload.reload(file) or AutoReload.reload_all.
#
# Usage:
# irb -rautoload
#
@agibralter
agibralter / jammit-mustache.js
Created April 19, 2010 22:22 — forked from documentcloud/jammit-mustache.js
Mustache.js templating function for Jammit.
// Add a Mustache.js templating function to your JavaScript:
Mustache.template = function(templateString) {
return function () {
if (arguments.length < 1) {
// With no arguments, return the raw template -- useful for rendering
// partials.
return templateString;
} else {
return Mustache.to_html(templateString, arguments[0], arguments[1]);
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
class Array
# Array.zipper: like Array#zip, but produces and full and even distributed
# array for 1,2, or N arrays. eg:
#
# a = %w( a b c d e f g h i )
# b = %w( 0 1 2 )
# c = %w( A B C D E F )
#
# zippered = Array.zipper(a, b, c)
@mnutt
mnutt / Instrument Anything in Rails 3.md
Created September 6, 2010 06:50
How to use Rails 3.0's new notification system to inject custom log events

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

@mattelacchiato
mattelacchiato / gist:578787
Created September 14, 2010 09:25
Move or copy complete lines in vim
"my own line movement kram
"Alt+Up, Alt+k moves line up
:nmap <A-Up> :m .-2<Enter>
:nmap <A-k> :m .-2<Enter>
:imap <A-Up> :m .-2<Enter>
:imap <A-k> :m .-2<Enter>
:vmap <A-Up> :m .-2<Enter>
:vmap <A-k> :m .-2<Enter>
"Alt+Down, Alt+j moves line down
@dchelimsky
dchelimsky / gist:590557
Created September 21, 2010 21:10 — forked from qrush/gist:590466
describe SomeClass do
freeze { 1.day.from_now }
it "does some stuff with time" do
end
end
# this actually does...
describe SomeClass do
around { |example| Timecop.freeze(1.day.from_now, &example) }
#
# Create a new repo on Github and directly push your initial commit with this shell script
#
url=https://github.com/api/v2/json/repos/create
username=$(git config github.user)
token=$(git config github.token)
name=${1-$(basename $(pwd))}
curl -F login=$username -F token=$token $url -F name=$name -F public=1 1>/dev/null