This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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"> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'activesupport' | |
module ConditionalEvaluator | |
def evaluate_conditional(conditional) | |
case conditional | |
when Symbol then send(conditional) | |
when Proc then conditional.call | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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 | |