Skip to content

Instantly share code, notes, and snippets.

View herval's full-sized avatar
:shipit:

Herval Freire herval

:shipit:
View GitHub Profile
# String extension to remove non-ascii/graphic accent characters
# pt-BR: métodos para remover acentos (e espaços) de String
require 'iconv'
class String
# São José do Poço -> Sao Jose do Poco
def remove_non_ascii
Iconv.iconv("ASCII//IGNORE//TRANSLIT", "UTF-8", self).join.gsub(/[^a-z._0-9 -]/i, "").tr(".", "_")
end
# Configuração do Sphinx para partial matching e caracteres acentuados em português
production:
enable_star: 1
min_infix_len: 2
charset_table: "\
U+00C0->a, U+00C1->a, U+00C2->a, U+00C3->a, U+00C4->a, U+00E0->a, U+00E1->a, U+00E2->a, U+00E3->a, U+00E4->a, \
U+00C7->c, U+00E7->c, \
U+00C8->e, U+00C9->e, U+00CA->e, U+00CB->e, U+00E8->e, U+00E9->e, U+00EA->e, U+00EB->e, \
U+00CC->i, U+00CD->i, U+00CF->i, U+00EC->i, U+00ED->i, \
U+00D2->o, U+00D3->o, U+00D4->o, U+00D5->o, U+00D6->o, U+00F2->o, U+00F3->o, U+00F4->o, U+00F5->o, U+00F6->o, \
Estamos dando início a um projeto novo, e temos uma a duas vagas pra estágios em desevolvimento.
Estou procurando interessados para fazer parte do projeto.
As duas vagas pedem por experiência mínima: leia-se noção das tecnologias citadas
(obviamente, quanto mais experiência melhor), proatividade e interesse em aprender até a cabeça estourar,
trabalhando em um projeto que vai dar o que falar :-)
RIA Padawan
- Flex e/ou Flash (visual e programação com actionscript)
- Java SE (Swing, SWT, JavaFX)
@herval
herval / santas.rb
Created April 6, 2010 20:50
Perl-ish solution for the Secret Santas Ruby Quiz (http://rubyquiz.com/quiz2.html)
# Perl-ish solution for the Secret Santas Ruby Quiz (http://rubyquiz.com/quiz2.html)
santas = "Luke Skywalker <[email protected]>
Leia Skywalker <[email protected]>
Gus Portokalos <[email protected]>
Toula Portokalos <[email protected]>
Bruce Wayne <[email protected]>
Virgil Brigman <[email protected]>
Lindsey Brigman <[email protected]>
".split("\n")
@herval
herval / gist:951054
Created May 2, 2011 01:03
Parsing Facebook's signed_request (in ruby)
def parse_data
# This is a typical set of parameters passed by Facebook
# Parameters: {"signed_request"=>"vsSe9NNeyqom0hAtGyb2L9scc3-aNbY5Xb25EW55LpE.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEzMDA3NzAwMDAsImlzc3VlZF9hdCI6MTMwMDc2NDg2Niwib2F1dGhfdG9rZW4iOiIxNzE2MDQwOTI4NjgwNTd8Mi4xQnBWNm5mU2VXRm5RT0lOdzltNWFRX18uMzYwMC4xMzAwNzcwMDAwLTE1MjAwMzkxfEFpNXctc2t4WlJyVUd1ZzZvOU95aDZBQmdSZyIsInVzZXIiOnsiY291bnRyeSI6InVzIiwibG9jYWxlIjoiZW5fVVMiLCJhZ2UiOnsibWluIjoyMX19LCJ1c2VyX2lkIjoiMTUyMDAzOTEifQ"}
# If we have the signed_request parameters, stash them away
session[:signed_request] = params[:signed_request] if params[:signed_request]
encoded_user_data = session[:signed_request]
return if encoded_user_data.blank?
@herval
herval / gist:2044137
Created March 15, 2012 13:13
My .bash_profile prompt
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
# <rvm_ruby@gemset> (<git branch, if in a git folder>) @ <current path in disk>
PS1='\[\e[0;32m\]$(~/.rvm/bin/rvm-prompt i v g) $(parse_git_branch)\[\e[m\] @ \[\e[1;34m\]\w\[\e[m\] \[\e[m\]
\[\e[1;32m\]\$ \[\e[m\]\[\e[m\] '
curl -i -H "Accept: application/json" -X POST -d "title=<bug title>&access_token=<your access token>" https://api.github.com/repos/<username>/<your repo>/issues
@herval
herval / each_hash_inject.rb
Created September 25, 2012 21:45
Comparing each, Hash[] and inject performance
require 'benchmark'
runs = 1000
original_data = {}
1000.times do |t| # 1000 depts with 100 guys each
original_data["dept_#{t}"] = (1..100).to_a
end
def employee_name(id)
class Entity < Struct.new(:name, :ratings)
end
@gamers = [
Entity.new('Lisa', {
'Prince of Persia' => 2.5,
'Doom' => 3.5,
'Castle Wolfenstein' => 3.0,
'Rise of the Triad' => 3.5,
'Commander Keen' => 2.5,
@herval
herval / rds_to_docker.md
Last active June 4, 2024 13:30
Moving a Postgres db from RDS to a Docker container

Make a backup from RDS

pg_dump -h <rds host> -p 5432 -F c -O -U <rds user> <db name> > db.dump

Restore the backup into a Docker container

docker run --rm --interactive --link <postgres container id>:postgres --volume $PWD/:/tmp/ postgres:latest /bin/bash -c 'pg_restore --verbose --clean --no-acl --no-owner -h "$POSTGRES_PORT_5432_TCP_ADDR" -p "$POSTGRES_PORT_5432_TCP_PORT" -U postgres -d <db name> /tmp/db.dump'