Skip to content

Instantly share code, notes, and snippets.

View maxsei's full-sized avatar

Maximillian Schulte maxsei

View GitHub Profile
@maxsei
maxsei / zig-gnueabihf.nix
Created May 15, 2023 21:24
running gnueabihf with zig on nix
{ lib, fetchFromGitHub, cmake, llvmPackages_13, libxml2, zlib }:
let inherit (llvmPackages_13) stdenv;
in stdenv.mkDerivation rec {
pname = "zig";
version = "0.9.1";
src = fetchFromGitHub {
owner = "ziglang";
repo = pname;
rev = version;
const std = @import("std");
fn BoolSerializer(
comptime Context: type,
comptime O: type,
comptime E: type,
comptime methods: struct {
serializeBool: ?fn (Context, bool) E!O = null,
},
) type {
@maxsei
maxsei / bad_ls.zig
Created May 31, 2023 14:50
unoptimized ls written in zig (still recurses subdirs)
const std = @import("std");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
defer {
const deinit_status = gpa.deinit();
if (deinit_status == .leak) std.log.err("leaked memory", .{});
}
@maxsei
maxsei / bool_iterators.zig
Last active June 7, 2023 14:56
zig boolean iterator
const BoolIterator = struct {
bools: []const bool,
cursor: usize = 0,
const Self = @This();
pub fn next(self: *Self) ?bool {
if (self.cursor < self.bools.len) {
const ret = self.bools[self.cursor];
self.cursor += 1;
return ret;
}
@maxsei
maxsei / concurrency.zig
Created June 12, 2023 19:28
concurrency experimentation in zig 0.11.0-dev.3202+378264d40
const std = @import("std");
const testing = std.testing;
const time = std.time;
const Mutex = std.Thread.Mutex;
var rand = std.rand.DefaultPrng.init(0);
pub fn hi(store: *usize, wg_counter: *usize, m: *Mutex) void {
// const id = std.Thread.getCurrentId();
// std.debug.print("hello from thread: {}\n", .{id});
@maxsei
maxsei / clickhouse_test_server.go
Created August 23, 2023 22:43
clickhouse database test server for golang
package main
import (
"log"
"os"
"os/exec"
"syscall"
"github.com/pkg/errors"
)
@maxsei
maxsei / csv_parsers.zig
Created September 17, 2023 20:20
two csv parser implemenations in zig
const std = @import("std");
const mem = std.mem;
const Allocator = mem.Allocator;
const log = std.log;
const Csv = struct {
fields: std.ArrayList([][]const u8),
backing: ?[]const u8,
allocator: Allocator,
@maxsei
maxsei / transducer.go
Created September 25, 2023 00:12
this is transducers in golang using golang generics (didn't implement cat or filter sorry)
package main
import "fmt"
type InitFn[A any] func() A
type IdentityFn[A any] func(x A) A
type ReduceFn[A any, B any] func(acc A, cur B) A
type Reducer[A any, B any] struct {
Init InitFn[A]
@maxsei
maxsei / thing_matrix_tfns.ts
Created October 18, 2023 19:12
thing matrix transformations
import * as mats from "@thi.ng/matrices" // https://docs.thi.ng/umbrella/matrices/
import * as vecs from "@thi.ng/vectors" // https://docs.thi.ng/umbrella/vectors/
const x = 4
const y = 5
const vec = [x, y, 1]
const dx = 1
const dy = 2
@maxsei
maxsei / map_and_object_benchmark.js
Created October 20, 2023 20:55
map and object benchmark
const randomString = (n) => {
n = n ?? 8
const ret = [];
for (let i = 0; i < n; i++) {
const c = String.fromCharCode(Math.floor(Math.random()*26)+65)
ret.push(c)
}
return ret.join("")
}