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 / 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;
@douglasmiranda
douglasmiranda / order_by_ignoring_0.sql
Created September 26, 2011 16:26
SQL ORDER BY ignoring fields filled with "0"
-- This problem happens when you try to order columns ASC
-- and you want to ignore the 0 values in the first results
SELECT `DATABASE_NAME`.*
FROM `TABLE_NAME`
ORDER BY
CASE WHEN `FIELD_FILL_WITH_0` in("", "0") THEN 1
ELSE 0 END, `FIELD_FILL_WITH_0_OR_ANY_OTHER_FIELD` ASC
@douglasmiranda
douglasmiranda / MySQLdb_virtualenv.sh
Created September 23, 2011 19:47
Fix error when try to install MySQLdb on virtualenv //I'm using Ubuntu
sudo apt-get build-dep python-mysqldb
pip install mysql-python