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
  • 17:06 (UTC -03:00)
View GitHub Profile
from PIL import Image
# The main image
img_b = Image.open("tumblr_nv07r7pHRh1txa2z2o1_500.png")
# The potato seal image
img_l = Image.open("avatar_3ee88102fcff_128.png")
# Area to paste potato seal
area = (img_b.size[0] - img_l.size[0],
img_b.size[1] - img_l.size[1],
/* OBMEP 2015 - 2ª Fase - Data */
function sum_digit(number) {
var result = 0;
while (number) {
result += number % 10;
number = Math.floor(number / 10);
}
return result;
}
# OBMEP 2015 - 2ª Fase - Data
def sum_digit(number):
result = 0
while number:
result, number = result + number % 10, number // 10
return result
def reverse_number(number):
@beatorizu
beatorizu / download_cleaner.py
Last active May 13, 2017 19:23
FTP download files cleaner
"""Clean downloaded files
Usage:
download_cleaner.py <ftpconfig_dir>
Arguments:
<ftpconfig_dir> Path to ftpconfig directories
Options:
-h, --help Show this screen
from pandas import DatetimeIndex, read_excel
# Essa planilha só tem um folha então vai retorna o DataFrame
sheets = read_excel('./BulletinSearch.xlsx')
# Pode agrupar para fazer max, min, sum e count
count_impact = sheets.groupby(by='Impact').count()
# Para agrupar datas tem que criar um obj DatetimeIndex
# Nesse DataFrame os dados já são diários, mas se fossem dados horários
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)
def find_nearest_point(latitude, longitude, l_latitude, l_longitude):
"""
This function find the index of the nearest value to the latitude and longitude values int the l_latitude and
l_longitude lists.
Parameters
----------
latitude: float
longitude: float
l_latitude: list
@beatorizu
beatorizu / find_git.py
Last active June 2, 2019 16:39
Python scripts with regex powers to find files XD
#!/opt/anaconda2/envs/py360/bin/python
from datetime import datetime
from json import dump
from os import walk
from os.path import join
import logging
import re
def search_dir(root, target='.git', pattern=re.compile(r'^\.git|[\w\d\s!@#$%^&*()_+\-=\[\]{};\':"\\|,<>\/?]+$'),
# Para somar no eixo 1 de três em três
txprec[::3].sum(axis=1)
@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)])