Skip to content

Instantly share code, notes, and snippets.

View 3noch's full-sized avatar
🕯️

Elliot Cameron 3noch

🕯️
  • Indiana
View GitHub Profile
@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 / 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 / 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
@3noch
3noch / Dockerfile
Last active November 27, 2020 23:23
Ubuntu with Nix Installed (Dockerfile)
FROM ubuntu:20.10
RUN apt-get update && \
apt-get install -y sudo curl xz-utils && apt-get clean && \
useradd builder -d /home/builder && \
mkdir /home/builder && chown builder /home/builder && \
echo "builder ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/user && \
chmod 0440 /etc/sudoers.d/user && \
(su builder --login -c 'curl -L https://nixos.org/nix/install | sh') && \
apt-get remove -y curl xz-utils && apt-get autoremove -y && apt-get clean && \
echo '. /home/builder/.nix-profile/etc/profile.d/nix.sh' >> /home/builder/.bashrc
@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 / drvname.nix
Created July 2, 2020 15:33
Make a string into a valid Nix derivation name
{ lib }: rec {
isValidDrvNameChar = c: "a" <= c && c <= "z" || "A" <= c && c <= "Z" || "0" <= c && c <= "9" || c == "+" || c == "-" || c == "_" || c == "?" || c == "=" || c == ".";
makeValidDrvName = { str, replacement ? "?" }:
let
newName = lib.stringAsChars (c: if isValidDrvNameChar c then c else replacement) str;
in if builtins.substring 0 1 newName == "." then "_" + newName else newName;
}
@3noch
3noch / materialize.nix
Last active June 18, 2020 12:21
Materialize Nix Expr
{ pkgs ? import (builtins.fetchTarball {
url = https://releases.nixos.org/nixpkgs/nixpkgs-20.09pre229671.9d0c3ffe678/nixexprs.tar.xz;
sha256 = "0apkg6kamf15v32j2kddrl8mf0l79frczrn5nlbab76dv9gdq008";
}) {}
}:
let
githubData = {
owner = "MaterializeInc";
repo = "materialize";
rev = "39faa05714a6e78e8d9e8b518cd39f94e9201e5a";