Skip to content

Instantly share code, notes, and snippets.

View maxsei's full-sized avatar

Maximillian Schulte maxsei

View GitHub Profile
@maxsei
maxsei / flatten_bookmarks.py
Created October 24, 2022 18:51
flatten firefox bookmarks
# coding: utf-8
#!/usr/bin/env python3
import uuid
import sys
import random
import json
from typing import MutableSequence
from typing import Mapping
from copy import deepcopy
from pathlib import Path
@maxsei
maxsei / list _local_package_dep_files.sh
Created October 25, 2022 19:28
list out all the local golang files that depend on a package
PKG_PATH="./path/relative/to/your/go/pkg"
go list -f '{{ with $modstr := (printf "%v" $.Module) -}}
{{ range $_, $dep := $.Deps -}}
{{ if ne (slice (printf "%v%v" (module $dep) $modstr) 0 (len $modstr)) $modstr -}}
{{ continue -}}
{{ end -}}
{{ println $dep -}}
{{ end -}}
{{ end -}}
@maxsei
maxsei / pivot_table.js
Last active November 4, 2022 03:04
verbose code that pivots an array of records in a very unperformant and naive way.
const rdate = () => new Date(parseInt(Math.random() * Number.MAX_SAFE_INTEGER));
const data = [
{ Symbol: 'a', Data: 0.0, At: rdate() },
{ Symbol: 'b', Data: 0.0, At: rdate() },
{ Symbol: 'c', Data: 1.0, At: rdate() },
{ Symbol: 'a', Data: 1.0, At: rdate() },
{ Symbol: 'c', Data: 0.0, At: rdate() },
{ Symbol: 'b', Data: 1.0, At: rdate() },
{ Symbol: 'd', Data: 0.0, At: rdate() },
];
@maxsei
maxsei / materializing_views_on_streams.js
Last active December 4, 2022 17:29
Demonstration of materializing views on boundless data streams
// What is is a materialized view?
// Materialized view is a view on some data that emits a message (or multiple
// per query) when the data view changes and/or when a single query changes.
//
// ┌──────────────────────────┐
// │ Raw Data │
// └─────┬────────────────────┘
// ┌─────│────────────────────┐
// │┌────▼─────┐ ┌─────┐ │
// ││View logic◄──────┤Query│ │
@maxsei
maxsei / cartestian_product.ts
Created December 5, 2022 16:37
cartesian product using transducers
import * as tx from '@thi.ng/transducers';
const product = <T>(first?: T[], ...args: T[][]): IterableIterator<T[]> =>
first === undefined
? tx.asIterable([[]])
: args.length === 0
? tx.partition(1, first)
: tx.mapcat((x) => tx.map((y) => [x, ...y], product(...args)), first);
@maxsei
maxsei / syncMultiplexKey.js
Created December 10, 2022 17:20
mutiplex the key of the the sync tuple in a synced stream
import * as rx from "https://cdn.skypack.dev/@thi.ng/rstream";
import * as tx from "https://cdn.skypack.dev/@thi.ng/transducers";
import { equivObject } from "https://cdn.skypack.dev/@thi.ng/equiv";
const syncMultiplexKey = (src) =>
rx.sync({ src }).transform(
(() => {
const idCache = new Map();
return tx.mapcat((tup) =>
tx.transduce(
@maxsei
maxsei / syncMultiplexKey2.js
Created December 11, 2022 03:22
mutiplex the key of the the sync tuple in a synced stream (improved using merge and sync in conjuction with sync lawl :3)
import * as rx from "https://cdn.skypack.dev/@thi.ng/rstream";
import * as tx from "https://cdn.skypack.dev/@thi.ng/transducers";
import { equivObject } from "https://cdn.skypack.dev/@thi.ng/equiv";
const syncMultiplexKey = (src) =>
rx.sync({
src: {
k: rx.merge({
src: [
...tx.map(([k, v]) => v.transform(tx.map((_) => k)), tx.pairs(src)),
@maxsei
maxsei / libc_patchelf.nix
Created December 14, 2022 00:13
Patching executables with presumed dynamically linked libarary locations (these systems that aren't nix lol)
{ stdenv, lib, gcc-unwrapped }:
stdenv.mkDerivation rec {
name = "mercurytcpclient";
version = "0.0.1";
src = ./.;
dontUnpack = true;
dontConfigure = true;
dontBuild = true;
@maxsei
maxsei / transducers.py
Last active January 3, 2023 18:28
Transducers implemention with map, filter, and concat.
try:
from collections.abc import Iterable # noqa
except ImportError:
from collections import Iterable # noqa
def reducer(init, rfn):
def ident(x):
return x
@maxsei
maxsei / python-environment-w-poetry-shell.nix
Last active April 2, 2023 17:02
python environment with poetry nix shell
{ pkgs ? import <nixpkgs> {} }:
let
mypython = pkgs.python39;
in
pkgs.mkShell {
buildInputs = [
pkgs.poetry
mypython
];
shellHook = ''