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: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: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 / 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: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 / 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:2030055
Created March 13, 2012 17:28
Shell: Deletar arquivo com nome inválido. Problema ao deletar arquivos acentuados pelo terminal.
# por exemplo, o nome do arquivo é: zéca_silva.jpg
# basta utilizar o wildcard " * "
rm -rf z*ca_silva.jpg
# porém se houver mais arquivos que enquadrem no padrão z[QUALQUER OUTRA COISA]ca_silva.jpg vai ser deletado tbm, então use com cuidado.
@douglasmiranda
douglasmiranda / remove_files.py
Created March 18, 2012 19:19
Detecting and removing all files that have invalid file names (not ascii names), that cannot be renamed or removed using ssh, in certain posix servers.
"""
Detecting and removing all files that have invalid file names (not ascii names),
that cannot be renamed or removed using ssh, in certain posix servers.
"""
import glob
import os
def isascii(s):
return all(ord(c) < 128 for c in s)
@douglasmiranda
douglasmiranda / functions_1.py
Created March 18, 2012 20:03
Django Filebrowser: Modifing the convert_filename function, to create a file name free of undesired chars.
def convert_filename(value):
"""
Convert Filename.
"""
def newname(text, encoding=None):
from unicodedata import normalize
if isinstance(text, str):
text = text.decode(encoding or 'ascii')
clean_text = text.strip().replace(' ', '-')
@douglasmiranda
douglasmiranda / gist:2362332
Last active October 3, 2015 01:27
Solving troubles with PIL ( Python Imaging Library ). When I'm installing it on my ubuntu. (Support jpeg)
# 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
# Create symbolic links to libs
sudo ln -s /usr/lib/x86_64-linux-gnu/libfreetype.so /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/
sudo ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib/
@douglasmiranda
douglasmiranda / app_launcher.desktop
Created April 19, 2012 03:18
create a launcher to add in unity panel ubuntu
[Desktop Entry]
Version=2
Type=Application
Terminal=false
Icon[pt_BR]=ICON_PATH
Name[pt_BR]=NAME
Exec=EXCEC_PATH
Name=NAME
Icon=ICON_PATH