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 / 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 || { }
Running with tiny string
- only scanning then injecting: 0.0131118297576904 seconds
- scanning groups and injecting: 0.0120480060577393 seconds
- scanning then splat hashing: 0.0159380435943604 seconds
- splitting then splat hashing: 0.00326204299926758 seconds
Running with medium string
- only scanning then injecting: 0.13988208770752 seconds
- scanning groups and injecting: 0.12324595451355 seconds
- scanning then splat hashing: 0.242349147796631 seconds
@nakajima
nakajima / gist:28035
Created November 23, 2008 04:50 — forked from defunkt/gist:28024
"up and atom!"
require 'rubygems'
require 'nokogiri'
class Nokogiri::XML::Node
def method_missing name, *args, &block
if args.empty?
list = xpath("//#{name}")
elsif args.first.is_a? Hash
hash = args.first
if hash[:css]
@nakajima
nakajima / gist:69211
Created February 23, 2009 22:12 — forked from pauldix/gist:69188
HTTPMachine.service_access(:threads => 3) do |data|
data.pages << YahooBOSS.web_search("paul dix").get_pages
end
$.fn.transitionToNext = function() {
({
entry: function() {
// do whatever is needed to transition to entry
$(this).data('state.next', 'captcha');
return false;
},
captcha: function() {
$(this).removeClass('entry').addClass('captcha');
[*1..99].reverse.each do |i|
phrase = ["#{i} bottles of beer on the wall",
"#{i} bottles of beer",
"You take one down",
"You pass it around",
"#{i - 1} bottles of beer on the wall.."].join(".. ")
`say #{phrase}`
end
@nakajima
nakajima / gist:84466
Created March 25, 2009 00:47 — forked from jm/gist:84447
# not to be a dick, just for fun
res = %w(one two three one two one).inject(Hash.new(0)) do |counts, t|
counts[t] += 1
counts
end
p res
@nakajima
nakajima / format_accepts.rb
Created April 14, 2009 14:55 — forked from reinh/format_accepts.rb
Fork'd to follow
module Rack
#
# A Rack middleware for automatically removing the format token at the end
# of a request path and adding its media type to the HTTP_ACCEPT header.
#
# MIT-License - Rein Henrichs
#
class FormatAccepts
def initialize(app)
@app = app
@nakajima
nakajima / gist:108213
Created May 7, 2009 17:24 — forked from sr/gist:108184
forked to follow
require "test/unit"
require "contest"
require "rack/test"
require "sinatra/base"
require "nakajima"
class MyApp < Sinatra::Base
set :environment, :test
get "/" do