Skip to content

Instantly share code, notes, and snippets.

View elgalu's full-sized avatar

Leo Gallucci elgalu

View GitHub Profile
@elgalu
elgalu / heroku.rake
Created February 20, 2011 03:50
Generate your .gems file with: rake heroku:gems.rb
namespace :heroku do
desc "Generate the Heroku gems manifest from gem dependencies"
task :gems do
RAILS_ENV='production'
Rake::Task[:environment].invoke
list = Rails.configuration.gems.collect do |g|
command, *options = g.send(:install_command)
options.join(" ") + "\n"
end
@elgalu
elgalu / Ruby.tmLanguage
Created October 20, 2012 00:54
Sublime Text - Adding ruby regular expression detection starting and ending with slashes
<!-- elgalu: Adding ruby regular expression detection starting and ending with slashes -->
<dict>
<key>begin</key>
<string>/</string>
<key>beginCaptures</key>
<dict>
<key>0</key>
<dict>
<key>name</key>
<string>punctuation.definition.string.begin.ruby</string>
This file has been truncated, but you can view the full file.
> gemini@1.0.4 test /home/user/oss/gemini
> istanbul test _mocha -- --recursive test/unit test/functional test/browser
Tue, 27 Oct 2015 10:45:07 GMT mocha:suite bail undefined
Tue, 27 Oct 2015 10:45:07 GMT mocha:suite enableTimeouts true
Tue, 27 Oct 2015 10:45:07 GMT mocha:suite timeout 0
Tue, 27 Oct 2015 10:45:07 GMT mocha:suite bail undefined
Tue, 27 Oct 2015 10:45:07 GMT mocha:suite timeout 0
Tue, 27 Oct 2015 10:45:07 GMT mocha:suite enableTimeouts false
@elgalu
elgalu / test-shell-colors.sh
Last active December 12, 2015 08:08
Testing if shell colors works on a gist
$ bundle gem lagema
\E[30m black \E[31mred \E[32mgreen \E[33myellow \E[34mblue \E[35mmagenta \E[36mcyan \E[37mwhite
<span>create</span> lagema/Gemfile
LIGHTGREEN="\033[1;32m"
LIGHTRED="\033[1;31m"
WHITE="\033[0;37m"
RESET="\033[0;00m"
create lagema/Rakefile
create lagema/LICENSE.txt
create lagema/README.md
@elgalu
elgalu / pro_git_quiz.sh
Last active December 13, 2015 19:09
My quiz on: Pro Git by Scott Chacon
##
- How is the git `staging area` a.k.a?
=>
# Is also known as the index
##
- List all available git configurations within current dir
=>
git config --list
#=>
@elgalu
elgalu / Gemfile.tt
Last active December 14, 2015 06:09
Sample thor task to create custom generators
source 'https://rubygems.org'
# Specify your gem's dependencies in <%= gem_name %>.gemspec
gemspec
@elgalu
elgalu / foreman.rb
Created June 5, 2013 15:45
Cron Job Idea for OpenShift at /.openshift/cron/hourly/foreman
#!/bin/bash
pushd ${OPENSHIFT_REPO_DIR} > /dev/null
# Set env vars
source ${OPENSHIFT_REPO_DIR}/.env.openshift
# Run jobs
# bundle exec rake jobs:work
bundle exec foreman start > ${OPENSHIFT_RUBY_LOG_DIR}/foreman.log &
# config/application.rb
module SpeakerDeck
class Application < Rails::Application
# …
console do
require 'speaker_deck/console'
Rails::ConsoleMethods.send :include, SpeakerDeck::Console
end
end
@elgalu
elgalu / decorator-pattern-with-ruby-in-8-lines.rb
Last active December 19, 2015 17:09
Decorator Pattern with Ruby in 8 lines - http://goo.gl/d960j
module Decorator
def initialize(decorated)
@decorated = decorated
end
def method_missing(method, *args)
args.empty? ? @decorated.send(method) : @decorated.send(method, args)
end
end
@elgalu
elgalu / order_service.rb
Created July 24, 2013 04:26
Services Objects: Moving Behavior from Controllers http://goo.gl/jtjDw
module OrderService
def self.create(listener, user, order_attrs)
Order.new(order_attrs.merge(user: current_user))
if order.save
transaction = PaymentProcessor.create_payment(order)
listener.order_creation_succeeded(order, transaction)
else
listener.order_creation_failed(order)
end
end