Skip to content

Instantly share code, notes, and snippets.

@tuzz
tuzz / irb.rb
Created Mar 15, 2012
A simple demo of my scene gem
View irb.rb
# gem install scene
require 'rubygems'
require 'scene'
class MyScene < Scene
def display
@count ||= 0
@count += 1
@count %= 200
@tuzz
tuzz / rubiks.rb
Created Mar 15, 2012
A potential project
View rubiks.rb
require 'rubiks'
front = [:green, :green, :white,
:yellow, :green, :green,
:green, :red, :red]
back = [:green, :blue, :yellow,
:green, :blue, :orange,
:yellow, :orange, :white]
@tuzz
tuzz / snippet.bash
Created Mar 18, 2012
mp4 conversion function
View snippet.bash
# Convert videos to mp4 for iTunes/iOS. Use cores * 1.5 as the number of threads.
# Works for most video formats out of the box. ffmpeg must be installed first.
mp4() {
ffmpeg -i "$1" -threads 6 -sameq -acodec libfaac -ar 48000 -ab 160k -ac 2 "$1".mp4
}
@tuzz
tuzz / qtn_patch.rb
Created Apr 14, 2012
A useful patch if you're subclassing AR 3.1.0-3.2.2
View qtn_patch.rb
# Fixes dynamic find by method attempting to use the connection
# on ActiveRecord::Base in activerecord versions 3.1.0 to 3.2.2
# when it should be respecting the connection on its subclass
class QuoteTableNamePatch
def self.quote_table_name(name)
name
end
end
module ActiveRecord
@tuzz
tuzz / without_nil.rb
Created Apr 15, 2012
Disallow nil from hash and array
View without_nil.rb
# hash = HashWithoutNilValues.new
# hash[:a] = nil
# hash # => {}
#
# hash[:a] = {}
# hash[:a].class # => HashWithoutNilValues
#
# hash[:a] = []
# hash[:a].class # => ArrayWithoutNilValues
#
@tuzz
tuzz / signature.rb
Created Apr 24, 2012
Generate an Unboxed email signature
View signature.rb
# Run this: ruby <(curl --silent https://raw.github.com/gist/2484316/signature.rb)
require 'erb'
def format_phone_number(string)
string.gsub!(/^0/, '+44')
string.gsub!(/(...)(..)(....)(....)/, '\1 \2 \3 \4')
end
def blank?(string)
@tuzz
tuzz / config.ru
Created May 5, 2012
Playing with rack
View config.ru
class Rack::Reverse
def initialize(app)
@app = app
end
def call(env)
status, headers, body = @app.call(env)
[status, headers, [body.join.reverse]]
end
@tuzz
tuzz / bootstrap.js
Created May 17, 2012
Bootstrap a JS file into a page via a bookmark
View bootstrap.js
javascript:void((function(){var%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('src','[[[[[URL HERE]]]]]');document.body.appendChild(e)})())
@tuzz
tuzz / dependencies.rb
Created May 26, 2012
Speedy gem dependency fetching
View dependencies.rb
# gem install gem-dependent
require 'rubygems/dependent'
def gem_dependencies(limit = nil)
specs_and_sources = Gem::Dependent.all_specs_and_sources(:all_versions => true)
specs_and_sources = specs_and_sources.take(limit) if limit
Gem::Dependent.fetch_all_dependencies(specs_and_sources)
end
puts gem_dependencies(100).inspect
@tuzz
tuzz / sample.rb
Created May 31, 2012
Sample pre 1.9
View sample.rb
unless RUBY_VERSION =~ /1.9/
class Array
def sample
self[rand(self.size)]
end
end
end
You can’t perform that action at this time.