Skip to content

Instantly share code, notes, and snippets.

View nosolopau's full-sized avatar

Pablo Torrecilla nosolopau

View GitHub Profile
require_relative "echo"
require "minitest/autorun"
require 'securerandom'
class TestEcho < Minitest::Test
def setup
@echo = Echo.new
end
require_relative "echo"
require "minitest/autorun"
require 'securerandom'
class TestEcho < Minitest::Test
def setup
@echo = Echo.new
end
require_relative "echo"
require "minitest/autorun"
class TestEcho < Minitest::Test
def setup
@echo = Echo.new
end
@nosolopau
nosolopau / rails_new
Last active August 29, 2015 14:14
Create a rails application into current directory with specific rbenv and rails version
#!/bin/bash
# Rails new utility
# Usage: rails_new ruby_version rails_version
echo "$1" > .ruby-version
echo "source 'https://rubygems.org'" > Gemfile
echo "gem 'rails', '$2'" >> Gemfile
bundle install
bundle exec rails new . --force --skip-bundle --skip-active-record
@nosolopau
nosolopau / .bash_profile
Created January 30, 2015 11:27
Basic .bash_profile
eval "$(rbenv init -)"
source ~/.git-completion.bash
alias gh='git checkout'
alias gl='git log --decorate=full'
alias g='git status'
alias gc='git commit'
alias be='bundle exec'
alias s='ssh'
@nosolopau
nosolopau / patapum
Last active November 11, 2015 16:32
The top-secret, ultimate, easy deployer.
#!/bin/bash
if [ -f "Capfile" ]
then
if [ "$1" = "parriba" ]
then
env='production'
else
env='staging'
fi
@nosolopau
nosolopau / deploy.rb
Created January 8, 2014 11:02
Send email notifications after deploy (with Capistrano and Rails 4). Capistrano variables reference: http://theadmin.org/articles/capistrano-variables/
# Add the following lines at the end of config/deploy.rb
Dir["config/deploy/extras/*.rb"].each { |file| load file }
set :notify_emails, ["mail@example.com"]
after "deploy", "deploy:notify"
@nosolopau
nosolopau / gist:6966003
Created October 13, 2013 18:57
Provinces of Spain with their codes in a Ruby hash.
provinces = {
1 => "Álava",
2 => "Albacete",
3 => "Alicante",
4 => "Almería",
33 => "Asturias",
5 => "Ávila",
6 => "Badajoz",
7 => "Illes Balears",
8 => "Barcelona",
@nosolopau
nosolopau / s3.js
Last active May 4, 2017 08:53
Amazon S3 upload policy generation with JavaScript (Node.js).
var crypto = require("crypto");
var moment = require("moment")
var s3 = {
generateS3Policy: function (fileName) {
var s3Policy = {
'conditions': [
{'bucket': CONF.s3.bucket},
['starts-with', '$key', 'uploads/' + fileName],
{'acl': 'public-read'},
@nosolopau
nosolopau / string.rb
Created May 28, 2012 11:20
Singularize method for Rails String class
# encoding: UTF-8
class String
def singularize_es
if self[-2..-1].index(/es/) # Ending in 'es'
if self[-4..-1].index(/[^aeiou][^aeiou]es/) # Ending in consonant + consonant + 'es': remove 's' ('coche' > 'coches')
self[0..-2]
else
if self[-3..-1].index(/[^aeiou]es/) # Ending in consonant + 'es'
case self[-3..-1]