Skip to content

Instantly share code, notes, and snippets.

View nervecenter's full-sized avatar

Chris C. nervecenter

  • GeoSonics Inc.
  • Florida
View GitHub Profile
@nervecenter
nervecenter / address_test.c
Created September 9, 2025 13:15
An exam test question I found online, testing sub-addressing 64-bit long values and endianness.
#include <stdio.h>
#include <inttypes.h>
int main() {
uint64_t n[2] = {0xaabbccddeeff1122, 0x1122334455667788};
for (int i = 0; i < 2; ++i) {
printf("at address: %lx\t number: %lx\n", (size_t)&n[i], n[i]);
for (int k = 0; k < 8; ++k) {
uint8_t* c = ((uint8_t*)(&n[i])) + k;
printf("at address: %lx\t number: %x\n", (size_t)c, *c);
#
# Brotli implementation for static compilation with musl-libc
# Compiled with: --gcc.exe:musl-gcc --gcc.linkerexe:musl-gcc --passL:-static --dynlibOverrideAll --passL:lib/libbrotli.a
#
type
BrotliEncoderMode = enum
BROTLI_MODE_GENERIC = 0.cint
BROTLI_MODE_TEXT = 1.cint
BROTLI_MODE_FONT = 2.cint
@nervecenter
nervecenter / simpleargs.nim
Last active October 25, 2025 01:56
A simple set of CLI argument parsing procedures using std/parseopt that covers the majority of basic cases for parsing CLI arguments.
# by Chris Collazo
# Released to the public domain
import std/parseopt
# `short` is optional
proc get_option*(oparser: var OptParser, name: string, default: string, short: string = ""): string =
for kind, key, val in oparser.getopt():
if kind == cmdLongOption and key == name:
return val
@nervecenter
nervecenter / get_json_value.nim
Last active May 24, 2023 14:52
Generic Nim code for querying JSON values, including deeply nested values. Statically typed by way of a default fallback value should the key not be found or be of incorrect type.
# Inputs:
# node: The JsonNode that represents the object you're querying.
# key/keys: The key you're looking for, or the sequence of key steps if your value is deeply nested.
# default: The default value should the key not be found.
# Examples:
# let enable_raytracing: bool = settings_json_node.get_json_value("enable_raytracing", false)
# let enable_raytracing: bool = settings_json_node.get_json_value(@["settings", "graphics", "enable_raytracing"], false)
proc get_json_value*[T: bool | float | int | string | JsonNode](node: JsonNode, keys: seq[string], default: T): T =