Skip to content

Instantly share code, notes, and snippets.

@ingoogni
ingoogni / goertzel_bench.nim
Created November 12, 2023 11:50 — forked from Moaneschien/goertzel.nim
Compare sine wave oscillators for speed and accuracy. Goertzel, Rotating Vector vs. sin()
#nim.cfg
#-d:release
#-d:danger
#-d:samplerate=44100
# Result (12th Gen Intel(R) Core(TM) i9-12900 2.40 GHz):
#
# GSinOsc : (seconds: 0, nanosecond: 516204700)
# RVSinOsc : (seconds: 1, nanosecond: 672888300)
# STDSinOsc: (seconds: 5, nanosecond: 908334300)
@ingoogni
ingoogni / markov.nim
Created May 16, 2022 14:45
Markov experiment in Nim
import random, math, times
#randomize()
type
TransitionMatrix* = object
order: int
tMatrix: seq[seq[float]]
multiplier: seq[int]
@ingoogni
ingoogni / psbus.nim
Last active June 14, 2022 08:03
Experimenting with pub/sub bus, using asyncstreams in Nim
import std/[os, asyncdispatch, asyncstreams, strutils, oids, tables, options]
type
PSBusException* = object of Defect
Topic* = string
MsgDist* = enum
mtPS, #pub/sub
mtRR, #public request(/reply)
@ingoogni
ingoogni / curve.nim
Created May 16, 2022 07:48
Spline and curve interpolation for many variants. Based upon the works of Steve H. Noskowicz.
import sequtils
import vmath
export vmath
#[
Spline and curve interpolation for many variants.
Based upon the works of Steve H. Noskowicz.
http://web.archive.org/web/20151002232205/http://home.comcast.net/~k9dci/site/?/page/Piecewise_Polynomial_Interpolation/
@ingoogni
ingoogni / sse.nim
Last active October 16, 2023 09:56
Experimenting with Server Sent Events in Nim
import asyncdispatch, asynchttpserver, asyncnet, nativesockets, net
import logging, oids, strformat, strutils, tables, times
#import sse_db
type SSEClient = object
fs: FutureStream[string]
clientClosed: int
req: Request
@ingoogni
ingoogni / pgmiter.nim
Last active May 16, 2022 07:49
Read .pgm file
import streams
from strutils import parseInt, Whitespace
#from os import getFileSize
type
PGMError* = object of Defect
proc pgmRead(strm: FileStream, filePos: int=0): auto=
var data: char
strm.setPosition(filePos)
@ingoogni
ingoogni / terts_pinknoise_6db.cmd
Last active December 7, 2020 08:41
SoX: create third octave bands of pink noise in one wav file. Using SoX's sinc, band & bandpass
sox -c2 -t waveaudio 0 terst_pinknoise_6dB_bandpass.wav synth 2 pinknoise fade 0.05 2 0.05 bandpass 19.686 4.558555717707598 : synth 2 pinknoise fade 0.05 2 0.05 bandpass 24.803 5.743465278182541 : synth 2 pinknoise fade 0.05 2 0.05 bandpass 31.25 7.236354067782308 : synth 2 pinknoise fade 0.05 2 0.05 bandpass 39.373 9.117342998745364 : synth 2 pinknoise fade 0.05 2 0.05 bandpass 49.606 11.486930556365081 : synth 2 pinknoise fade 0.05 2 0.05 bandpass 62.5 14.472708135564616 : synth 2 pinknoise fade 0.05 2 0.05 bandpass 78.745 18.23445443416057 : synth 2 pinknoise fade 0.05 2 0.05 bandpass 99.213 22.974092676060337 : synth 2 pinknoise fade 0.05 2 0.05 bandpass 125.0 28.945416271129233 : synth 2 pinknoise fade 0.05 2 0.05 bandpass 157.49 36.46890886832114 : synth 2 pinknoise fade 0.05 2 0.05 bandpass 198.425 45.94795378879053 : synth 2 pinknoise fade 0.05 2 0.05 bandpass 250.0 57.890832542258465 : synth 2 pinknoise fade 0.05 2 0.05 bandpass 314.98 72.93781773664227 : synth 2 pinknoise fade 0.05 2 0
@ingoogni
ingoogni / Thing.py
Last active July 29, 2020 06:28
CherryPy config & structure
```
import os
import cherrypy
app_dir = os.path.dirname(__file__)
@cherrypy.expose
class Thing(object):
def __init__(self):
self.app_name = 'thing' #
@ingoogni
ingoogni / hbmqttcherrypy.py
Last active March 6, 2019 06:16
Cherrypy MQTT HBMQTT plugin
#https://stackoverflow.com/questions/26270681/can-an-asyncio-event-loop-run-in-the-background-without-suspending-the-python-in
import asyncio
import threading
import cherrypy
from cherrypy.process import plugins
from hbmqtt.client import MQTTClient, ClientException
from hbmqtt.mqtt.constants import QOS_1, QOS_2
@ingoogni
ingoogni / CherryPy_PGrepub.py
Last active October 1, 2017 16:54
CherryPy PostgreSQL pgpubsub
import threading
import pgpubsub
import cherrypy
from cherrypy.process import plugins
class PGrepub(plugins.SimplePlugin):
"""
Plugin that listens to Postresql notification channels and publishes
the payload unmodified to a channel on the CherryPy bus.