Skip to content

Instantly share code, notes, and snippets.

@amb
amb / oai_test.py
Created September 12, 2023 15:33
Simple OpenAI chat for CLI
import openai
import pygments
from pygments import highlight
from pygments.formatters import TerminalFormatter
from pygments.lexers import get_lexer_by_name
def colored(r, g, b, text):
return f"\033[38;2;{r};{g};{b}m{text}\033[0m"
@amb
amb / test.ipynb
Created February 25, 2024 12:07
Optimal transport rough approximation
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@amb
amb / parallel_pio.c
Last active July 14, 2024 14:32
Simple parallel out with RP2040 PIO
#include <stdio.h>
#include "hardware/clocks.h"
#include "hardware/pio.h"
#include "hardware/timer.h"
#include "main.pio.h"
#include "pico/stdlib.h"
#define START_PIN 10
#define ROW_PINS 4
@amb
amb / pad.py
Created October 10, 2024 10:54
Launchpad X midi Game of Life
import time
import mido
import random
import numpy as np
# List all available MIDI ports
print("Available MIDI ports:")
for port in mido.get_input_names():
print(port)
for port in mido.get_output_names():
@amb
amb / raw_hall.py
Created January 20, 2025 20:42
Reading linear hall effect sensor and converting it to linear displacement on RP2040 mPython
from machine import Pin, ADC
from time import sleep
from math import sqrt
pin = Pin(26)
adc = ADC(pin)
val = 0
margin = (2**8)
@amb
amb / QMC6309.py
Created February 4, 2025 17:52
Reading data from QMC6309 3D hall effect I2C sensor
# QMC6309 3D Hall Sensor Micropython Library sketch
from machine import I2C, Pin, SoftI2C
from micropython import const
import ustruct
import utime
class QMC6310: