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
@GusGA
GusGA / fizz_buzz.ex
Created September 18, 2015 12:20
FizzBuzz Code in Elixir
defmodule FizzBuzz do
def start do
IO.inspect Enum.map(1..100, fizz_or_buzz)
end
def fizz_or_buzz(n) do
cond do
rem(n,15) == 0 -> "FizzBuzz"
rem(n,5) == 0 -> "Buzz"
@GusGA
GusGA / excel_validator.rb
Last active September 22, 2015 04:46
Prueba 5Rabbits
require 'roo'
module ExcelValidator
class Cause
#EXCEL_COLUMN_NAMES = ['NOMBRE DEL CLIENTE', 'ASUNTO', 'CODIGO DE LA CAUSA', 'JUZGADO', 'MATERIA', 'CODIGO', 'PERSONAS INVOLUCRADAS EN LA CAUSA']
# column_names = { id: 'NOMBRE DEL CLIENTE', .... }
class << self
def manage_file(file, **column_names)
@column_names = column_names
case File.extname(file.original_filename)
@GusGA
GusGA / list_by_commiter.sh
Created July 29, 2015 02:00
lines_by_commiter
git log --numstat --pretty="%H" --author=$1 | grep -v "public/" | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'

DigitalOcean Ubuntu 14.04 x64 + Rails 4 + Nginx + Unicorn + PostgreSQL + Capistrano 3

SSH into Root

$ ssh root@123.123.123.123

Change Root Password

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 root@123.123.123.123

Add ssh fingerprint and enter password provided in email

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

morse_dict = Hash.new({
"a" => ".-",
"b" => "-...",
"c" => "-.-.",
"d" => "-..",
"e" => ".",
"f" => "..-.",
"g" => "--.",
"h" => "....",
"i" => "..",
@GusGA
GusGA / deploy.rb
Last active August 29, 2015 14:19 — forked from wlangstroth/deploy.rb
require 'bundler/capistrano'
set :application, "net"
set :repository, "git@githost.com:net.git"
set :scm, :git
set :default_environment, {
'PATH' => "$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH"
}
# 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 / 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