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>
@elgalu
elgalu / exceptional_ruby_book_quiz.rb
Created November 22, 2012 21:26
Exceptional Ruby: Master the Art of Handling Failure in Ruby by Avdi Grimm
Great book! Here are my quiz notes:
- What is the diff bt raise and fail?
=> no diff
- Are raise//fail ruby keywords or methods?
=> Kernel#raise (are methods)
- Re-raise last exception
=>
@elgalu
elgalu / metaprogramming_ruby_quiz.rb
Created December 6, 2012 04:00
My quiz on: Metaprogramming Ruby: Program Like the Ruby Pros by Paolo Perrotta
- Returns?
module Module
def const_missing(name)
"sorry i don't have #{name} yet"
end
end
Untitled #=> ?
Monkeys #=> ?
=>
You get `TypeError: Module is not a module` before reaching Untitled code
@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 / write_expectation.rb
Last active May 9, 2019 08:39
An RSpec expectation to test text written to standard output and standard error
require 'rspec'
require 'stringio'
# Custom matcher to test text written to standard output and standard error
#
# @example
# expect { $stderr.puts "Some random error" }.to write(/Some.* error/).to(:stderr)
#
# @example
# expect { $stderr.puts "Some specific error" }.to write('Some specific error').to(:stderr)
@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