Skip to content

Instantly share code, notes, and snippets.

View jlucasps's full-sized avatar

João Lucas Pereira de Santana jlucasps

View GitHub Profile
class Caller
def self.exec_before( method_name)
@@before = method_name
end
def self.exec_after( method_name )
@@after = method_name
end
def execute( &code )
class Caller
def self.exec_before( method_name)
@@before = method_name
end
def self.exec_after( method_name )
@@after = method_name
end
@jlucasps
jlucasps / parse_params.rb
Created February 14, 2014 04:08
Parser for parameters from terminal
require 'yaml'
# Parser for parameters from terminal
# When you run a ruby script like $ ruby my_script.rb RAILS_ENV=production DATABASE=postgresql
# Usage in you my_script.rb file:
# >> p = ParseParams.new(ARGV, 'path/to/config_file.yml')
# >> p.params
class ParseParams
attr_accessor :params
%w(rb js erb).each do |format|
Dir.glob("app/**/*.#{format}").each do |file|
if File.file? file
puts file
f = File.open(file, "r:UTF-8")
text = f.read
new_text = text.gsub(/\t/, ' ')
File.open(file, "w:UTF-8") do |file|
@jlucasps
jlucasps / ruby_on_rails_roadmap.txt
Last active December 25, 2015 20:49
Rails roadmap
rails-0.10.0: Routing, Web Services, Components, Oracle
active support:
class e module attribute accessors:
Extends the class object with class and instance accessors for class attributes
Extends the module object with module and instance accessors for class attributes
inflectors:
The Inflector transforms words from singular to plural, class names to table names, modularized class names
@jlucasps
jlucasps / hostname_aws
Last active December 21, 2015 03:49
Changing hostname of aws instance
# Change content of file /etc/hostname to
princessleia
# Add same hostname to /etc/hosts
127.0.0.1 localhost
127.0.0.1 princessleia
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
@jlucasps
jlucasps / git_lg.sh
Last active December 20, 2015 23:29
Digite: git lg em qualquer projeto
# Add this line to ~/.gitconfig
[alias]
lg = log --graph --format=format:'%C(yellow)%h%C(reset) %C(red)- %an%C(reset) - %C(white)%s%C(reset) %C(bold yellow)%d%C(reset) %C(green)(%ar)%C(reset)' --abbrev-commit --date=short
# via https://gist.github.com/fernandopso
@jlucasps
jlucasps / coloring_terminal.sh
Last active December 20, 2015 23:29
No terminal vai informar em qual branch você está, diretório, usuário e o ambiente virtual se vocês estiver usando.
GIT_PS1_SHOWDIRTYSTATE=true
PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ '
# via https://gist.github.com/fernandopso
@jlucasps
jlucasps / ruby_nginx_postgres.sh
Last active April 25, 2018 12:07
Guide to Install ruby on rails, nginx and postgres
#update ubuntu packager
sudo apt-get update
#### Dependencies
#Install following prerequisite libraries for our environment
sudo apt-get install libpcre3-dev build-essential libssl-dev libxml2 libxml2-dev libxslt-dev ncurses-dev
#Install image processing libraries, if necessary
sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev
@jlucasps
jlucasps / friendly_url.js
Last active December 13, 2015 18:49
Transforms String in URL
// Transforms String in URL
function friendly_url(str, max) {
if (max === undefined) max = 32;
var a_chars = new Array(
new Array("a", /[áàâãªÁÀÂÃŪ]/g),
new Array("e", /[éèêÉÈÊ]/g),
new Array("i", /[íìîÍÌÎ]/g),
new Array("o", /[òóôõºÓÒÔÕ°Ö]/g),
new Array("u", /[úùûÚÙÛµÜü]/g),
new Array("c", /[çÇ¢©]/g),