Skip to content

Instantly share code, notes, and snippets.

View villares's full-sized avatar
💥

Alexandre B A Villares villares

💥
View GitHub Profile
View boids_numpy.py
# -----------------------------------------------------------------------------
# From Pytnon to Numpy
# Copyright (2017) Nicolas P. Rougier - BSD license
# More information at https://github.com/rougier/numpy-book
# -----------------------------------------------------------------------------
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.path import Path
from matplotlib.animation import FuncAnimation
from matplotlib.collections import PathCollection
@villares
villares / dados.md
Created November 9, 2023 01:03
Lê uma planilha de Excel e altera um arquivo de Word
@villares
villares / exemplo.py
Created November 9, 2023 00:30
Exemplo PDF multiplas folhas (e depois overlay)
View exemplo.py
import py5
import random # import sample, shuffle, seed
NUM_PAGES = 10
s = 0.71 # fator de escala 1 => 356 x 275 queremos 252 x 195
rs = 1 # random seed
save_pdf = False
@villares
villares / Aqui_SP-OSMNX.py
Created August 25, 2023 13:30
Experimentos com osmnx
View Aqui_SP-OSMNX.py
import pickle
from pathlib import Path
import osmnx as ox
from download_from_gdrive import download_from_gdrive
# configure the place, network type, trip times, and travel speed
place = {"city": "São Paulo", "country": "Brazil"}
network_type = "walk"
@villares
villares / export_single_png.py
Created August 18, 2023 14:24
Export PNG with transparent background
View export_single_png.py
# using py5 imported mode (https://py5coding.org to learn more)
def setup():
size(600, 600) # drawing size
output_canvas = create_graphics(width, height)
background(255, 0, 0) # you can turn this off, this won't be recorded!
begin_record(output_canvas) # starts recording
# output_canvas.clear() # clears pixels (not necessary in this case)
color_mode(HSB) # this needs to be inside the recording!
no_stroke() # same as with the color_mode, has to be brought here
@villares
villares / pygame_jukebox_tosca.py
Last active August 19, 2023 16:16
Tocadores de arquivos mp3 com pygame
View pygame_jukebox_tosca.py
# TODO quando som termina, retomar não recomeça
# (mudar para próximo som autmaticamente?)
from pathlib import Path
import pygame
# Procura arquivos .mp3 na mesma pasta
folder = Path.cwd() # se quiser pode trocar por Path('/caminho/pasta/')
audio_files = [fp for fp in sorted(folder.iterdir())
if fp.name.lower().endswith('.mp3')]
@villares
villares / fitz-zine-impostion.py
Last active September 10, 2023 14:30
Faz a "imposição" de páginas de um zine em um A3
View fitz-zine-impostion.py
"""
Make a PDF A3 zine combining 8 pages from a source PDF
WIP: I'd like to have an option for the 9th page (index=8) to be a poster in the backside or not.
-------------------------------------------------------------------------------
License: GNU GPL V3
(c) 2023 Alexandre Villares
Based on https://github.com/pymupdf/PyMuPDF-Utilities/blob/master/examples/combine-pages/combine.py
(c) 2018 Jorj X. McKie
@villares
villares / mp4_to_gif.py
Last active July 31, 2023 06:26
A bare bones mp4 to gif converter Python CLI script
View mp4_to_gif.py
#! /home/villares/thonny-python-env/bin/python3
"""
MP4 to GIF animation. Depends on moviepy and ffmpeg.
"""
import argparse
from moviepy.editor import *
parser = argparse.ArgumentParser(prog='Create a GIF animation from a MP4 file. Depends on moviepy and ffmpeg.')
parser.add_argument('-i', '--input', help='Input .mp4 file.')
@villares
villares / image_pickle_concept.py
Last active July 29, 2023 04:43
monkey patching a Py5Image to allow pickling
View image_pickle_concept.py
import pickle
import py5
from py5 import Py5Image
old_new = Py5Image.__new__
def new_new(self, *args):
if args:
return old_new(self, *args)
@villares
villares / a.svg
Created July 15, 2023 22:27
SVG File that breaks Processing 4.2 parsing
View a.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.