Skip to content

Instantly share code, notes, and snippets.

View elcritch's full-sized avatar

Jaremy Creechley elcritch

View GitHub Profile
@elcritch
elcritch / ownedrefs.md
Last active October 9, 2026 14:54
Nim owned references: a practical tutorial

Owned references: a tutorial

An owned ref T marks one reference as the object's owner. You can move that ownership to another variable, but copying it would create a second owner, so the compiler rejects the copy.

An ordinary ref T can be copied: each copy points to the same object. You can create these ordinary references from an owner, and they can read or change the object too. They keep it alive even after the owner is cleared or goes out of scope. So owned tracks ownership, while ordinary refs allow shared access.

@elcritch
elcritch / rc.conf
Created December 28, 2025 16:30
FreeBSD IPv6 Dual Ethernets
net.inet.ip.forwarding=1 # Enable IPv4 forwarding between interfaces
net.inet6.ip6.forwarding=1 # Enable IPv6 forwarding between interfaces
net.inet6.ip6.accept_rtadv=1 # Important: Still accept IPv6 Router Adverts even with IPv6 Forwarding
net.inet6.ip6.rfc6204w3=1 # Enable per interface router adverts (?)
net.link.bridge.pfil_onlyip=0 # Only pass IP packets when pfil is enabled
net.link.bridge.pfil_bridge=0 # Packet filter on the bridge interface
net.link.bridge.pfil_member=0 # Packet filter on the member interface
@elcritch
elcritch / pyauto.py
Last active September 22, 2025 23:41
Simple Pyauto Rest API
import pyautogui
import subprocess
import time
import logging
from datetime import datetime
# Create logger
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
@elcritch
elcritch / NocdeA.md
Created November 2, 2023 00:38
codex-two-client-test

metric: connmanager.nim(221) muxCleanup count: 1 avg execTime: 25us542ns total: 25us542ns avg wallTime: 49us625ns total: 49us625ns avg runTime: 49us584ns total: 49us584ns

metric: asyncsync.nim(367) popFirst count: 47690 avg execTime: 1us385ns total: 66ms56us535ns avg wallTime: 129ms128us33ns total: 1h42m38s115ms901us655ns

@elcritch
elcritch / case_types.nim
Created June 12, 2023 23:09
Experiment with Nim Pattern Matching Syntax
import macros
type
EitherKind {.pure.} = enum
Some, None
Either[T] = object
case kind: EitherKind
of Some:
@elcritch
elcritch / rfc idea.md
Last active June 9, 2023 22:17
Omnimvore Error Handling

RFC Draft: Omnimvore Error Handling

This RFC presents an attempt to unify parts of the syntatical styles between exceptions vs results based error handling techniques. The two styles can be implemented in a somewhat similar fashion under the covers, but do offer quite different ergonomics. In an ideal world we can take the best from both styles as fits a given situation.

The core idea of this RFC is to present a gradual typing like system for enhancing error typing. This provides attempts to provide a best of all worlds and let folks decide how strictly they want to track their error types in a given set of code.

Another idea is to provide a seamless integration from full exceptions to enum based error codes. While it provides nice ergonomics, this may not be desirable at an implementation level though.

Syntax Proposal and Compiler Checks

@elcritch
elcritch / devcontainer.json
Created May 16, 2023 19:38
vscode devcontainer for esp-idf and nesper
{
"name": "esp-idf",
"image": "ghcr.io/embeddednim/esp-idf:4.4-2023-02-12",
"remoteUser": "root",
"postCreateCommand": "git config --global --add safe.directory '*' && sh -c \"$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh) --skip-chsh\" ",
// "postStartCommand": "",
"customizations": {
"vscode": {
"extensions": [
"nimsaem.nimvscode",
@elcritch
elcritch / settings_nvs_esp32.nim
Created June 15, 2022 07:21
Example NVS Setting Object (ESP-IDF)
## Example usage of NVS
## license: Apache-2.0
import macros, strutils, md5, options
import json
import nesper
import nesper/net_utils
import nesper/consts, nesper/general
import nesper/nvs_utils
@elcritch
elcritch / pararulesStaticEx.nim
Created May 16, 2022 02:35
pararules static example
import pararules
import std/[times, monotimes, os, strformat, strutils, sequtils, sugar]
type
Id = enum
Global, Player, Derived
Attr = enum
DeltaTime,
TotalTime,
X,