Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env bash
#
# This script sets up git similar to the git bridge of Overleaf. It is based on
# instructions by Tobias Bora (https://github.com/sagemathinc/cocalc/issues/3811#issuecomment-493138304).
# If the repository and git hooks do not exist, they are created.
# If they do exist, then this script tells you about config conflicts and how to
# resolve them.
#
#
# Usage:
@jorsn
jorsn / prettyUnsafe.nix
Created January 4, 2024 19:39
Unsafely pretty-print Nix values
with builtins;
let
printChild = prefix: x:
let
names = attrNames x;
in
if isAttrs x && length names == 1
then "." + head names + printChild prefix x.${head names}
else " = " + print prefix x
;
@jorsn
jorsn / Eqns.hs
Last active June 11, 2020 22:27
Type-level sanitized labels for HaTeX/TeX-my-math
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE Rank2Types #-}
@jorsn
jorsn / nix-findattr
Created June 27, 2019 22:59
A convenience shell wrapper around the nix function unsafeGetAttrPos.
#!/bin/sh
pname="$(basename "$0")"
read -d '' usage <<EOF
Usage: $pname -h|--help
$pname [-n <number of context lines>] [attrset (default: nixpkgs)] <attr name>
EOF
attrset="import <nixpkgs> {}"
n=3
#!/bin/sh
self="$(basename "$0")"
warn() {
# !!! WARNING: don't ever feed user-supplied args into this function !!!
fmt="${1%\\n}\\n"
shift
# disable warning about variables in format string
# shellcheck disable=SC2059