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:5786
Created August 17, 2008 03:53
undefined
# My first shoes app
Shoes.app(:width => 250, :height => 100) do
background gradient('#000', '#222')
flow(:margin => 10) do
@e = edit_line "My name is Judge!", :width => 210
flow(:margin_top => 12) do
button("TELL") { alert @e.text }
button("QUIT") { exit }
end
end
@nakajima
nakajima / gist:6320
Created August 20, 2008 04:36
A pixel painting app for shoes, sort of like looklooksee.com.
class LookLookSee < Shoes
url '/', :index
# TODO Use actual Shoes::Color objects for these values?
BACKGROUND = [20,20,20]
START_COLOR = [24,24,24]
HOVER_COLOR = [36,36,36]
PIXEL_SIZE = 20
ANIMATING = { }
PAINTED = { }
@nakajima
nakajima / ego_hub.rb
Created September 1, 2008 21:03
Find out how many people are following your projects on GitHub.
require 'rubygems'
require 'hpricot'
require 'open-uri'
GITHUB = "http://github.com/"
PROJECT_SELECTOR = 'li.project .title b a'
class String
def parse_int
scan(/\d+/).to_s.to_i
@nakajima
nakajima / gist:8691
Created September 3, 2008 23:26
Giving erector a fair shake.
%w(rubygems dm-core dm-validations erector sinatra erb).each { |lib| require lib }
class Blog < Erector::Widget
def initialize(err=false)
@err = err
super
end
def render
html do
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<title>Cropper</title>
<script src="http://localhost:3000/javascripts/prototype.js" type="text/javascript" charset="utf-8"></script>
<script src="http://localhost:3000/javascripts/effects.js" type="text/javascript" charset="utf-8"></script>
<script src="http://localhost:3000/javascripts/dragdrop.js" type="text/javascript" charset="utf-8"></script>
<style type="text/css" media="screen">
@nakajima
nakajima / gist:13001
Created September 26, 2008 01:15
undefined
# For making nicer CLI tools that take a while to do things
#
# Example:
#
# with_progress do
# sleep 2 # or some slow task
# end
#
# You can also pass in options to customize messages as well
# as the rate of the progress output.
require 'rubygems'
require 'activesupport'
module ConditionalEvaluator
def evaluate_conditional(conditional)
case conditional
when Symbol then send(conditional)
when Proc then conditional.call
end
end
@nakajima
nakajima / gist:14600
Created October 3, 2008 18:13
Shows the other records that get destroyed when you destroy this one.
class ActiveRecord::Base
def dependents(type=:destroy)
reflections = self.class.reflect_on_all_associations
reflections = reflections.select { |r| r.options[:dependent] == type }
names = reflections.map(&:name)
names.inject([]) do |list, name|
list += send(name)
list += send(name).map { |entity| entity.dependents rescue [] }
list
end.flatten.compact
%w(rubygems sinatra sinatras-hat dm-core dm-serializer).each { |lib| require lib }
class Post
include DataMapper::Resource, DataMapper::Serialize
property :id, Serial, :key => true
property :name, String
property :body, Text
end
@nakajima
nakajima / gist:14528
Created October 3, 2008 08:03
Shoot footing fun, ported from JavaScript
require 'rubygems'
require 'metaid' # always a good idea
require 'spec'
Object.class_eval do
def with(hash)
hash.each do |key, value|
meta_def(key) { hash[key] }
meta_def("#{key}=") { |v| hash[key] = v }
end