Skip to content

Instantly share code, notes, and snippets.

View GusGA's full-sized avatar
🕶️
Reading someone else's code

Gustavo Giménez GusGA

🕶️
Reading someone else's code
  • Santiago, Chile
View GitHub Profile

Keybase proof

I hereby claim:

  • I am gusga on github.
  • I am gusga (https://keybase.io/gusga) on keybase.
  • I have a public key whose fingerprint is 6541 70EF DC04 1CD3 43F3 E3C5 5F45 CBE5 C936 3153

To claim this, I am signing this object:

@GusGA
GusGA / al-livelog.sh
Last active February 29, 2016 18:44
Git repo real time status
#!/bin/bash
while :
do
clear
date +"%A %B %d, %Y at %T"
lines=`tput lines`
lines=`expr $lines - 5`
git --no-pager log --color --all --pretty='format:%C(auto)%d%Creset %C(yellow)%h%Creset %C(green)%an%Creset - %s - %C(cyan)%cr%Creset' --graph $* | head -n $lines
sleep 1
#!/usr/bin/env ruby
# Libraries:::::::::::::::::::::::::::::::::::::::::::::::::::::::
require 'rubygems'
require 'sinatra/base'
require 'slim'
require 'sass'
require 'coffee-script'
# Application:::::::::::::::::::::::::::::::::::::::::::::::::::
@GusGA
GusGA / mi_yeoman.sh
Last active August 29, 2015 14:13
generador de estructura de directorio para desarrollo front-end
#!bin/bash
if [ -z "$1" ]; then
echo "Debes ingresar el nombre del proyecto o directorio"
exit 1
else
if [ -e "$1" ]; then
echo "El Directorio $1 ya existe"
exit 1
fi
# Tell system when Xcode utilities live:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
# Set "opendiff" as the default mergetool globally:
git config --global merge.tool opendiff
@GusGA
GusGA / deploy.rb
Last active August 29, 2015 14:19 — forked from wlangstroth/deploy.rb
require 'bundler/capistrano'
set :application, "net"
set :repository, "[email protected]:net.git"
set :scm, :git
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}
morse_dict = Hash.new({
"a" => ".-",
"b" => "-...",
"c" => "-.-.",
"d" => "-..",
"e" => ".",
"f" => "..-.",
"g" => "--.",
"h" => "....",
"i" => "..",

Transactions

As your business logic gets complex you may need to implement transactions. The classic example is a bank funds transfer from account A to account B. If the withdrawal from account A fails then the deposit to account B should either never take place or be rolled back.

Basics

All the complexity is handled by ActiveRecord::Transactions. Any model class or instance has a method named .transaction. When called and passed a block, that block will be executed inside a database transaction. If there's an exception raised, the transaction will automatically be rolled back.

Example

Deploy Rails app to digitalocean with nginx, unicorn, capistrano & postgres

Create droplet of your liking (ubuntu 12.10 x32)

ssh to root in terminal with your server ip

ssh [email protected]

Add ssh fingerprint and enter password provided in email