Skip to content

Instantly share code, notes, and snippets.

@ppdeassis
ppdeassis / model_spec.rb
Last active December 17, 2015 08:09
Template for a Model spec
require 'spec_helper'
describe Person do
# NOTE: build, create and attributes_for are FactoryGirl methods
# You should include this line in spec_helper to make them available
# without FactoryGirl. (prefix):
# ---
# Rspec.configure do |config|
# ...
@ppdeassis
ppdeassis / controller_spec.rb
Last active December 17, 2015 08:18
Template for a Controller spec
# spec/controllers/contacts_controller_spec.rb
require 'spec_helper'
describe MyController do
describe "#action" do
context "access restriction" do
it "requires authentication" do
# expect(repsonse).to redirect_to(login_path)
end
it 'requires authorization' do
@ppdeassis
ppdeassis / homebrew
Last active December 17, 2015 08:18 — forked from gcatlin/gist:1847248
Install a specific formula with Homebrew package manager, or change versions...
brew update
brew versions FORMULA
cd `brew --prefix`
git checkout HASH Library/Formula/FORMULA.rb # use output of "brew versions"
brew install FORMULA
brew switch FORMULA VERSION
git checkout -- Library/Formula/FORMULA.rb # reset formula
## Example: Using Subversion 1.6.17
#
@ppdeassis
ppdeassis / string_extensions.rb
Last active December 17, 2015 09:19
String extensions in ruby (rails initializers...)
# -*- encoding : utf-8 -*-
module StringExtensions
def sanitize(options = {})
Sanitize.clean(self, options)
end
def downcase_with_accent_support
self.
downcase.
tr("À", "à").
@ppdeassis
ppdeassis / git
Last active January 27, 2016 14:25
Snippets for git
# init a bare repository (on a server)
mkdir repos/path.git
cd repos/path.git
git init --bare
# then, on a workstation
mkdir LOCAL_REPOS_PATH
cd LOCAL_REPOS_PATH
git init
touch .gitkeep
git add .
@ppdeassis
ppdeassis / postgresql
Last active December 17, 2015 16:09
Common postgresql tasks
# environment variables: http://www.postgresql.org/docs/9.2/static/libpq-envars.html
# PGUSER - default username
# PGDATABASE - default database name
# PGDATA - default database cluster directory
# initializing a cluster
initdb --encoding=UTF-8 --locale=pt_BR.UTF-8 [--pgdata=$PGHOME/data] [--username=superuser]
@ppdeassis
ppdeassis / iconv
Last active December 18, 2015 04:59
File encoding conversion
# iso to utf-8
iconv -f iso-8859-1 -t utf-8 INPUT_FILE > OUTPUT_FILE
# mac to utf-8 (OS X Office Excel exports CSV with this encoding)
iconv -f mac -t utf-8 INPUT_FILE > OUTPUT_FILE
# converting .DAT files in a directory from ISO-8859-1 to UTF-8
find input/dir -iname "*.dat" -type f -exec bash -c 'iconv -f iso-8859-1 -t utf-8 "{}" > output/dir/"{}"' \;
@ppdeassis
ppdeassis / rsync
Last active December 18, 2015 05:29
Synchronizing files with rsync
# Synchronize directories with rsync and ssh:
# -r recursive
# -c skip based on checksum, not mod-time & size
# -h output numbers in a human-readable format
# -a archive mode
# -v verbose mode
# -e define shell used as transport
# -P same as --partial --progress: keeps partial transfered files if interrupted AND shows progress
# --delete to delete extraneous files on dest dir
rsync -rav -e "ssh -l $_USERNAME" --delete $_SOURCE_DIR $_DEST_DIR
@ppdeassis
ppdeassis / iptables
Last active December 18, 2015 05:59
Manipulating rules with iptables
# listing chain rules
iptables --list CHAIN --line-numbers
# deleting a rule
iptables --delete CHAIN LINE_NUMBER
# inserting a rule in a predefined position (i.e. 3)
iptables -I INPUT 2 -p tcp --dport 80 -j ACCEPT
# appending rule to chain
@ppdeassis
ppdeassis / oracle_reader.rb
Created June 18, 2013 14:35
A Ruby class to acces an Oracle database
################################################################################
require 'oci8'
require 'iconv'
################################################################################
class OracleReader
################################################################################
def initialize(server, username, password)
# Open the connection.
@connection = OCI8.new(username, password, server)