Skip to content

Instantly share code, notes, and snippets.

View douglasmiranda's full-sized avatar
👽

Douglas Miranda douglasmiranda

👽
  • Earth, Brazil
View GitHub Profile
@douglasmiranda
douglasmiranda / gist:2029087
Created March 13, 2012 14:22
Python: Get the parent dir relative to the current python file. # Using in Django, maybe need to refactor.
from os.path import abspath, join, dirname
PROJECT_ROOT_PATH = abspath(join(dirname(abspath(__file__)), '..'))
@douglasmiranda
douglasmiranda / gist:2024893
Created March 12, 2012 21:45
Django: Proposta de organização do settings no projeto. (local, teste e produção)
Na empresa que trabalho, nós temos ambientes de desenvolvimento, teste e producao.
Cada ambiente tem um settings específico onde importamos as configuracões comuns
a todos de um settings base e mudamos as configurações específicas,
como banco de dados por exemplo.
A estrutura de diretório fica mais ou menos assim:
- Projeto
--- settings
------ __init__.py
@douglasmiranda
douglasmiranda / extract_pks.py
Created March 6, 2012 22:13
Django: extract pks from a db object in to a list of integers
def extract_pks(objects):
return [int(value.get('pk')) for value in objects.values('pk')]
@douglasmiranda
douglasmiranda / gist:1973844
Created March 4, 2012 16:50
Install PIL with JPEG and PNG support in WebFaction. Just in case the "pip install PIL" not solve the problem in your shared host.
# Download
wget http://effbot.org/media/downloads/PIL-1.1.7.tar.gz
tar zxf PIL-1.1.7.tar.gz
cd PIL-1.1.7
# Edit setup file
vim setup.py
# Set the following variables
JPEG_ROOT = '/usr/lib64','/usr/include'
ZLIB_ROOT = '/lib64','/usr/include'
@douglasmiranda
douglasmiranda / gist:1963967
Created March 3, 2012 02:48
Unix tar gzip a folder then unzip it - ssh
tar -cvzf <filename>.tar.gz <folder-name>
tar -xvzf <filename>.tar.gz
@douglasmiranda
douglasmiranda / gist:1963350
Created March 3, 2012 01:22
Example: Create another branch to fix a bug in master, while another branch was not merged/finalized, and merge it with master and delete the temporary branch
git checkout -b issue2
# after fix
git add YOUR_FILES_HERE
git commit -m "fixing #issue2"
git checkout master
git merge issue2
git branch -d issue2
@douglasmiranda
douglasmiranda / gist:1913266
Last active September 5, 2019 09:29
MySQL - Export and Import free of troubles with Foreign Key Restriction From innoDB Tables
# Export and pack
mysqldump -uUSER -pPASSWORD database_name --compact --host=HOST_IP_ADDRESS | gzip > mysqlbackup.sql.gz
# Unpack
gunzip mysqlbackup.sql.gz
# Importing free of troubles with Foreign Key Restriction From innoDB Tables
mysql -uUSER -pPASSWORD
# MySQL terminal
mysql> CREATE DATABASE database_name CHARACTER SET utf8 COLLATE utf8_general_ci;
@douglasmiranda
douglasmiranda / .htaccess
Created November 30, 2011 15:28
Diretivas .htaccess para cache
# 1 ANO
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
# 1 SEMANA
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 2 DIAS
<FilesMatch "\.(xml|txt|css|js)$">
@douglasmiranda
douglasmiranda / fix_error_lxml.sh
Created October 7, 2011 22:08
Fix error when try to install/upgrade splinter on ubuntu.
# I don't know why, but everytime than i try to install or update splinter in my pc
# i get this error: src/lxml/etree_defs.h:9:31: fatal error: libxml/xmlversion.h
# anyway i try to discover why, for while this is a solution:
# install/upgrade libxml2-dev and libxslt-dev
sudo apt-get install libxml2-dev libxslt-dev
@douglasmiranda
douglasmiranda / nth_child_odd_even.css
Created October 7, 2011 16:39
Aplicar css em elementos pares em ímpares.
/* Example */
/* Par */
ul li:nth-child(even){
background:#fff;
}
/* Ímpar */
ul li:nth-child(odd){
background:#000;