Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / transcribe_dit.bat
Last active September 9, 2023 06:29
Transcribe a directory of mp3 files using whisper.cpp and ffmpeg
@echo off
setlocal enabledelayedexpansion
rem Set the directory containing your MP3 files
set mp3_dir=%1
set "mp3_dir=!mp3_dir:"=!"
rem Loop through each MP3 file in the directory
for %%i in ("%mp3_dir%\*.mp3") do (
@amb
amb / macro_demo.nim
Last active July 21, 2023 20:49
Demo/test of Nim macros
import std/macros
macro makeVar(arg: varargs[untyped]): untyped =
result = newStmtList()
for a in arg:
result.add newVarStmt(a, a)
# echo result.treeRepr
macro lazyVar(arg: untyped): untyped =
var statements = newStmtList()
@amb
amb / beat.nim
Created May 18, 2023 11:40
Simple Bytebeat in Nim+portaudio
# For Windows add following to nim.cfg (in user/.choosenim/toolchains/nim-x.y.z/config/)
# Line ~159: gcc.path = r"C:\tools\msys64\mingw64\bin"
import os, math
import nordaudio
const
# SAMPLE_RATE = 44100
SAMPLE_RATE = 8000
FRAMES_PER_BUFFER = 64
@amb
amb / yt.pyw
Last active September 15, 2023 07:57
Simple Youtube-dl GUI with Python. Edit YDL and FOLDER to match your params
import tkinter as tk
from tkinter import ttk
from subprocess import run
win = tk.Tk()
win.geometry("600x140")
# YDL = "youtube-dl.exe"
YDL = "yt-dlp.exe"
FOLDER = "D:\\swap\\downloads\\ydl"
@amb
amb / test.py
Created October 9, 2022 21:33
Motion-diffusion to Blender
import numpy as np
import mathutils as mu
import bmesh
import bpy
ndir = "F:\ml\motion-diffusion-model\save\humanml_trans_enc_512\samples_humanml_trans_enc_512_000200000_seed10\\results.npy"
data = np.load(ndir, allow_pickle=True)
motions = data[()]['motion']
@amb
amb / upscale.bat
Created August 23, 2022 21:39
ESRGAN auto upscale
@echo %*
@echo off
magick %* input.jpg
F:\apps\esrgan\realesrgan-ncnn-vulkan.exe -i input.jpg -o esr_output.jpg -n realesrgan-x4plus
magick esr_output.jpg -scale 50%% esr\\%~n1.jpg
del input.jpg
del esr_output.jpg