Skip to content

Instantly share code, notes, and snippets.

@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;
@Lucus16
Lucus16 / SafeIO.hs
Created August 16, 2023 11:56
Proof of concept for interruptible-checked IO
module System.SafeIO where
import "base" Control.Concurrent ( ThreadId )
import "base" Control.Concurrent qualified as Unsafe
import "base" Control.Exception ( AsyncException(..), Exception(..) )
import "base" Control.Exception qualified as Unsafe
import "base" Prelude ( Applicative(..), Functor(..), Monad(..), const, ($), (.) )
import "base" System.IO qualified as Unsafe
data Uninterruptible
newtype Pool r = Pool (TVar (Seq r))
newPool :: [r] -> IO (Pool r)
newPool = fmap Pool . newTVarIO . Seq.fromList
getResource :: Pool r -> IO r
getResource (Pool pool) = STM.atomically do
rs <- STM.readTVar pool
case rs of
Seq.Empty -> STM.retry