Skip to content

Instantly share code, notes, and snippets.

View maxsei's full-sized avatar

Maximillian Schulte maxsei

View GitHub Profile
@maxsei
maxsei / uuids.ts
Created April 8, 2024 21:32
uuid4 and maybe a valid uuid7 (aka tsid)
const uuid4 = (): Uint8Array => {
let res = crypto.getRandomValues(new Uint8Array(18));
res[6] = (res[6] & 0x0f) | 0x40; // Version 4
res[8] = (res[8] & 0x3f) | 0x80; // Variant is 10
return res
};
const uuid7 = (() => {
let prev = 0;
return (): Uint8Array => {
let res = uuid4();
@maxsei
maxsei / default.md
Last active March 7, 2024 17:32
install font on nixos 23.05

configuration.nix

  # Fonts
  fonts = {
    enableDefaultFonts = true;
    fonts = with pkgs; [
      (callPackage ../../pkgs/astigmata {} )
    ];
    fontconfig.defaultFonts.monospace = [ "Astigmata" ];
 };
@maxsei
maxsei / index.js
Last active February 21, 2024 18:22
Drawing overlapping rectangles with webgl
function drawRectangles(gl) {
// Create vertex buffer and bind it.
const vertices = new Float32Array(4 * 2);
const vertexBuffer = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
// Create vertex shader
const vertexShaderCode = `
attribute vec2 coordinates;
void main(void) {
@maxsei
maxsei / zig_codegen.md
Created February 16, 2024 18:00
experimental codegen in zig to javascript wasm bindings

codegen.zig

const std = @import("std");
const module = @import("./module.zig");

var __typeNameFix: [4096 * 4]u8 = undefined;
var __typeNameBuf: []u8 = __typeNameFix[0..];
fn typeName(comptime T: type) []const u8 {
    const name = @typeName(T);
    _ = std.mem.replace(u8, name, ".", "_", __typeNameBuf);
@maxsei
maxsei / build.zig
Created February 14, 2024 22:31
custom zig build step
const std = @import("std");
const Step = std.build.Step;
const Allocator = std.mem.Allocator;
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
@maxsei
maxsei / merge_obj_stream.ts
Created February 14, 2024 14:21
attempt at using an object with merge function
import { labeled, pairs, mapA } from "@thi.ng/transducers";
import {
merge,
TransformableOpts,
ISubscribable,
Subscription,
} from "@thi.ng/rstream";
import { IObjectOf, Pair } from "@thi.ng/api";
type MappedSubcribable<K, V> = {
@maxsei
maxsei / main.md
Created February 12, 2024 22:56
memory experiment with wasm gpa
const std = @import("std");
const wasm_api = @import("node_modules/@thi.ng/wasm-api/zig/lib.zig");

var gpa = std.heap.GeneralPurposeAllocator(.{}){};
pub const WASM_ALLOCATOR = gpa.allocator();

pub export fn start() i32 {
    const allocator = wasm_api.allocator().?;
    const page_size = 65_536;
{
description = "dev shell";
inputs.nixpkgs.url = "github:nixos/nixpkgs/release-23.05";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.zls.url = "github:zigtools/zls";
outputs = { self, nixpkgs, flake-utils, ... }@inputs:
let
zigpkgs = inputs.zls.inputs.zig-overlay.outputs.packages;
@maxsei
maxsei / uhiccup.js
Created January 31, 2024 21:28
super small hiccup-like javascript framework powerd by "signals" 1116 bytes 521 bytes gzipped
// START FRAMEWORK
class Signal {
state;
subs;
constructor(state) {
this.state = state;
this.subs = [];
}
subscribe(sub) {
@maxsei
maxsei / main.go
Last active January 30, 2024 22:48
Safe channel closing in go
package main
import (
"context"
"encoding/json"
"fmt"
"sync"
"time"
)