Skip to content

Instantly share code, notes, and snippets.

View nakajima's full-sized avatar
💭
you can have statuses now?

Pat Nakajima nakajima

💭
you can have statuses now?
View GitHub Profile
@nakajima
nakajima / remote.rake
Created November 8, 2010 16:38
bad idea
require 'open-uri'
desc "Run a remote script from ENV['REMOTE_URL']"
task :remote => :environment do
instance_eval(open(ENV['REMOTE_URL']).read)
end
@nakajima
nakajima / campfire
Created November 1, 2010 22:36
Lets you post to campfire from the command line. It might already exist.
#!/usr/bin/env ruby
# Usage:
#
# $ campfire "Hello Everyone"
#
# You can also paste
#
# $ campfire -p "some code"
#
# You can also pipe into it
user.go_to_zoo_and_see_the_penguins_and_get_a_snack_but_get_home_before_seven_because_its_a_school_night_and_hey_awesome_mom_made_brownies_but_theyre_still_cooling_so_we_cant_eat_them_yet_so_lets_watch_some_tv_until_daddy_gets_home_oh_I_think_i_hear_him_and_oh_no_i_think_hes_been_drinking_and_mommy_saw_lipstick_on_his_collar_and_NO_dont_hit_mommy_I_want_to_go_to_my_room_but_I_also_want_brownies
@nakajima
nakajima / go-go-nakajima
Created June 23, 2010 15:54
Get a project going, nakajima-style
#!/usr/bin/env bash
echo "Installing key bindings"
mkdir -p "$HOME/Library/KeyBindings"
curl --silent "http://github.com/nakajima/dot-rot/raw/master/nakajima/DefaultKeyBinding.dict" > "$HOME/Library/KeyBindings/DefaultKeyBinding.dict"
echo "Installing TextMate bundles"
mkdir -p "$HOME/Library/Application Support/TextMate/Bundles"
function get_bundle() {
test -e "$HOME/Library/Application Support/TextMate/Bundles/$1.tmbundle" || git clone $2 "$HOME/Library/Application Support/TextMate/Bundles/$1.tmbundle"
<html>
<head>
<style type="text/css" media="screen">
li {
color: #aaa;
}
</style>
<script type="text/javascript" charset="utf-8">
(function() {
// Helpers
@nakajima
nakajima / example.rb
Created May 4, 2010 00:17
Making fixjour better
require 'fixjoury-girl'
# Why the new syntax ideas?
#
# * People get confused by `klass`
# * A lot of builders really don't need `overrides` processing
# * The case has been successfully argued that "scenario" builders, (that is, builders that come from other builders)
# are a good idea.
#
# SO without further ado:
class Class
def include_eval(&block)
include Module.new(&block)
end
end
if Rails.env.development?
module ActionView
module Partials
def render_partial_with_annotations(options = {})
if partial_path = options[:partial]
html = "\n<!-- START PARTIAL: \"#{partial_path}\" -->\n"
html += render_partial_without_annotations(options)
html += "\n<!-- END PARTIAL: \"#{partial_path}\" -->\n"
html
else
$ ruby -e 'exit'
$ echo $?
0
$ ruby -e 'exit 1'
$ echo $?
1
$ ruby -e 'abort "oh no"'
oh no
$ echo $?
1
@nakajima
nakajima / I choo choo choose you.js
Created March 5, 2010 21:22
Choose an option from a select by text
// Usage:
//
// $('#the-select').choose('Some Option');
//
// It'll throw an error if the option doesn't exist.
$.fn.choose = function(name) {
var elem = $(this);
if (elem.is(':not(select)')) { return elem; }
var option = elem.find('option').filter(function() {