Skip to content

Instantly share code, notes, and snippets.

View marler8997's full-sized avatar

Jonathan Marler marler8997

  • Tuple
  • Idaho, United States
View GitHub Profile
@marler8997
marler8997 / signing.zig
Created July 9, 2022 22:35
Generate Keys, Sign and Verify files on linux with ED25119 and BLAKE3
const std = @import("std");
const Signer = std.crypto.sign.Ed25519;
// Blake3 : 1
// Blake2b512 : 1.3 x slower than Blake3
// Sha256 : 4 x slower than Blake3
//const Hasher = std.crypto.hash.sha2.Sha256;
//const Hasher = std.crypto.hash.blake2.Blake2b512;
const Hasher = std.crypto.hash.Blake3;
rough date version
2022-07-01 0.10.0-dev.2836+2360f8c49
2022-06-06 0.10.0-dev.2490+135b91aec
2022-05-26 0.10.0-dev.2413+ee1a95b55
2022-05-11 0.10.0-dev.2186+3a64693db
2022-05-04 0.10.0-dev.2063+49a7ceb5b
2022-03-15 0.10.0-dev.1335+c64279b15
@marler8997
marler8997 / get-defines
Created February 16, 2024 20:58
C Get Defines
#!/usr/bin/env python3
import sys
import os
import re
import argparse
import subprocess
def scan_path(defines, path):
for entry_base in os.listdir(path):
entry = os.path.join(path, entry_base)
@marler8997
marler8997 / watch.cpp
Created January 27, 2024 16:42
Win32 Watch directory for changes recursively
#include <windows.h>
#include <stdio.h>
#define logf(fmt,...) do { fprintf(stderr, fmt "\n", ##__VA_ARGS__); fflush(stderr); } while (0)
void MonitorDirectoryRecursively(const char* directoryPath) {
HANDLE hChange = FindFirstChangeNotification(
directoryPath,
TRUE, // Watch the subtree
FILE_NOTIFY_CHANGE_LAST_WRITE | FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME
@marler8997
marler8997 / anywriter.zig
Last active December 26, 2023 05:02
Zig Any Writer
const std = @import("std");
const mem = std.mem;
const testing = std.testing;
/// AnyWriter is an instance of std.io.Writer that is able to wrap
/// any other std.io.Writer type and forward data to it.
///
/// AnyWriter enables std.io.Writer to be used in places where concrete
/// types are required such as function pointer parameters or as a field
/// in a struct.
@marler8997
marler8997 / interp.zig
Last active December 10, 2023 16:59
interp.zig
const std = @import("std");
const Vm = @import("vm.zig").Vm;
const tokenizer = @import("tokenizer.zig");
pub fn lex(src: [:0]const u8, off: usize) tokenizer.Token {
var t = @import("tokenizer.zig").Tokenizer{ .code = src, .idx = off };
return t.next();
}
@marler8997
marler8997 / wasm4-change-pitch.zig
Created November 25, 2023 15:48
WASM4 Change Pitch
fn changePitchOne(freq: u16, semitones: f32) u16 {
if (freq == 0) return 0;
const freq_f32 = @as(f32, @floatFromInt(freq));
return @intFromFloat(@round(freq_f32 * std.math.pow(
f32,
@exp2(1.0 / 12.0),
semitones,
)));
}
@marler8997
marler8997 / thing.zig
Created November 1, 2023 18:51
Thing.zig
const std = @import("std");
fn fatal(comptime fmt: []const u8, args: anytype) noreturn {
std.log.err(fmt, args);
std.os.exit(0xff);
}
pub fn main() void {
var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const arena = arena_instance.allocator();
@marler8997
marler8997 / ZigScript.md
Last active September 22, 2023 15:24
ZigScript

Since people seem to enjoy making scripting languages so much (not meant to be a "dig", I like this)...here's a scripting language I'd be very interested in.

ZigScript

"A companion scripting language meant for Zig developers."

Zig is my language of choice, but I still reach for Python when I want to make something fast or "short lived". However, Python has downsides, it's hard to build the interpreter for it (especially a static executable), its packaging system is a mess and it's got some interesting syntax choices that would feel foreign to a native Zig developer, but overall I think the core of the language is brilliant. I imagine ZigScript as Python but in a "Zig Style" syntax with the problems fixed. Here are some features that come to mind:

@marler8997
marler8997 / downloads.zig
Created September 20, 2023 15:12
Zig Template
const std = @import("std");
const stdout = std.io.getStdOut().writer();
fn raw(s: []const u8) void {
stdout.writeAll(s) catch |err| @panic(@errorName(err));
}
fn fmt(comptime spec: []const u8, args: anytype) void {
stdout.print(spec, args) catch |err| @panic(@errorName(err));
}