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: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
@nakajima
nakajima / gist:108480
Created May 7, 2009 23:50 — forked from pauldix/gist:108444
aesthetics
# Currently it looks like this:
class Twitter
include Typhoeus
remote_defaults :on_success => lambda {|response| JSON.parse(response.body)},
:on_failure => lambda {|response| puts "error code: #{response.code}"},
:base_uri => "http://search.twitter.com"
define_remote_method :search, :path => '/search.json'
define_remote_method :trends, :path => '/trends/:time_frame.json'
end
Go through each of the commits here and see the process
of writing an object-oriented beginner Ruby program.
Good luck!
Pat
@nakajima
nakajima / likewise.rb
Created May 14, 2009 09:41 — forked from jbarnette/adjacent.rb
Ruby's fun, right?
# likewise require
# by Pat Nakajima
# because I've been drinking more than Jack Barnette
# and
# to annoy John Susser and Aaron Peterson
#
# use to require files relative to the current file:
#
# likewise do
# require "foo" # require current-dir/lib
@nakajima
nakajima / quiz.rb
Created May 15, 2009 20:23 — forked from ryanb/quiz.rb
could be better, could be worser
# COMMUNITY CHALLENGE
#
# How would you test this Quiz#problem method? Only two rules:
#
# 1. The tests should fail if any part of the application breaks.
# For example: If "gets" is moved before "puts" then the tests should
# fail since that breaks the application.
#
# 2. You cannot change the Quiz class. But you can use whatever framework
# and tools you want for the tests. (RSpec, Cucumber, etc.)
A simple, test-driven, object-oriented approach to converting Celsius to
Fahrenheit and vice-versa, hopefully it's simple enough to be useful for a
newcomer to programming.
# Not exactly sure what I'm doing here...
class RestKlass
%W[get post put delete].each { |verb|
define_method(verb) { |res| res }
}
def get; :gotten end
end
class SQLKlass
@nakajima
nakajima / A.rb
Created June 19, 2009 08:34 — forked from bmizerany/A.rb
Rails::Initializer.run do |config|
# Require the latest version of haml
config.gem "haml"
# Require a specific version of chronic
config.gem "chronic", :version => '0.2.3'
# Require a gem from a non-standard repo
config.gem "hpricot", :source => "http://code.whytheluckystiff.net"
ftw = {
:a => 42,
:b => 43
}
$ ruby -e 'exit'
$ echo $?
0
$ ruby -e 'exit 1'
$ echo $?
1
$ ruby -e 'abort "oh no"'
oh no
$ echo $?
1