Skip to content

Instantly share code, notes, and snippets.

View 3noch's full-sized avatar
🕯️

Elliot Cameron 3noch

🕯️
  • Indiana
View GitHub Profile
@3noch
3noch / Distributed Builds.md
Last active January 4, 2024 14:34
How to set up distributed builds with nix

Reference: https://github.com/LnL7/nix-docker

# If on Darwin, I recommend keeping nix stuff contained
mkdir -p /nix/etc/nix
ln -s /nix/etc/nix /etc/nix  # sysconfdir; can be overridden with $NIX_CONF_DIR

cd /nix/etc/nix/
openssl genrsa -out signing-key.sec 2048
openssl rsa -in signing-key.sec -pubout > signing-key.pub
@3noch
3noch / ListView.py
Last active June 20, 2023 12:01
ListView.py
class ListView():
def __init__(self, items, slice_=None):
start = (slice_.start if slice_ else None) or 0
stop = (slice_.stop if slice_ else None) or float('inf')
step = (slice_.step if slice_ else None) or 1
if isinstance(items, ListView):
self._items = items._items
self._start = max(items._start, items._start + start)
self._stop = min(items._stop, items._start + stop)
self._step = items._step * step
@3noch
3noch / shell.nix
Created June 2, 2023 20:25
nix-shell VSCode Golang
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell rec {
packages = with pkgs; [ delve go gopls go-outline go-tools libkrb5.dev ];
WORKSPACE_ROOT = toString ./.;
# VSCode's Go plugin doesn't play well with nix shells, so we create a custom directory for all our tools and tell the plugin to use it.
shellHook = ''
initNixShell() {
echo Initializing Nix shell
@3noch
3noch / nix-wrap
Last active May 19, 2022 09:00
Command-line wrapper to put commands within a nix-shell using the nearest parent shell.nix file.
#!/usr/bin/env bash
# based on discussion: https://github.com/atom-haskell/haskell-ghc-mod/issues/160
origdir=$PWD
# Source nix env because this script is intended to be
# used by editors, e.g. Atom which doesn't source .bashrc,
# and we need NIX_PATH to be set correctly.
source ~/.nix-profile/etc/profile.d/nix.sh
@3noch
3noch / tiny_cli.rs
Created February 14, 2022 09:25
tiny_cli.rs
use std::str::FromStr;
#[derive(Debug, Clone, PartialEq, Eq)]
enum Error {
PositionalArgExpected(String),
FlagExpectedValue(String),
ConversionFailed(String),
}
/// A trait for types that can represent a command-line argument or flag.
@3noch
3noch / Functor.py
Last active December 20, 2021 21:41
Functors in Python
import types
global fmap_vtable
fmap_vtable = {}
def fmap_for(type):
def register_fmap(func):
fmap_vtable[type] = func
return func
@3noch
3noch / Containers.hpp
Last active February 23, 2021 05:07
C++ FRP
// Various functions for working with containers of any kind.
#pragma once
#include <boost/optional.hpp>
#include <vector>
// -------- Advanced C++ Trickery ----------------
// From https://stackoverflow.com/a/7943765/503377
@3noch
3noch / NonEmpty.h
Created February 15, 2021 06:06
NonEmpty type for C++
template<typename T, typename Container = std::vector<T>>
struct NonEmpty {
using iterator = typename Container::iterator;
using const_iterator = typename Container::const_iterator;
iterator begin()
{
return c_.begin();
}
iterator end()
@3noch
3noch / units.cpp
Created January 7, 2021 21:57
C++ Typesafe Units
#include <iostream>
#include <math.h>
struct RTK{};
struct Barometer{};
struct Meters{};
template<typename Repr, typename Self>
struct UnitWrapped {
@3noch
3noch / CommandLog.sh
Created December 8, 2020 21:18
NixOS Install Dual-Boot Windows on encrypted ZFS root
# 1. Install Windows 10 but leave a chunk of your drive unpartitioned
# 2. Within Windows create a new partition for your NixOS install
# 3. Create an installation disk/USB for NixOS
# 4. Boot into NixOS graphical installer
# 5. Open GParted so you can make sure you've selected the right drives (ls -lah /dev/disk/by-id/... will tell you what drive the path is symlinked to)
# 6. Run the following!
TARGET_DISK="/dev/disk/by-id/nvme-Force_MP600_20468229000128554A4B-part5"
sudo zpool create -o ashift=12 -O acltype=posixacl -O compression=lz4 -O dnodesize=auto -O normalization=formD -O relatime=on -O xattr=sa -O mountpoint=none zroot "$TARGET_DISK"
sudo zfs create -o encryption=aes-256-gcm -o keyformat=passphrase -o mountpoint=none zroot/crypt