Skip to content

Instantly share code, notes, and snippets.

@renzon
renzon / some_module.py
Created Mar 1, 2019
Flask Cli Example
View some_module.py
from flask.cli import AppGroup
user_cli = AppGroup('users', help='Manage users')
@user_cli.command('create_admin', help='Create a user with Admin role on database')
@click.option('--name', prompt='User name')
@click.option('--email', prompt='User email')
@click.option('--password', prompt='User password', hide_input='True', confirmation_prompt=True)
def create_admin(name, email, password):
...
View string_n_string.py
from itertools import chain
def string_n_string(s, n):
for _ in range(n):
even = (char for i, char in enumerate(s) if i % 2 == 0)
odd = (char for i, char in enumerate(s) if i % 2 != 0)
s = ''.join(chain(even , odd))
return s
View fat_escopo_dinamico.py
def fat(n):
i = 1
result = 1
def fat_iter():
nonlocal i, result
if i > n:
return
result *= i
i += 1
View fat_escopo_estatico.py
def fat(n):
def fat_iter(i, result):
if i > n:
return result
return fat_iter(i + 1, result * i)
return fat_iter(1, 1)
def test():
View sum_prod.py
from itertools import zip_longest
def sum_prod(iter, iter2):
return sum(map(lambda tpl: tpl[0] * tpl[1], zip_longest(iter, iter2, fillvalue=1)))
def test_sum_prod():
assert 0 == sum_prod([], [])
assert 2 == sum_prod([2], [])
View bolsa.py
import datetime
data = [
{
'C01_tipo_de_registro': 1, 'C02_numero_de_negocios_por_codigo_de_negociacao': 10,
'C03_natureza_da_operacao': 'C', 'C04_codigo_de_negociacao': 'AAAA3',
'C05_tipo_de_mercado': 'VIS', 'C06_tipo_da_transacao': 'NOR',
'C07_nome_da_sociedade_emissora': 'Aa Aa Aa', 'C08_especificacao': 'ON NM',
'C09_quantidade_do_negocio': 100, 'C10_1_preco_do_negocio': 3.5,
'C11_codigo_do_usuario_contraparte': 999, 'C12_prazo_de_vencimento': '',
@renzon
renzon / conc.py
Created Jun 24, 2018
Conc lines in file accordingly to condition
View conc.py
with open('seu_arquivo.txt', 'r', encoding='utf-8') as file:
new_line=[]
for line in file:
new_line.append(line)
if not # Aqui vai sua condiçao para concatenar com a(s) outra(s) linha(s):
print(''.join(new_line))
new_line=[]
if new_line:
print(''.join(new_line))
View soma.py
class Soma:
def soma(a, b, c=0):
return a+b+c
@renzon
renzon / soma.java
Last active Jun 4, 2018
Classe SOma
View soma.java
class Soma(){
int soma(int a, int b){
return a+b;
}
int soma(int a, int b, int c){
return a+b+c;
}
@renzon
renzon / matriz.py
Created May 8, 2018
Matrix Diagonal dominante
View matriz.py
>>> def eh_diagonal_dominante(matriz):
... for i, linha in enumerate(matriz):
... soma = sum(linha)
... item_diagonal = linha[i]
... if item_diagonal <= (soma - item_diagonal):
... return False
... return True
...
>>> eh_diagonal_dominante([
... [2, 1],