Skip to content

Instantly share code, notes, and snippets.

View maxsei's full-sized avatar

Maximillian Schulte maxsei

View GitHub Profile
@maxsei
maxsei / materialized-views-with-lock.ts
Created January 19, 2023 21:56
experiment for dealing with a single materialized view via locking
import * as rx from '@thi.ng/rstream';
import * as tx from '@thi.ng/transducers';
// Random string function
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const randstr = (length: number, ret: string = ''): string =>
length <= 0
? ret
: randstr(length - 1, ret + chars[Math.floor(Math.random() * chars.length)]);
@maxsei
maxsei / multi-vim-headless.sh
Created February 23, 2023 19:54
Editing multiple files with vim in a headless way
vim -u NONE -c 'argdo source cmd.vim | w' -c 'qa' foo.txt bar.txt qux.txt
@maxsei
maxsei / closure.c
Created March 3, 2023 16:21
closures in c
#include <stdio.h>
#include <stdlib.h>
// Generic closure that you may want to replace with some sort of typed version
// for your own needs and safety.
typedef struct {
void (*call)(void *data);
void *data;
} closure;
closure *closure_init() { return (closure *)malloc(sizeof(closure)); }
@maxsei
maxsei / custom_ultisnip.lua
Created March 9, 2023 17:13
per project vim ultisnip
snip = [[time: `!v strftime("%Y-%m-%dT%H:%M:%S%z")`
category: ${1:Category}
note: ${2:Note}]]
print(vim.fn['UltiSnips#AddSnippetWithPriority']('note', snip, 'datetime, category, and note', 'b', 'yaml', 50))
@maxsei
maxsei / client_side_routing.html
Created March 10, 2023 18:38
client side routing
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Client Side Routing Example</title>
<script charset="utf-8">
const route = (path) => {
const navbar = `<div>
<a href="/" onclick="return route(event.target.pathname)">Home</a>
@maxsei
maxsei / cache_lcality.c
Created April 2, 2023 19:06
program that trys but fails to demonstrate cache locality (c learning)
/* gcc -o out main.c && ./out */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
typedef struct {
int x;
int y;
} Point;
@maxsei
maxsei / flatkeys.nix
Created April 4, 2023 15:39
Get the keys of a nested object in a flat data structure in nix
let
flatkeys = cur:
if builtins.isAttrs cur then
(builtins.concatMap
(k: builtins.map (x: [ k ] ++ x) (flatkeys cur."${k}"))
(builtins.attrNames cur))
else if builtins.isList cur then
builtins.concatLists (builtins.genList
(i: builtins.map (x: [ i ] ++ x) (flatkeys (builtins.elemAt cur i)))
(builtins.length cur))
@maxsei
maxsei / firefox_history.sql
Created April 6, 2023 18:12
sql query for firefox history database to show urls you visited before or after a certain query
WITH q1 AS (
SELECT
mp.id,
mp.origin_id,
mp.site_name,
mp.title,
mp.url,
mp.visit_count
FROM
moz_places mp
@maxsei
maxsei / diag.c
Last active April 26, 2023 16:36
diagonal iterator
/*
* diag iterates based on a number of rows in columns across diagonals of a
* 2 dimensions. Iteration starts at the first row and column. For each
* diagonal we go to the dth column and start decrementing the column by 1
* and incrementing the row by 1 until we reach a boundary. Once we have
* exchausted column we will start at row `d-rows` and continue the
* algorithm.
*
* Fig 1:
* 0 1 2 3 4
@maxsei
maxsei / gcounter.go
Created May 7, 2023 19:37
This program is an implementation of a gcounter CRDT. A gcounter is a counter that is a distributed across nodes and is eventually consistent. Each node has it's own local counter and an estimate of the interal states of the other nodes.
package main
// This program is an implementation of a gcounter CRDT. A gcounter is a counter
// that is a distributed across nodes and is eventually consistent. Each node
// has it's own local counter and an estimate of the interal states of the other
// nodes.
import (
"fmt"
"math/rand"
)