Skip to content

Instantly share code, notes, and snippets.

@ingoogni
ingoogni / _nimscripter_about.txt
Last active April 2, 2025 14:38
scripting in Nim with nimscripter
compile
> nim c -d:release -d:danger renderer.nim
to render image from prompt:
> renderer sincos.nims
Render a function to a grey scale image, using nimscripter https://github.com/beef331/nimscripter for realtime scriptable applications.
@ingoogni
ingoogni / circlespline2d.nim
Created January 19, 2025 16:40
Circle spline 2D in Nim
import vmath
import math
type
ColinearSegmentError* = object of Defect
Input2D = object
dir: Vec2 # tangent vector at first input knot
knot: seq[Vec2]
@ingoogni
ingoogni / 1_sqlite_table_with_history.ddl
Last active January 26, 2025 21:16
Table that keeps its own history, SQLite
/*
Database schema SQLite for a table that keeps its own history and
never deletes data.
On update, historic data is kept under a new id and references the original
creation id. The end of life timestamp (ts_eol) is set so a time line can be
built. The new data is used to update the data under the existing id.
On delete, nothing is deleted. Only the ts_eol timestamp is set to current.
*/
@ingoogni
ingoogni / sseClient.nim
Last active February 26, 2025 14:17
SSE Client Nim experiment Server Sent Events
# Compile:
# nim c --gc:orc --experimental:strictFuncs -d:ssl -d:nimStressOrc --import:std/httpcore sseClient.nim
# based on Harpoon https://github.com/juancarlospaco/harpoon
import std/[net, macros, strutils, times, json, httpcore, uri]
type
SSE = object
comment: string
@ingoogni
ingoogni / avxgoertzeloscbank.nim
Last active May 22, 2025 15:03
Goertzel, Rotating Vector vs. sin() Compare sine wave oscillators for speed and accuracy.
# Goertzel oscillator bank (scalar):
# (seconds: 208, nanosecond: 253406100)
# duration: 4440s samplerate: 44100 samples: 195804000
# 0.0000010635809590202449 seconds per sample @ 1000 oscillators
# Goertzel AVX oscillator bank:
# (seconds: 26, nanosecond: 403254200)
# duration: 4440s samplerate: 44100 samples: 195804000
# 0.00000013484532593818306 seconds per sample @ 1000 oscillators
# Speedup: 7.887414351371886x
@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
Last active March 11, 2025 12:07
Spline and curve interpolation for many variants. Based upon the works of Steve H. Noskowicz. Parallel excecution using Malebolgia.
import sequtils, math
## 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/
## Get the book PDF and the appendix.
type
CurveSegmentError* = object of Defect
CurveOrderError* = object of Defect
@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)