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
(define (is-awesome? name)
(if (eq? name 'github)
#t
#f))
(is-awesome? 'pastie) ; => #f
(is-awesome? 'github) ; => #t
@nakajima
nakajima / a-better-try.rb
Created July 22, 2008 15:26
A version of Object#try that allows arguments and a block
class Object
def try(method, *args, &block)
respond_to?(method) ? send(method, *args, &block) : nil
end
end
@nakajima
nakajima / gist:1084
Created July 22, 2008 15:32
Curry args on a proc. Probably buggy.
class Proc
def curry(*arguments)
if arguments.empty?
return self
else
_proc = self.dup
return lambda do |*args|
return _proc.call(*arguments.concat(args))
end
end
module WithScopes
def with_scopes(*named_scopes)
named_scopes.inject(self) { |klass, scope| klass.send(scope) }
end
end
ActiveRecord::Base.extend(WithScopes)
// Module to contain logic for fixing characters.
var FigureFixer = {
Map: { }, // Holds character/code pairs
// Adds a character/code pairing, where the "code"
// is the escaped string and the "character" is the
// character that should replace it.
add: function(code, character) {
FigureFixer.Map[code] = character;
},
@nakajima
nakajima / gist:3401
Created July 31, 2008 04:20
Ain't Aintablog
%w(rubygems dm-core sinatra erb).each { |lib| require lib }
# Easier on the eyes
class String
def erb_eval(b)
ERB.new(self).result(b)
end
end
# Blogs need posts
%w(rubygems sinatra).each { |lib| require lib }
get '/' do
"Fellow World!"
end
@nakajima
nakajima / gist:3625
Created August 1, 2008 14:11
AE Expressions test
// Namespace for Bounce effects
var Bounce = {
squashStretch: function(options) {
var settings = {
maxDev: 13, // max deviation in pixels
speed: 30, // speed of oscillation
decay: 1.0 // how fast it slows down
}
options = options || { }
@nakajima
nakajima / gist:4180
Created August 6, 2008 06:21
Deploy from a gist.
# Use this Capfile to deploy a gist via Capistrano.
#
# If the gist you want to deploy is here: http://gist.github.com/3401,
# just fill in the appropriate server settings (domain, deploy_to, etc)
# and run the following command:
#
# cap deploy GIST=3401
#
# You might need to run cap deploy:setup first.
require 'rubygems'
require 'johnson'
require 'spec'
RUNTIME = Johnson::Runtime.new
RUNTIME.evaluate <<-JS
var Person = function(name) {
this.name = name;
this.foods = [];
}