Skip to content

Instantly share code, notes, and snippets.

@villares
villares / anonymize-pdf-annotations.md
Last active December 17, 2024 01:44
Erase name/title from PDF annotations
@villares
villares / optical_flow.py
Last active November 7, 2024 02:36
OpenCV Optical Flow + py5
# https://docs.opencv.org/4.x/d4/dee/tutorial_optical_flow.html
import py5
import numpy as np
import cv2 # opencv-python
cap = None
py5_img = None
prvs_frame = None
reduced_size = 600, 400
@villares
villares / open-meteo-example.py
Last active October 29, 2024 18:31
Weather stuff
# from https://open-meteo.com/en/docs#latitude=-23.5475&longitude=-46.6361&hourly=temperature_2m,rain
import openmeteo_requests # pip install openmeteo-requests
import requests_cache # install requests-cache
import pandas as pd # install pandas
from retry_requests import retry # install retry-requests
# Setup the Open-Meteo API client with cache and retry on error
cache_session = requests_cache.CachedSession('.cache', expire_after = 3600)
@villares
villares / tetris_for_pyp5js.py
Created October 6, 2024 14:16
Porting my tetris from py5 to pyp5js
"""
This is quick adaptation from my py5 imported mode sketch at:
https://abav.lugaralgum.com/sketch-a-day/#sketch_2024_07_09
Use arrows to play - up to rotate, space bar to restart.
What changed: py5pjs didn't have random_choice, so I had to import it, and
in pyp5js the arrow key constants are different ARROW_LEFT and not LEFT, etc.
"""
@villares
villares / my_hackmd.py
Last active October 1, 2024 20:35
Hacky HackMD API helper in Python
"""
Usage:
from my_hackmd import API
api = API(your_access_token) # get one at https://hackmd.io/settings#api (please don't publish it in your repo!)
user_notes = api.get_note_list()
new_note_data = api.create_note(
title="My Ha",
content="# Ha\nhahaha",
@villares
villares / taichi_py5.py
Created August 3, 2024 15:27
taichi + py5 failure (taichi needs the main thread)
import taichi as ti
import taichi.math as tm
import py5
#ti.init(arch=ti.gpu)
ti.init()
@ti.func
def complex_sqr(z): # complex square of a 2D vector
return tm.vec2(z[0] * z[0] - z[1] * z[1], 2 * z[0] * z[1])
@villares
villares / fading_sketch_template.py
Last active September 29, 2024 18:48
fading screensaver-like sketch show
"""
You'll need py5 and a use the run_sketch tool or Thonny + thonny-py5mode
to run this py5 "imported mode" style sketch. Learn more at py5coding.org
I will run on full screen. Click on screen and press ESC to exit.
Adjust speed by changing the time_per_image variable in milliseconds.
"""
time_per_image = 3000 # milliseconds
fade_time = 500 # actually fade in + fade out will be double this
@villares
villares / animated_image_show.py
Last active July 26, 2024 23:25
Show images or SVGs from a folder named 'data' next to your py5 imported mode script.
"""
You'll need py5 and a use the run_sketch tool or Thonny + thonny-py5mode
to run this py5 "imported mode" style sketch. Learn more at py5coding.org
Add images or SVGs to a folder named 'data' next to your animated image show script.
It will run on full screen. Click on screen and press ESC to exit.
Adjust speed by changing the time_per_image variable in milliseconds.
Beware py5 might be unable to load some SVGs... an error message will be printed.
This version will not try to scale images to fit the screen.
@villares
villares / mapas_sesc_grupo_de_Estudo.ipynb
Last active July 11, 2024 18:41
Mapa das sorveterias - Grupo de Estudos em Python - Sesc Av. Paulista - Based on work by Lisa-Ho: https://github.com/Lisa-Ho/small-data-projects/blob/main/2023/2307-gelaterias/gelaterias-map.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@villares
villares / truchet.md
Last active March 12, 2024 02:49
Elementos para criar Truchet Tiles https://en.wikipedia.org/wiki/Truchet_tiles com py5 #Truchet #Pyhon #py5 #ProgramaçãoCriativa

Truchet tiles

Vídeos

Os exemplos mais abaixo neste Gist são a inspiração para 3 videozinhos sobre Azulejos de Truchet com py5 (usando py5 imported mode no Thonny)

Se você gostar, considere apoiar a instância do PeerTube do LHC que hospeda os vídeos https://peertube.lhc.net.br e me apoiar (que fiz esse material) https://liberapay.com/villares