Skip to content

Instantly share code, notes, and snippets.

View arthuralvim's full-sized avatar

Arthur Alvim arthuralvim

View GitHub Profile
@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 / s3cmd_sync.sh
Last active September 1, 2015 20:44 — forked from niraj-shah/s3cmd_sync.sh
Downloading files from S3.
# Installation
wget -O- -q http://s3tools.org/repo/deb-all/stable/s3tools.key | sudo apt-key add -
sudo wget -O/etc/apt/sources.list.d/s3tools.list http://s3tools.org/repo/deb-all/stable/s3tools.list
sudo apt-get update && sudo apt-get install s3cmd
# Configuration
s3cmd --configure
@arthuralvim
arthuralvim / contador_prefixos.py
Created April 13, 2015 13:59
Uma palavra (uma cadeia de caracteres, ou string) s1 é prefixo de uma outra palavra s2, se as primeiras letras de s2 formam a palavra s1. Por exemplo ’ti’ é prefixo de ’tia’, mas não é de ’Tinha’. Por outro lado, a palavra vazia ’’ é prefixo de todas as palavras. Considere o seguinte texto. texto = ’Tinha tanta tia tantã Tinha tanta anta antiga …
# -*- coding: utf-8 -*-
from collections import Counter
texto = 'Tinha tanta tia tantã Tinha tanta anta antiga, Tinha tanta anta que era tia Tinha tanta tia que era anta'
class ContadorPrefixos(object):
def __init__(self, prefixos, corpus):
@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 / monthyearfield.py
Last active December 16, 2015 23:59 — forked from yashh/monthyearfield.py
A MonthYearWidget forked from yashh/monthyearfield.py .
from django import forms
import datetime
class MonthYearWidget(forms.MultiWidget):
"""
A widget that splits a date into Month/Year with selects.
"""
@arthuralvim
arthuralvim / setas.css
Created November 2, 2013 20:25
Arrows without images, only CSS. (Cross Browser) Setas sem usar imagem via CSS. (pt-br)
.seta{
width: 0;
height: 0;
}
.seta.cima {
border-left: 10px solid transparent;
border-right: 10px solid transparent;
border-bottom: 10px solid #aaa;
}
@arthuralvim
arthuralvim / bootstrap.py
Created December 21, 2013 02:48
A virtualenv bootstrap script for a generic project in python.
# -*- coding: utf-8 -*-
import virtualenv, textwrap
output = virtualenv.create_bootstrap_script(textwrap.dedent("""
import os, subprocess
import urllib2
# YOUR REPO URL ex:
REPO = 'https://github.com/arthuralvim/dj-kickstart.git'
@arthuralvim
arthuralvim / megasena.py
Created December 31, 2013 14:12
Megasena Pythônica.
import random; random.sample(range(1,61),6)