Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'gosu'
class LittleBrat < Gosu::Window
LETTER_LIMIT = 100
def initialize
# Full resolution, fullscreen
super(Gosu.screen_width, Gosu.screen_height, true)
self.caption = "Leave me alone you little brat!"
# The letters the little brat hits on the keyboard
@blowmage
blowmage / gist:590629
Created September 21, 2010 21:39
Array#=~
a = [1, 2, 3]
b = [3, 2, 1]
class Array
def =~(other)
self.sort == other.sort
end
end
puts a =~ b #=> true
@blowmage
blowmage / event_queue_callbacks.rb
Created April 5, 2011 19:26
Quick example on using a local hash to hold event callbacks.
class Foo
def start
# Do something important here
perform :start
end
def finish
perform :finish
# Clean up stuff here
end
@blowmage
blowmage / GEM_NAME.gemspec
Created June 8, 2011 22:08
Simple Gem Template
require "rake"
Gem::Specification.new do |s|
s.name = "GEM_NAME"
s.version = "0.1.0"
s.summary = "GEM_SUMMARY (short)"
s.description = "GEM_DESCRIPTION (longer)"
s.homepage = "http://example.com/GEM_NAME"
s.authors = ["GEM_AUTHOR_NAME"]
s.email = "GEM_AUTHOR_EMAIL"
@blowmage
blowmage / list.rb
Created July 14, 2011 15:12
Testing Primer (URUG presentation 7/12/2011)
class List < ActiveRecord::Base
belongs_to :user
validates_presence_of :name
validates_presence_of :user
end
@blowmage
blowmage / edgecase.rb
Created July 27, 2011 02:08
Ruby Koans Hackfest
#!/usr/bin/env ruby
# -*- ruby -*-
require 'test/unit/assertions'
class Object
def method_missing *args
true
end
end
@blowmage
blowmage / Rakefile
Created August 23, 2011 03:18
Flog Example
# Note we are requiring Flog before any other rake task
# This fails with "uninitialized constant Rake::TaskLib"
require "flog_task"
FlogTask.new do |t|
t.verbose = true
end
# If we require this before flog_task then it will load fine
require "rake/testtask"
Rake::TestTask.new do |t|
@blowmage
blowmage / lambda.rb
Created December 14, 2011 02:48
Blocks, Procs and Lambda - Oh My!
def test_lambda
puts "About to call lambda"
blck = lambda do
puts " -- Start lambda"
return "lambda"
puts " -- End lambda"
end
val = blck.call
puts "The value is #{val}"
puts "Just called lambda"
@blowmage
blowmage / changes.rake
Created June 5, 2012 18:21
Rake tasks for generating changes made by author
# Taken from http://stackoverflow.com/a/9782550
namespace :git do
desc "Analytics of changes made by author"
task :changes do
git_changes_by_author.sort_by { |a,h| -h[:total] }.each do |author, changes|
puts "#{author}: #{changes[:total]} (#{changes[:insertions]} insertions, #{changes[:deletions]} deletions)"
end
end
end
@blowmage
blowmage / foo.rb
Created August 3, 2012 11:42
Shouldify MiniTest
class Foo
def bar
"bar"
end
def baz
"baz"
end
end