Skip to content

Instantly share code, notes, and snippets.

@mrzor
mrzor / perplexing_list.py
Created June 25, 2024 08:58
A Python list for prestidigitators
class PerplexingList(UserList):
"""
A list that may veil or unveil elements of a certain type at different types.
Useful for boneheaded libraries.
"""
veiled: bool = False
masked_type: type
class PerplexingIterator(Iterator):
@mrzor
mrzor / minimal_state_machine.py
Created October 6, 2023 18:14
Minimal Python State Machine
from __future__ import annotations
from inspect import signature, Signature, Parameter
from typing import Generic, TypeVar, TypeAlias, Iterable, Callable, Any, NamedTuple
def magic_call(fn: Callable, kwargs: dict[str, Any]):
sig = signature(fn)
accepted_parameters = set(sig.parameters.keys())
forwarded_parameters = {}
@mrzor
mrzor / gist:e06faeb76f005d485273fce5a37c211b
Created January 31, 2021 16:05
Automatically updated PKGBUILD for regolith-de
# Author: Matt McDonald <[email protected]>
# Contributor: Kevin Gilmer
# Contributor: Avinash Duduskar <[email protected]>
# Maintainer: Matt McDonald <[email protected]>
pkgbase=regolith-de
pkgname=(regolith-i3 # (regolith-i3-gaps regolith-i3-gaps-session i3-gaps-wm i3-gaps-wm-dbg i3-snapshot i3xrocks gnome-flashback ubiquity-slideshow-regolith)
regolith-i3xrocks # allll the i3xrocks shit
regolith-styles # alll the styles shit
@mrzor
mrzor / ig-doc.md
Created October 15, 2020 11:05
Integrant Doc

First immediate issue I see is that we don't have a common definition for "component" in the context of Integrant. The README only alludes to the idea in the read-namespaces doc. All other uses point to the eponymous library. Integrant operates at the "config" level. Might be a component - doesn't have to be.

I understand such an Integrant "component" to be some set of Integrant keywords - let's call that an ig/key. An ig/key exists is a key in a configuration map, and init-key is provided for this keyword (optionally, more methods, as you well know). In my project, I call such sets of Integrant keywords "subsystems" and they are defined by .. a subsystem function that returns a subsystem map. These subsystem maps are (merge ...'d together to form a "system" map. As it happens, in my case and maybe in yours, all keys of a given subsystem are namespaced keywords that share a namespace - so maybe that's a connected, somewhat equivalent definition of an Integrant component. All of this is in line with

#!/usr/bin/env python3
# Renames i3 workspaces that may not be using pretty names from Xresources
# (as defined by Regolith default configuration)
#
# Execute once on i3 startup (edit path as appropriate):
# exec --no-startup-id "python3 /home/<YOUR_USER>/.config/regolith/i3/rename_default_workspaces.py"
#
# Author: mrzor
# License: mrzor has waived all copyright and related or neighboring rights to rename_default_workspaces.py.
@mrzor
mrzor / prettier-tools-trace.clj
Last active December 16, 2019 16:44
Prettify clojure.tools.trace/trace
;; See https://greglook.github.io/puget/api/puget.printer.html
;; Hack tools trace to be prettier
;; (won't work if everything has been aot compiled with direct linking)
;; ty alexdmiller
(defn hacked-tracer [name value]
(println (str "TRACE" (when name (str " " name)) ": ")
;; you may want to remove the second param and bind puget.printer/*options* instead
(puget.printer/pprint-str value {:print-color true}))
value)
@mrzor
mrzor / fish-set-cookie-redirect.js
Created March 6, 2018 14:40
Nick.js / Headless Chrome / Redirect + Set-Cookie fishing
@mrzor
mrzor / AllAllocationsTogglable.java
Created November 4, 2016 17:28
A flawed BTrace script to record all object allocations
package btraces;
import com.sun.btrace.annotations.*;
import static com.sun.btrace.BTraceUtils.*;
@BTrace
public class AllAllocationsTogglable {
@TLS private static boolean enabled = false;
@mrzor
mrzor / util.clj
Last active August 23, 2016 12:41
UUID heresy
(defn ^StringBuilder stringbuilder-append-UUID [^StringBuilder sb ^UUID uuid]
(doto sb
(.append "#UUID\"")
(.append (.getLeastSignificantBits uuid))
(.append "\"")))
(defmethod print-method UUID [^UUID v ^java.io.Writer w]
(.append
w
(stringbuilder-append-UUID (StringBuilder. 60) v)))
@mrzor
mrzor / mkmf.log
Created July 18, 2016 19:45
archlinux skylight compile issue
find_header: checking for skylight_dlopen.h in /home/zor/.gem/ruby/2.3.0/gems/skylight-0.10.5/ext... -------------------- yes
"gcc -o conftest -I/usr/include/ruby-2.3.0/x86_64-linux -I/usr/include/ruby-2.3.0/ruby/backward -I/usr/include/ruby-2.3.0 -I. -D_FORTIFY_SOURCE=2 -Wno-error=pedantic conftest.c -L. -L/usr/lib -L. -Wl,-O1,--sort-common,--as-needed,-z,relro -fstack-protector -rdynamic -Wl,-export-dynamic -lruby -lpthread -lgmp -ldl -lcrypt -lm -lc"
In file included from /usr/include/stdio.h:27:0,
from /usr/include/ruby-2.3.0/ruby/defines.h:26,
from /usr/include/ruby-2.3.0/ruby/ruby.h:36,
from /usr/include/ruby-2.3.0/ruby.h:33,
from conftest.c:1:
/usr/include/features.h:331:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
# warning _FORTIFY_SOURCE requires compiling with optimization (-O)