Skip to content

Instantly share code, notes, and snippets.

View lucasdavila's full-sized avatar
🌈

Lucas D'Avila lucasdavila

🌈
  • SC, Brasil
View GitHub Profile
@lucasdavila
lucasdavila / password_strength.rb
Created January 16, 2013 03:16
Password strength with regex in Ruby
# example of using lookahead assertion to test password strength
# test if a given string contains at least a lowercase letter, a uppercase, a digit, a special char and 8+ chars
strong = "123ABCabc-"
strong[/^(?=.*[a-zA-Z])(?=.*[0-9])(?=.*[\W]).{8,}$/]
# test if a given string contains at least a lowercase letter, a uppercase, a digit and 8+ chars
medium = "123ABCabc"
medium[/^(?=.*[a-zA-Z])(?=.*[0-9]).{8,}$/]
@lucasdavila
lucasdavila / lazy_fixtures.rake
Created January 12, 2013 17:49
Dumps database records into test fixtures.
namespace :db do
namespace :fixtures do
# by default it task load records from development env,
# to change send the RAILS_ENV var, eg: $ rake db:fixtures:dumps RAILS_ENV=production
desc 'dumps the database data into test fixtures.'
task :dumps => :environment do
sql = "SELECT * FROM %s"
skip_tables = ['schema_info', 'schema_migrations']
@lucasdavila
lucasdavila / install_pg-8.2.sh
Last active May 9, 2022 20:38
Homebrew formula for install postgresql-8.2 on mac os x
brew install https://gist.github.com/raw/4355097/postgresql82.rb --no-python --no-perl --without-ossp-uuid
# to execute this gist, just run the line bellow in terminal
# \curl -L https://gist.github.com/raw/4355097/install_pg-8.2.sh | sh
@lucasdavila
lucasdavila / object_join.js
Last active February 24, 2023 17:40
Joining javascript key-value objects as string.
Object.prototype.join = function(glue, separator) {
var object = this;
if (glue == undefined)
glue = '=';
if (separator == undefined)
separator = ',';
return Object.keys(object).map(function (key, value) { return [key, value].join(glue); }).join(separator);
@lucasdavila
lucasdavila / force_dropdb
Created November 22, 2012 16:22
Force postgresql dropdb without restarting
# first get the ids from the process that still connected to db
$ psql -d db_name -c "select procpid from pg_stat_activity where datname='db_name' and waiting is not false;"
# after, kill the process that still connected to db
$ kill procpid_returned_from_query
$ dropdb db_name
@lucasdavila
lucasdavila / query_from_utf8_to_latin1.sh
Created November 21, 2012 21:25
Simple postgresql script conversion from utf8 to latin1
# first convert the utf-8 script to latin1
iconv -f utf-8 -t latin1 file.sql > __latin1-file.sql
# after execute the latin1 file
psql -d db-name -a -f __latin1-file.sql
@lucasdavila
lucasdavila / pt-BR.yml
Created November 20, 2012 19:55
i18n for simple_form labels and placeholders
# rails_app/config/locales/pt-BR.yml
'pt-BR':
simple_form:
labels:
form_name:
name: 'Nome'
city: 'Cidade'
placeholders:
@lucasdavila
lucasdavila / 1_Gemfile
Created November 12, 2012 23:24
xpath in ruby with nokogiri
source "http://rubygems.org"
gem 'nokogiri'
@lucasdavila
lucasdavila / account_name_in_action_mailer.rb
Created November 12, 2012 15:41
Setting up account name in action_mailer
# /config/initializers/setup_mail.rb
# ...
ActionMailer::Base.default :from => "Company Name <no-reply@yourcompany.com>"
@lucasdavila
lucasdavila / 0_about
Created October 16, 2012 14:27
asynchronous twitter bootstrap typeahead
Typeahead is a javascript plugin from Twitter Bootstrat [1] that allows quickly creating typeaheads with any
form text input element.
[1] http://twitter.github.com/bootstrap/javascript.html#typeahead