Skip to content

Instantly share code, notes, and snippets.

View arthuralvim's full-sized avatar

Arthur Alvim arthuralvim

View GitHub Profile
@arthuralvim
arthuralvim / ffmpeg.txt
Created April 8, 2015 20:11
Utilizando o FFMPEG para gerar gifs.
ffmpeg -t 10 -ss 00:00:08 -i video.mp4 -loop 0 -vf "transpose=1" -s 240x320 output.gif
convert -layers Optimize output.gif output-small.gif
ffmpeg -t 10 -ss 00:00:10 -i video2.mp4 -loop 0 -s 320x240 output2.gif
convert -layers Optimize output2.gif output2-small.gif
@arthuralvim
arthuralvim / add_ssh_key.sh.
Created April 9, 2015 13:41
Adicionando Chave SSH
cat ~/.ssh/id_rsa.pub | ssh root@your.ip.address "cat >> ~/.ssh/authorized_keys"
@arthuralvim
arthuralvim / choices_enum.py
Last active August 29, 2015 14:19
The way I organize my choices on my Django Projects.
class ChoicesEnum(object):
@classmethod
def choices(cls):
descriptions = cls.get_descriptions()
keys = descriptions.keys()
attrs = cls.get_atributes(keys)
return tuple([(attrs[k], descriptions[k]) for k in keys])
@classmethod
@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 / anime.py
Created April 21, 2015 21:43
Uma classe em Python para baixar os animes do site http://www.animesproject.com.br.
from bs4 import BeautifulSoup
import urllib2
import re
class Anime2MP4(object):
anime_zero_url = 'http://www.animesproject.com.br/serie/885/2162/Death-Parade-Episodio-00' # noqa
anime_url_format = 'http://www.animesproject.com.br/playerv52/player.php?a=0&0={0}&1={1}' # noqa
def build_episode_url(self, url_parameters):
@arthuralvim
arthuralvim / hidroweb.py
Created April 26, 2015 00:24
Para baixar os arquivos de texto sobre as chuvas das estações meteorológicas. http://hidroweb.ana.gov.br/
# -*- coding: utf-8 -*-
"""
Hidroweb
http://hidroweb.ana.gov.br/
Algumas bibliotecas terceiras deverão ser instaladas.
pip install requests
pip install beautifulsoup4
@arthuralvim
arthuralvim / itertools_study.py
Created May 14, 2015 11:44
Estudo sobre o itertools.
from itertools import permutations
from itertools import combinations
from itertools import combinations_with_replacement
@arthuralvim
arthuralvim / aws_file.py
Created June 15, 2015 04:32
Working with files in AWS S3
from boto.s3.connection import S3Connection
from boto.s3.key import Key
# Get connection using Amazon secret and access keys
conn = S3Connection('<aws secret key>', '<aws access key>')
# Get the bucket with name 'bucketname'
bucket = conn.get_bucket('bucketname')
# Get the key reference to file 'picture.jpg'
@arthuralvim
arthuralvim / signature_upload_to_s3.py
Created June 18, 2015 18:49
Conseguindo assinatura do S3 para enviar arquivos via PUT direto do cliente.
# -*- coding: utf-8 -*-
from django.conf import settings
from django.http import JsonResponse
from hashlib import sha1
import base64
import hmac
import time
import urllib
@arthuralvim
arthuralvim / download.sh
Created July 6, 2015 18:01
Download private videos on Youtube that needs authentication.
pip install youtube-dl
youtube-dl --username xxxxxxxx --password xxxxxxxx --twofactor XXXXXX "https://www.youtube.com/watch?v=xxxxxxx"