Skip to content

Instantly share code, notes, and snippets.

@flavioamieiro
flavioamieiro / NES_controller_PIO_polling.py
Created August 9, 2021 14:27
Reading an NES controller using RP2040's PIO
import time
import rp2
from machine import Pin
from ucollections import OrderedDict
led_1 = Pin(25, Pin.OUT)
@rp2.asm_pio(set_init=(rp2.PIO.OUT_LOW, rp2.PIO.OUT_LOW), push_thresh=8, autopush=True)
def read_NES_buttons():
{
"session1": "[[[0,25145],\"L' F2 D' F2 L2 F2 R2 U L2 U' F2 B R B2 F' L F' D B2 L'\",\"\"],[[0,27296],\"R' L B2 D2 R' U' F' B D U2 R' F2 R2 B2 L2 U2 B2 L' F2 R'\",\"\"],[[0,31612],\"D' B D' B' L F2 R D' F' R2 D B2 R2 D' F2 D B2 D2 L2\",\"\"],[[0,43915],\"F B2 D2 L B2 D2 L2 D2 R F2 R D2 F R2 D R F2 L U2 L2 B'\",\"\"],[[0,33840],\"U' L2 D' F2 L2 B2 U B2 F2 U' R2 L' B' L' D' L D' U' B' D2 R2\",\"\"],[[0,22367],\"F2 R2 D' L2 U' L2 B2 L2 D' F2 B D2 F' L B R' B2 R' D' R2\",\"\"],[[0,30773],\"L2 U L2 D2 R2 B2 U L2 U L2 U' L B R2 D U' F' D' R2 D U2\",\"\"],[[0,30421],\"F' D2 B2 R2 D2 L2 U L2 F2 L2 U2 F2 L' D' B D B' F' R2 U' R'\",\"\"],[[0,34548],\"F' L2 B2 R2 B' U2 F D2 R2 D2 F2 D' B' R' F' L R2 U2 B2 F' D\",\"\"],[[0,35270],\"R2 B2 L2 U' F2 L2 D' F2 D L2 D L' B' R' B2 L' D L' F U B2\",\"\"],[[0,30971],\"U2 R2 U' D2 B' L U' R2 U2 F U2 F' R2 L2 F' U2 L2 R\",\"\"],[[0,26835],\"L2 F2 R2 B2 L' F2 U2 L U2 L R' U' L' D F' D' R U2 R2 U2\",\"\"],[[0,29399],\"L U2 R B2 D2 R' B2 D2 R' B2 U B D2 B R B' L' D' U' F2\",\"\"]
@flavioamieiro
flavioamieiro / Dockerfile-IRPF-2018
Created April 8, 2018 03:42
Dockerfile para rodar o programa do IRPF 2018
# Para executar, necessário compartilhar alguns diretórios que fazem o X11 funcionar.
# Além disso, monto um diretório atual como o home do usuário criado pra poder compartilhar arquivos.
# Rodo tudo usando esse comando:
# docker run --rm -it -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=unix$DISPLAY \
# --device /dev/snd --volume /run/user/1000/pulse:/run/user/1000/pulse \
# -e PULSE_SERVER=/run/user/1000/pulse/native --device /dev/dri \
# --volume /dev/shm:/dev/shm \
# --volume $PWD/home:/home/ubuntu/ \
# irpf
# Se o uid do seu usurio no for 1000, troque pelo uid certo (e use ele aqui no Dockerfile)
@flavioamieiro
flavioamieiro / smart_rockets_python.pyde
Created June 27, 2017 15:34
Coding Challenge #29 - Smart Rockets (in Python)
#https://www.youtube.com/watch?v=bGz7mv2vD6g
lifespan = 300
population_size = 25
mutation_rate = 0.01
max_force = 0.2
max_vel = 10
SAVE_FRAMES = False
@flavioamieiro
flavioamieiro / waves.py
Last active January 10, 2017 14:16
Another python processing sketch
import math
import itertools
DEBUG = True
LOOP = False
PROGRESS = True
RATIO_OF_POINTS_IN_CIRCLE = 6
START_RADIUS = 5
RADIUS_STEP = 10
NUMBER_OF_WAVES = 10
@flavioamieiro
flavioamieiro / circle_1st_iteration.py
Created January 10, 2017 13:09
Python processing sketch
import math
DEBUG = True
LOOP = False
POINTS_IN_CIRCLE = 1000
NUMBER_OF_CIRCLES = 10
def setup():
size(500, 500)
noFill()
if LOOP:

Keybase proof

I hereby claim:

  • I am flavioamieiro on github.
  • I am amieiro (https://keybase.io/amieiro) on keybase.
  • I have a public key whose fingerprint is 9A21 04AB F6F6 2547 D756 D21E 45DC EBAB 0488 FBEF

To claim this, I am signing this object:

Wrote profile results to benchmarking.py.lprof
Timer unit: 1e-06 s
Total time: 0.815547 s
File: pypln/backend/celery_task.py
Function: run at line 48
Line # Hits Time Per Hit % Time Line Contents
==============================================================
48 @profile
Wrote profile results to benchmarking.py.lprof
Timer unit: 1e-06 s
Total time: 3.2938 s
File: pypln/backend/celery_task.py
Function: run at line 45
Line # Hits Time Per Hit % Time Line Contents
==============================================================
45 @profile
#-*- coding: utf-8 -*-
import base64
import pymongo
from pypln.backend.workers import Extractor
from pypln.backend.celery_app import app
from pypln.backend import config
client = pymongo.MongoClient(host=config.MONGODB_CONFIG['host'],
port=config.MONGODB_CONFIG['port'])