Skip to content

Instantly share code, notes, and snippets.

@amb
amb / fft.nim
Created May 12, 2022 12:43
Simple Nim FFT
# OTFFT library
# http://wwwa.pikara.ne.jp/okojisan/otfft-en/optimization1.html
# This is +20-50% improvement
const thetaLutSize = 2048
const thetaLut = static:
var arr: array[thetaLutSize, Complex[float]]
let step = 2.0*PI/float(thetaLutSize)
for k, v in mpairs(arr):
v = complex(cos(step * float(k)), -sin(step * float(k)))
@amb
amb / wav.nim
Last active May 9, 2022 22:57
Simple Nim wav library
import streams, std/base64, std/strformat
type
WavFile* = object
data*: seq[uint8]
size*: int
freq*: int
bits*: int
channels*: int
https://news.ycombinator.com/item?id=26746537
godmode2019 3 hours ago [–]
I think everyone was a txt file on their computer filled with FFmpeg commands.
Care to share yours?
stevens37 0 minutes ago [–]
from mido import MidiFile
import mido
from collections import defaultdict
import time
import sys
filename = "Space Harrier.mid"
# filename = "Shovel.mid"
if len(sys.argv) == 2:
@amb
amb / gen_sin_table_fpga.py
Created March 17, 2021 12:19
Generate 7-bit sin table for FPGA/Verilog
import math
for i in range(16):
print(
f"@{(i*16):08x} "
+ " ".join(f"{int(-math.cos((j+i*16)*math.pi*2/255)*127.1+128):02x}" for j in range(16))
)
# for Xilinx Vivado FPGA purposes
# sin_table.mem
@amb
amb / l3.py
Created March 6, 2021 09:58
Ron Garret l.py Python 3 conversion
# l.py - A tiny interpreter for a lisp-like language with full
# lexical closures in Python
#
# Written by Ron Garret. Contributed to the public domain
# The global environment
# modification 2021 ambi, also public domain
globalenv = {}
"""
https://bottosson.github.io/posts/oklab/
Lab
L=lightness
a=green/red
b=blue/yellow
Lab to lightness, chroma, hue (LCh)
C=sqrt(a**2+b**2)
@amb
amb / chainanalysis.py
Created February 13, 2021 21:06
Simple chainanalysis with Python and Blockcypher
from blockcypher import get_address_details, get_transaction_details
import json
import datetime
def open_chain_info(addr, func):
"cache web API data locally"
def _datetime_conv(o):
if isinstance(o, datetime.datetime):
@amb
amb / gist:7c6a75202c0b4211a192de90eefe4e81
Created July 6, 2020 16:30
AHK script for better nav in Fusion 360
; by twitch.tv/floatharr
; rebind fusion360 navigation to be the same as blender emulate mmb
#NoEnv
#InstallKeybdHook
SetKeyDelay, 0
SetMouseDelay, 0
SetControlDelay, 0
SetBatchLines, 0
SendMode input
@amb
amb / oculus_touch_osc_stream.py
Last active June 10, 2020 23:56 — forked from awesomebytes/htc_vive_controller_keypresses.py
Oculus Touch streaming with pythonosc and openvr
# forked from: https://gist.github.com/awesomebytes/75daab3adb62b331f21ecf3a03b3ab46
import time
import openvr
from pythonosc import osc_message_builder
from pythonosc import osc_bundle_builder
from pythonosc import udp_client
def get_controller_ids(vrsys=None):