Skip to content

Instantly share code, notes, and snippets.

require 'rubygems' rescue nil
require 'gosu'
require 'chipmunk'
class Array
# e.g. [1,2,3].each_link yields [1,2], [2,3]
def each_link
prev = first
self[1, size].each do |item|
yield prev, item
# What is it with you people and your singletons?
class Hash
def self.from_block(&block)
Hash[*BlockBuilder.new(&block).collected]
end
class BlockBuilder
attr_reader :collected
# Is there a preferred way to do it? A lot of people I see use inject, but it makes my eyes bleed.
x = [[1, 2], [3, 4]]
p x.inject({}) { |h, r| h[r[0]] = r[1]; h }
# {1=>2, 3=>4}
p Hash[*x.flatten]
# {1=>2, 3=>4}
describe 'rsync' do
it 'should keep the latest version of a file' do
system("mkdir -p d1 d2")
begin
system("echo 'This is the first version' > d1/file.txt")
sleep 1 # ensure timestamps are different
system("echo 'This is the second version' > d2/file.txt")
system("rsync -ru d2/ dest/")
system("rsync -ru d1/ dest/")
File.read('dest/file.txt').should include('second version')
@puyo
puyo / mypresentation.haml
Created November 19, 2010 22:18
Putting all your slick in one place...?
:javascript
Shining.config({...})
#first
%h1 Hi there world
%p Yes this is a slide
%p.step with a step
:javascript
// stuff for the first slide
:css
@puyo
puyo / order_spec.rb
Created August 26, 2011 08:08
Is it possible to rspec this properly without hitting the database?
create_table "line_items", :force => true do |t|
t.integer "cost"
t.boolean "paid"
t.integer "order_id"
end
create_table "orders", :force => true do |t|
end
# -----
@puyo
puyo / Gemfile
Created September 6, 2011 03:07
Rails 3.1 + Sprockets + Compass
gem 'haml-rails', '~> 0.3'
gem 'rails', '~> 3.1'
group :assets do
gem 'compass', '~> 0.11'
gem 'sass-rails', '~> 3.1'
gem 'coffee-rails', '~> 3.1'
gem 'uglifier', '~> 1.0'
end
1.9.3-p125 :001 > 1.week
=> 7 days
1.9.3-p125 :002 > Rails.version
=> "3.2.2"
1.9.3-p125 :003 >
#/usr/bin/env ruby
COLORS = [
RED = "\e[01;31m",
GREEN = "\e[01;32m",
YELLOW = "\e[01;33m",
BLUE = "\e[01;34m",
PINK = "\e[01;35m",
CYAN = "\e[0;36m",
GRAY = "\e[01;30m",
@puyo
puyo / eulalie.rb
Created April 27, 2012 10:01
Eulalie's first program
#/usr/bin/env ruby
COLORS = [
RED = "\e[01;31m",
GREEN = "\e[01;32m",
YELLOW = "\e[01;33m",
BLUE = "\e[01;34m",
PINK = "\e[01;35m",
CYAN = "\e[0;36m",
GRAY = "\e[01;30m",