This file contains hidden or 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
# Permit the Frog | |
# =============== | |
# | |
# NOTE: The idea is to release it as a gem eventually, but for now, until we have | |
# used it in the real world for a while, let's just keep it here. | |
# | |
# Define permissions with something like this: | |
# | |
# class Permit::Set | |
# it.can :read, Product do |user, target| |
This file contains hidden or 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" |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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. |