Skip to content

Instantly share code, notes, and snippets.

View villares's full-sized avatar
💥

Alexandre B A Villares villares

💥
View GitHub Profile
@villares
villares / multiple_page_pdf_py5_imported_mode.py
Last active January 26, 2024 15:21
Template for generating a multi-page PDF with py5 (and a bonus PDF "overlay" script)
View multiple_page_pdf_py5_imported_mode.py
"""
An example/template for generating a mutiple page PDF using py5.
Imported mode style - You'll need to use the thonny-py5mode plug-in or the sketch_runner tool
CC0 / Public Domain dedication - by Alexandre B A Villares
"""
NUM_PAGES = 10
s = 0.71 # scale factor 1 => 356 x 275 trying 252 x 195
rs = 1 # starting random seed
@villares
villares / make_a_box.py
Created January 22, 2024 19:26
Caixinha com corte laser, versão com py5
View make_a_box.py
import py5
fator_escala = 3.78 * 50 / 189
NOME = "caixa_flex-v1" # Precisa ser cortado 2x! só desenha "meia caixa"
W, H, P = 200, 120, 50 # dimensões
R = 30 # raio
XO, YO = 50, 50 # offset do desenho na página
def setup():
@villares
villares / silly_set_gol.py
Last active November 28, 2023 18:01
silly game of life with Processing and Python, using py5
View silly_set_gol.py
# You *need* to install py5!
# Instructions at https://py5.ixora.io/
from collections import Counter
from random import randint
import py5
cell_size = 4
current_board = set()
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 / download_images_modify_files.py
Last active November 13, 2023 00:10
Backup HackMD.io Notes
View download_images_modify_files.py
"""
Downloads images from my notes at HackMD.io.
Creates new MD files with relative path image links.
Uses the links from the 'notes-backup' files downloaded with
download_notes.py (run it first)
I was skipping images hosted from my dreamhost account
but decided to download them too.
"""
@villares
villares / dados.md
Created November 9, 2023 01:03
Lê uma planilha de Excel e altera um arquivo de Word
@villares
villares / image_viewer.py
Last active September 25, 2023 00:25
Tweaking a PySimpleGUI Image viewer example
View image_viewer.py
#!/home/villares/miniconda3/bin/python
"""
Based on: PytSimpleGUI demo for displaying any format of image file.
2022 - Alexandre B A Villares - I just added some PNG metadata viewing
for use with villares.helpers.save_png_with_src()
github.com/villares/villares/
2023 - Alexandre B A Villares - Moved from os.path to pathlib.Path
and added folders to the list!
@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 / 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 / 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')]