Skip to content

Instantly share code, notes, and snippets.

@amb
amb / parallel_pio.c
Last active February 27, 2024 12:33
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
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
@amb
amb / ms_abc_cams.py
Created June 17, 2022 20:18
Meshroom cameras, with images, into Blender
import bpy
from pathlib import Path
#selo = bpy.context.selected_objects
#assert len(selo) > 0, "Need to select the camera root"
#mroot = selo[0]
#assert mroot.name == "mvgRoot"
mroot = bpy.data.objects['mvgRoot']
image_folder = Path("D:\\art\\photo\\2022.6\\16")