Skip to content

Instantly share code, notes, and snippets.

View foca's full-sized avatar

Nicolás Sanguinetti foca

View GitHub Profile
@foca
foca / deploy.rake
Created January 21, 2012 17:21
Rake task to synchronize assets to S3 (via asset_sync) and deploy to heroku, optionally migrating the database if that needs doing.
# 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",
@foca
foca / singleton.coffee
Created January 18, 2012 22:39
Small implementation of Singletons for Backbone
# 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.
▸ 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
@foca
foca / config.ru
Created December 4, 2011 19:38
How to stack multiple sinatra applications
require "sinatra/base"
class Foo < Sinatra::Base
get "/" do
"hola"
end
get "/foo" do
pass
end
end
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
$ 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)
@foca
foca / value_object.rb
Created July 30, 2011 02:14
Extremely lightweight "Struct" that only defines attribute readers
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])
@foca
foca / job.rb
Created July 22, 2011 18:29
I don't really care for running Resque in dev or test environments.
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)
@foca
foca / gist:1098132
Created July 21, 2011 20:30
List branches that are still in the upstream repositories
$ 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
@foca
foca / capistrano-tag_release.rb
Created June 20, 2011 19:29
Automatically create a tag of your repository when you deploy
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"