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
# gem install scene | |
require 'rubygems' | |
require 'scene' | |
class MyScene < Scene | |
def display | |
@count ||= 0 | |
@count += 1 | |
@count %= 200 |
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 'rubiks' | |
front = [:green, :green, :white, | |
:yellow, :green, :green, | |
:green, :red, :red] | |
back = [:green, :blue, :yellow, | |
:green, :blue, :orange, | |
:yellow, :orange, :white] |
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
# 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 | |
} |
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
# 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 |
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
# hash = HashWithoutNilValues.new | |
# hash[:a] = nil | |
# hash # => {} | |
# | |
# hash[:a] = {} | |
# hash[:a].class # => HashWithoutNilValues | |
# | |
# hash[:a] = [] | |
# hash[:a].class # => ArrayWithoutNilValues | |
# |
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
# 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) |
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 Rack::Reverse | |
def initialize(app) | |
@app = app | |
end | |
def call(env) | |
status, headers, body = @app.call(env) | |
[status, headers, [body.join.reverse]] | |
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
javascript:void((function(){var%20e=document.createElement('script');e.setAttribute('type','text/javascript');e.setAttribute('src','[[[[[URL HERE]]]]]');document.body.appendChild(e)})()) |
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
# 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 |
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
unless RUBY_VERSION =~ /1.9/ | |
class Array | |
def sample | |
self[rand(self.size)] | |
end | |
end | |
end |
OlderNewer