Skip to content

Instantly share code, notes, and snippets.

@nikola-j
nikola-j / main.py
Last active March 6, 2024 08:46
Micropython play wav file forever on M5stack atom echo
import uasyncio as asyncio
from machine import I2S, Pin
# I2S configuration
device_config = {
'bck': 19,
'ws': 33,
'sdout': 22,
}
SAMPLES_PER_SECOND = 16000
@nikola-j
nikola-j / white_noise.py
Created January 31, 2024 14:30
RPI White noise + Airplay server
# Simple script to start white noise on button click on rpi zero w2 combined with waveshare WM8960 audio hat
# It will also stop/start an airplay container
import RPi.GPIO as GPIO
import pygame
import time
import subprocess
# Initialize pygame mixer
pygame.mixer.init()
@nikola-j
nikola-j / diverse_cmap.py
Created September 17, 2020 13:54
Plot diverse labels for segmentation image
def color_map(N=256, normalized=True):
def bitget(byteval, idx):
return (byteval & (1 << idx)) != 0
dtype = 'float32' if normalized else 'uint8'
cmap = np.zeros((N, 3), dtype=dtype)
for i in range(N):
r = g = b = 0
c = i
for j in range(8):
@nikola-j
nikola-j / atan2.py
Last active September 22, 2023 02:51
Atan2 pytorch onnx
def my_atan2(y, x):
pi = torch.from_numpy(np.array([np.pi])).to(y.device, y.dtype)
ans = torch.atan(y / (x + 1e-6))
ans += ((y > 0) & (x < 0)) * pi
ans -= ((y < 0) & (x < 0)) * pi
ans *= (1 - ((y > 0) & (x == 0)) * 1.0)
ans += ((y > 0) & (x == 0)) * (pi / 2)
ans *= (1 - ((y < 0) & (x == 0)) * 1.0)
ans += ((y < 0) & (x == 0)) * (-pi / 2)
return ans
@nikola-j
nikola-j / table_q_learning.py
Last active December 7, 2018 09:14
Table Q learning
from time import sleep
import gym
import numpy as np
import matplotlib.pyplot as plt
import sys
import os
def val_to_bin(obs):