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 / 1_ubuntu_terminal_command
Last active February 21, 2024 16:26
Installing Source Code Pro fonts in ubuntu
# to execute this gist, run the line bellow in terminal
\curl -L https://raw.github.com/gist/3875946/install_source_code_pro.sh | sh
@lucasdavila
lucasdavila / fixup.txt
Last active December 20, 2023 12:00
Fixing mac os yosemite issue "bash: fork: Resource temporarily unavailable"
# see the current limits
$ sysctl -a | grep maxproc
# increase it
$ sudo sysctl -w kern.maxproc=xxxx
$ sudo sysctl -w kern.maxprocperuid=xxx
# run at startup
$ sudo vim /etc/sysctl.conf
@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 / 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 / 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 / example_use_gravatar_image_tag.py
Last active July 7, 2021 01:06
Gravatar em 3 linhas com python
print gravatar_image_tag('some.gravatar.email@foo.com', 32, {'class' : 'avatar', 'alt' : 'your gravatar'})
<img src="http://www.gravatar.com/avatar/3b4d33514d78047bf86307ab354658df?size=32" alt="your gravatar" class="avatar" />
@lucasdavila
lucasdavila / dynamic_form_for_hstore_attributes_in_rails.html.erb
Created September 13, 2012 15:54
Dynamic form for hstore attributes in rails
<%= simple_form_for @product do |f| %>
<%= f.simple_fields_for :attributes do |d| %>
<% f.object.attributes.try(:each) do |key, value| %>
<%= d.input key, :input_html => {:value => value } %>
<% end %>
<% end %>
<% end %>
@lucasdavila
lucasdavila / ssh_config
Created April 4, 2019 18:25
Using multiple ssh keys with git
# This gist will help you using multiple github or bitbucket accounts in the same machine.
# 1. create a .ssh/config file, with this content:
# use "bitbucket-ieducativa" as git remote host, to use this custom key
Host bitbucket-ieducativa
HostName bitbucket.org
User git
IdentityFile ~/.ssh/bitbucket-ieducativa
IdentitiesOnly yes
@lucasdavila
lucasdavila / conf_pg_bouncer_ubuntu.txt
Created August 11, 2011 01:51
PostgreSQL connection pooling com pgbouncer
Um método para otimizar as conexões com o banco de dados é estabelecer um pool de conexão, caso sua aplicação
não faça isto nativamente você pode usar alguma ferramenta como o pgbouncer [1].
O principal motivo para manter um pool de conexões ativas com o banco de dados, é que o processo
de criar uma conexão com o banco de dados e posteriormente elimina-la gasta recursos e leva algum tempo,
o que pode ser pouco para uma conexão, mas para apps onde a conexão / desconexão ocorre com muita
frequência (como em aplicações web) manter um pool de conexões ativas, pode economizar algum tempo
entre cada solicitação.
Um pool de conexões trabalha de maneira muito simples, após a aplicação criar e usar a conexão com o
@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