Skip to content

Instantly share code, notes, and snippets.

@Lucus16
Lucus16 / pg_tmp.sh
Created June 3, 2026 11:52
simple temp postgres database
#!/usr/bin/env bash
# A simple wrapper around pg_ctl that automatically initializes and creates a database on start.
# export PGHOST=$(mktemp -d)
# pg_tmp start
# psql -c "SELECT 'Have fun!';"
# pg_tmp stop
# rm -r $PGHOST # Be careful!
set -eo pipefail
@Lucus16
Lucus16 / secret-demo.nix
Created March 24, 2026 17:22
Nix secret daemon demo
let
pkgs = import <nixpkgs> { };
inherit (pkgs) lib;
dummyIdentity = pkgs.runCommand "dummyIdentity" { } ''
${pkgs.age}/bin/age-keygen -o $out
'';
secretValue = "super-secret-token";
@Lucus16
Lucus16 / nixos-rebuild-switch.sh
Created October 3, 2025 19:18
Complete implementation of nixos-rebuild switch.
system=$(nix-build --no-out-link '<nixpkgs/nixos>' -A system)
nix-env -p /nix/var/nix/profiles/system --set $system
$system/bin/switch-to-configuration switch
@Lucus16
Lucus16 / shell.nix
Created September 3, 2025 15:37
Heroes of the Storm on linux
# Instructions:
# 1. Put this file in a new directory.
# 2. nix-shell
# 3. Download the battle.net installer from the website.
# 4. wine installer.exe
# 5. Install battle.net and then Heroes of the Storm, then shut it down.
# 6. While in the nix-shell, run fixdlls
# 7. Run hots in the nix-shell to start
{ pkgs ? import <nixpkgs> { } }:
@Lucus16
Lucus16 / layers.py
Created March 22, 2025 10:34
Example of new automatic docker layering algorithm
[{'closureSize': 9848472,
'layerSize': 9848472,
'paths': ['/nix/store/19lnwi85piic5rrh8g4adx277apwp0xn-hwdata-0.392'],
'usedBy': ['/nix/store/19lnwi85piic5rrh8g4adx277apwp0xn-hwdata-0.392']},
{'closureSize': 21525128,
'layerSize': 21525128,
'paths': ['/nix/store/lz929ybayr76mwkw6la2vkkxs5xl8zx4-iso-codes-4.17.0'],
'usedBy': ['/nix/store/lz929ybayr76mwkw6la2vkkxs5xl8zx4-iso-codes-4.17.0']},
{'closureSize': 32823488,
'layerSize': 32823488,
@Lucus16
Lucus16 / fluid.zig
Last active September 29, 2024 20:16
A better fluid model for Factorio.
// Run with `zig run -lc -O ReleaseSafe fluid.zig`.
// On a Ryzen 3700X, I'm getting about 0.45 million edges per tick on a single core.
const do_output = false;
const live_output = false;
const prevent_overflow = true;
const c = @cImport({
@cInclude("stdio.h");
});
@Lucus16
Lucus16 / Futamura.hs
Last active May 8, 2024 16:21
The Futamura projections type-checked by Haskell.
{-# LANGUAGE ImpredicativeTypes #-}
module Futamura where
newtype C a = C {runC :: a}
newtype L a = L a
newtype Executable a = Executable {run :: a}
-- Given:
-- - A high level language L
@Lucus16
Lucus16 / Lifetime.hs
Created February 15, 2024 17:18
Haskell supports lifetimes!
{-# LANGUAGE RankNTypes #-}
module Lifetime where
import Data.Text (Text)
import Data.Text.IO qualified as Text
import System.IO (IOMode (..))
import System.IO qualified as Base
import Prelude hiding (Handle, withFile)
import Prelude qualified as Base
@Lucus16
Lucus16 / lineageos.md
Created December 25, 2023 22:29
Install LineageOS on a Nokia 6.1
@Lucus16
Lucus16 / splitmix.nix
Created October 30, 2023 16:21
Experiment to build haskell in pure nix
{ pkgs ? import <nixpkgs> { } }:
with builtins;
rec {
inherit (pkgs) ghc lib;
uniqueStrings = strings:
attrNames (listToAttrs (map (name: {
inherit name;