Skip to content

Instantly share code, notes, and snippets.

View wilsonsilva's full-sized avatar

Wilson Silva wilsonsilva

View GitHub Profile
@wilsonsilva
wilsonsilva / install_gem_in_production_console.rb
Last active June 16, 2020 10:33
Install and use gem in production rails console
# Install the gem
`gem install hirb`
# Find the gem's location
gem_path = ENV['GEM_HOME'] + '/gems/hirb-0.7.3/lib'
$: << gem_path
# Require it
require 'hirb'
# Download the alpine image, which is more than 50% smaller than the base image
docker pull postgres:12.3-alpine
# macros is a the name of your app. My app is called "macros".
# One volume per app ensures that we can isolate and back it up independently
docker volume create macros
docker run --name postgres \
-e POSTGRES_PASSWORD=postgres -d -p 5432:5432 \
-v macros:/var/lib/postgresql/data postgres:12.3-alpine
@wilsonsilva
wilsonsilva / configure-pattern.rb
Created April 25, 2018 13:10
Configuration pattern [PATTERNS]
# Definition
module Project
class Configuration
attr_accessor :name, :author
end
end
module Project
extend self
describe '#educate' do
 it 'increments the education level by 1' do
  expect { person.educate }.to change { person.education_level }.from(1).to(2)
  end
end
@wilsonsilva
wilsonsilva / undo_last_commit.sh
Created June 21, 2017 15:47
Undo last commit but keep changes
# https://stackoverflow.com/a/44672195/3013522
git reset --soft HEAD~1
@wilsonsilva
wilsonsilva / crazy_method.rb
Created December 11, 2015 10:25
Crazy Ruby Method
def self.❨╯°□°❩╯︵┻━┻
puts 'Calm down, yo.'
end
@wilsonsilva
wilsonsilva / remove-old-branches.sh
Last active August 29, 2015 14:27
Deletes all local branches that are already merged into master
#!/bin/bash
git branch --merged master | grep -v 'master$' | xargs git branch -d
@wilsonsilva
wilsonsilva / dts
Last active August 29, 2015 14:25
Deploy current branch to staging using capistrano
#!/bin/sh
export BRANCH=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
echo "Deploying $BRANCH to staging"
cap staging deploy
@wilsonsilva
wilsonsilva / small_spec.rb
Last active October 13, 2015 11:39
RSpec one liners
describe User do
subject { create(:user, name: 'Wilson Silva', activated: true) }
it { is_expected.to be_activated }
its(:name) { is_expected.to eq('Wilson Silva') }
end
@wilsonsilva
wilsonsilva / read
Created March 24, 2015 11:38
Read process output
sudo tail -f /proc/<pid>/fd/1
example: sudo tail -f /proc/2394/fd/1