This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import timeit | |
ncache = 0 | |
cache = {} | |
def partition(number): | |
global cache, ncache | |
answer = {(number,), } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
def notas_total(valor): | |
notas = [100, 50, 20, 10, 5, 2, 1] | |
totais = [] | |
for idx, nota in enumerate(notas): | |
totais.append(0) | |
if valor > nota: | |
totais[idx] = int(valor / nota) | |
valor -= totais[idx] * nota |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
def decompor_decimal(num): | |
"""Decompoe um numero em sua representação decimal. """ | |
l = len(str(num)) | |
return ' + '.join([i.ljust(l - b, '0') for b, i in enumerate(str(num))]) | |
print(decompor_decimal(32477)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import with_statement | |
from itertools import chain | |
import datetime | |
import sys | |
import warnings | |
import time | |
import logging | |
import threading | |
import time as mod_time | |
from redis._compat import (b, basestring, bytes, imap, iteritems, iterkeys, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Implements semaphoro to control atomic blocks on file.""" | |
# by [email protected] | |
import os | |
import sys | |
import uuid | |
import time | |
import signal | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
def busca_noticias(url, limit=10, debug=False): | |
offset = 0 | |
while True: | |
urlget = url.format(limit=limit, offset=offset) | |
if debug: | |
print('#### GET: ' + urlget) | |
resp = requests.get(urlget).json() | |
for noticia in resp['ok']['noticias']: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def template(html, **params): | |
import jinja2 | |
env = jinja2.Environment(loader=FileSystemLoader('')) | |
def tojson(s): | |
import json | |
return json.dumps(s) | |
env.filters['tojson'] = tojson |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Fecha todas as janelas pelo nome.""" | |
from gi.repository import Gtk, Wnck | |
import os | |
Gtk.init([]) | |
screen = Wnck.Screen.get_default() | |
screen.force_update() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
"""Renomeia pastas de acordo com uma tag de um arquivo dentro da pasta.""" | |
# renomeia_pastas.py | |
import unicodedata | |
import glob | |
import os | |
def remove_accents(s): | |
"""Remove acentos de uma string.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# da_urllib.py | |
# by [email protected] | |
import urllib | |
def urldencode(params): | |
resp = {} | |
for item in params.split('&'): | |
if not item: |