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
# This is inspired by http://ckdake.com/comment/reply/362 | |
desc "Deploy ALL the targets" | |
task :deploy => ["deploy:assets", "deploy:heroku"] | |
namespace :deploy do | |
desc "Synchronize assets to S3" | |
task assets: [:environment, | |
:load_config, | |
"assets:precompile", |
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
# Public: generates a mixable singleton implementation dependent on a model key. | |
# Once you mix it into a model, your model gains an .instance method that will | |
# generate an object and cache it. Further calls to the .instance methods will | |
# return the same object. | |
# | |
# key - The name of the attribute we use to index instances. Defaults to "id". | |
# | |
# Example | |
# | |
# # Called without arguments uses the "id" as key. |
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
▸ rake about --trace | |
** Invoke about (first_time) | |
** Invoke environment (first_time) | |
** Execute environment | |
** Execute about | |
About your application's environment | |
Ruby version 1.9.3 (x86_64-darwin11.2.0) | |
RubyGems version 1.8.11 | |
Rack version 1.3 | |
Rails version 3.1.2 |
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 "sinatra/base" | |
class Foo < Sinatra::Base | |
get "/" do | |
"hola" | |
end | |
get "/foo" do | |
pass | |
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
image = ChunkyPNG::Image.from_file("./app/assets/images/rails.png") | |
colors = image.pixels.inject(Hash.new(0)) do |counts, pixel| | |
color = ChunkyPNG::Color.to_truecolor_alpha_bytes(pixel) | |
counts[color] += 1 | |
counts | |
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
$ sud osu | |
No command 'sud' found, did you mean: | |
Command 'sed' from package 'sed' (main) | |
Command 'sup' from package 'sup' (universe) | |
Command 'sux' from package 'sux' (universe) | |
Command 'sbd' from package 'cluster-glue' (universe) | |
Command 's3d' from package 's3d' (universe) | |
Command 'sudo' from package 'sudo' (main) | |
Command 'sudo' from package 'sudo-ldap' (universe) | |
Command 'snd' from package 'snd-nox' (universe) |
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
module ValueObject | |
def self.new(*attrs) | |
klass = Class.new(Object) | |
klass.send(:attr_reader, *attrs) | |
klass.send(:define_method, :initialize) do |*args| | |
raise ArgumentError, "wrong number of arguments (#{args.size} for #{attrs.size})" unless args.size == attrs.size | |
attrs.each_with_index do |attr, idx| | |
instance_variable_set("@#{attr}", args[idx]) |
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 Job | |
LAZY_ENVIRONMENTS = %w(development test) | |
# Add a job to the queue. If we're currently running in any of the | |
# environments listed in +LAZY_ENVIRONMENTS+ then it automatically performs | |
# the job. | |
def self.enqueue(*args) | |
if LAZY_ENVIRONMENTS.include? Rails.env | |
Rails.logger.debug "Performing job instead of enqueuing: #{name}" | |
perform(*args) |
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
$ git config alias.stale | |
!for sha in $(git branch -rv --merged | grep -v origin/HEAD | awk '{print $2}'); do printf "%-40s %s" "$(git name-rev --name-only $sha)" "$(git log -1 --format="%h %an" $sha | cat)"; done |
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
namespace :git do | |
desc "Create a git tag of the current release" | |
task :tag_release do | |
ref = `git ls-remote #{repository} #{branch} | awk '{print $1}'`.chomp | |
# ISO representation of the current time | |
time = Time.now.utc.to_datetime.to_s | |
time.gsub! /-|:/, "" | |
time.gsub! /\+\d+$/, "Z" |