Skip to content

Instantly share code, notes, and snippets.

@arthuralvim
arthuralvim / unistr.py
Created July 8, 2015 03:56
About unicode and str in Python.
# unicode => human readable format
uni_text = u'café'
print type(uni_text)
print isinstance(uni_text, str)
print len(uni_text)
uni_str_convert = uni_text.encode('UTF-8')
# str => bytes
str_text = 'café'
@arthuralvim
arthuralvim / transition.py
Created July 28, 2015 15:22
Modelo para trabalhar com fluxos e transições.
# -*- coding: utf-8 -*-
import inspect
class TransitionObject(object):
"""
TransitionObject:
Uma classe para ajudar nas passagens de transições em fluxos.
@arthuralvim
arthuralvim / csv2djfixtures.py
Created August 19, 2015 21:05
Convert .csv to Django fixtures.
# -*- coding: utf-8 -*-
# requirements
# pip install unipath
# pip install python-decouple
from os.path import join
from unipath import Path
from decouple import config
import csv
from boto.s3.connection import S3Connection
conn = S3Connection('awskey', 'awssecret')
bucket = conn.get_bucket('awsbucket')
@arthuralvim
arthuralvim / rsync_example.sh
Last active September 30, 2015 15:24
Example of rsync call.
// v = verbose
// a = archive
// z = compress
// h = progress
rsync -vazh --dry-run --partial -e "ssh -p port" /path/to/local/files/ user@111.111.111.111:/path/to/remote/files/
rsync -vazh --dry-run --partial -e "ssh -p port" user@111.111.111.111:/path/to/remote/files/ /path/to/local/files/
@arthuralvim
arthuralvim / log_rotation.py
Created October 12, 2015 12:36
Understanding log rotation in Python.
import logging
from logging.handlers import RotatingFileHandler
LOG_FILENAME = "log_name.log"
LOG_LEVEL = logging.INFO
log = logging.getLogger("Notifier")
log.setLevel(LOG_LEVEL)
# Add the log message handler to the logger
@arthuralvim
arthuralvim / setter_exemplo.py
Created November 23, 2015 11:33
Estudando classes e properties.
# -*- coding: utf-8 -*-
class MyClass(object):
error_msgs = {
'integer': "This doesn't look like an integer."
}
def __init__(self, default=0, raise_errors=True):
@arthuralvim
arthuralvim / color-table.sh
Created January 17, 2016 15:00
Generates an 8 bit color table (256 colors) for reference purposes.
#!/bin/bash
# Generates an 8 bit color table (256 colors) for
# reference purposes.
# credits for Michael.
# http://bitmote.com/index.php?post/2012/11/19/Using-ANSI-Color-Codes-to-Colorize-Your-Bash-Prompt-on-Linux
function boxcolor {
printf "\033[48;5;$1m \033[m "
@arthuralvim
arthuralvim / copa_crocovix.py
Last active January 22, 2016 17:23
Sorteio dos integrantes da Copa Crocovix de Futebol de Vídeo Game.
# -*- coding: utf-8 -*-
from random import shuffle
from random import sample
def sortear_partidas(duplas):
while duplas:
dupla = sample(duplas, 2)
print dupla[0], 'x========x', dupla[1]
@arthuralvim
arthuralvim / human.py
Created February 23, 2016 06:58
Studying mock objects in Python.
# -*- coding: utf-8 -*-
class NoConnectionException(Exception):
def __init__(self, message=None):
super(NoConnectionException, self).__init__(message)
self.message = 'No connection!'