Skip to content

Instantly share code, notes, and snippets.

View beatorizu's full-sized avatar
🤓
Focusing

beatorizu

🤓
Focusing
  • São José dos Campos, SP Brazil
  • 00:51 (UTC -03:00)
View GitHub Profile
reduce(lambda _, __: _ + __, valores)
@beatorizu
beatorizu / nested_dict.py
Created November 7, 2018 22:08
Convert values in nested dicts using python
from collections.abc import Mapping
# Recursive function to apply a func to nested dict
def map_nested_dicts(ob, func):
if isinstance(ob, Mapping):
return {key: map_nested_dicts(value, func) for key, value in ob.items()}
return func(ob)
@beatorizu
beatorizu / init.vim
Last active September 23, 2020 22:02
neovim config file
" Specify a directory for plugins
call plug#begin('~/.local/share/nvim/plugged')
" Colorizer A plugin to color colornames and codes
Plug 'chrisbra/Colorizer'
" vim-markdown-composer An asynchronous markdown preview plugin for Vim and Neovim
function! BuildComposer(info)
if a:info.status != 'unchanged' || a:info.force
if has('nvim')
@beatorizu
beatorizu / nan_if.py
Created August 31, 2018 18:43
Filtro para substituir o missing_value por nan
def nan_if(data, missing_value):
return np.where(data == missing_value, np.nan, data)
@beatorizu
beatorizu / .coveragerc
Created August 28, 2018 19:10
Configuração do Coverage
[run]
branch = True
[report]
exclude_lines=
if response.status_code == 404:
elif response.status_code == 503:
pragma: no cover
class ServiceUnavailable(Exception):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import facebook
class SimpleFacebook(object):
def __init__(self, oauth_token):
self.graph = facebook.GraphAPI(oauth_token)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from controller import simple_facebook
from unittest import mock, TestCase
class SimpleFacebookTestCase(TestCase):
@beatorizu
beatorizu / apply_format_df_columns.py
Created May 9, 2018 18:05
Aplicando formatos diferentes para cada coluna no DataFrame
# Aplicando formatos diferentes para cada coluna no DataFrame
df = DataFrame({'a':[7.7885], 'b': [1.989878968657576e-10]})
# out
# a b
# 0 7.7885 1.989879e-10
df.loc[:, 'b'] = df.loc[:, 'b'].map(lambda x: float('%.11f' % x))
df.loc[:, 'a'] = df.loc[:, 'a'].map(lambda x: float('%.2f' % x))
# out
@beatorizu
beatorizu / operacoes-eixo-intervalo.py
Last active June 10, 2018 21:27
Aplicar função de acordo com o eixo e cortes por intervalo
import numpy as np
data = np.random.rand(7, 3, 2)
op_dict = {'sum': np.sum, 'mean': np.mean, 'max': np.max, 'min': np.min}
def apply_function(func, data, step, axis=0, slice_=slice(None)):
sections = np.arange(step, data.shape[axis], step)
return np.array([func(d[slice_], axis=axis) for d in np.split(data, sections, axis=axis)])
# Para somar no eixo 1 de três em três
txprec[::3].sum(axis=1)