Skip to content

Instantly share code, notes, and snippets.

import hashlib
from functools import reduce
inputs = """\
4987a884
dc917386
54c4938a
dcf3388d
22e1e08f
02e29593
#!/usr/bin/env sage
import itertools
# cycle decomposition of a permutation
def cycles(perm):
seen = [False] * len(perm)
for i in range(len(perm)):
if seen[i]:
continue
cycle = [i]
@jix
jix / main.rs
Created January 29, 2022 17:09
Lifetime GAT emulation on stable rust
// This is a technique to emulate lifetime GATs (generic associated types) on stable rust starting
// with rustc 1.33.
//
// I haven't seen this exact technique before, but I would be surprised if no one else came up with
// it. I think this avoids most downsides of other lifetime GAT workarounds I've seen.
//
// In particular, neither implementing nor using traits with emulated lifetime GATs requires adding
// any helper items. Only defining the trait requires a single helper trait (+ a single helper impl
// for the 2nd variant) per GAT. This also makes the technique viable without any boilerplate
// reducing macros.
@jix
jix / decodegen.py
Last active October 2, 2021 23:06 — forked from olofk/decodegen.py
from sympy.logic import SOPform
from sympy import symbols
from functools import partial, reduce
from itertools import product, combinations
import networkx as nx
import z3
HEADER = """module serv_auto_decode
(
input wire i_clk,
@jix
jix / docs_rs_hotkey_for_crates_io.user.js
Last active March 6, 2021 13:04
User script that adds a hotkey to open the docs.rs link for the currently viewed crate on crates.io.
// ==UserScript==
// @name docs.rs hotkey for crates.io
// @namespace Violentmonkey Scripts
// @match https://crates.io/*
// @grant none
// @version 1.1
// @author @jix_
// @description Press d to open the docs.rs link for the currently viewed crate on crates.io.
// ==/UserScript==
# Copyright 2021 Jannis Harder
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
@jix
jix / resolve_tco_links.user.js
Last active July 16, 2024 02:01
User script to resolve t.co links on twitter
@jix
jix / lrdocs
Created February 13, 2021 09:53
#!/usr/bin/env python3
from livereload import Server, shell
import shlex
import sys
import os
import toml
config = toml.load('Cargo.toml')
cmd = 'cargo +nightly doc ' + shlex.join(sys.argv[1:])
server = Server()
@jix
jix / cep_graph.py
Last active December 21, 2020 14:26
# Copyright 2020 Jannis Harder
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# Return a representative of each conjugacy class of maximal subgroups of a
# permutation group that stabilize a block or point. These are the maximal
# subgroups whose orbit parition is a strict refinement of the whole groups
# orbit partition.
#
# The result is a list of pairs containing the representative subgroup and the
# block or point for which it is the stabilizer. A point is returned as a block
# of size 1.
MaximalBlockStabilizerClassReps := function ( G )
local i, pt, pt2, orb, lorb, on_lorb, l2g, block_reps, block_rep,