Skip to content

Instantly share code, notes, and snippets.

View tazjin's full-sized avatar
🥝
computers

tazjin

🥝
computers
View GitHub Profile
@tazjin
tazjin / thoughts.md
Last active August 15, 2025 18:19
Nix builder for Kubernetes
@tazjin
tazjin / cargo-update.txt
Created October 5, 2018 21:33
house cleaning in journaldriver
~/s/journaldriver $ cargo update
Updating registry `https://github.com/rust-lang/crates.io-index`
Removing adler32 v1.0.2
Updating aho-corasick v0.6.4 -> v0.6.8
Removing arrayvec v0.4.7
Adding ascii v0.9.1
Updating atty v0.2.10 -> v0.2.11
Updating backtrace v0.3.8 -> v0.3.9
Updating backtrace-sys v0.1.21 -> v0.1.24
Updating base64 v0.9.1 -> v0.9.3
@tazjin
tazjin / journald_log4rs.rs
Created September 24, 2018 17:07
journald priority decorator for log4rs
/// Implementation of a log-encoder decorator that can prepend
/// journald log priorities to any given `log4rs`-encoder.
#[derive(Debug)]
struct JournaldDecorator<E: Encode>(E);
/// Helper function to map from `log`-crate log levels to journald log
/// priorites. Please see `sd-daemon(3)` for detailed information on
/// these levels.
fn journald_priority(level: &Level) -> &'static str {
match level {
@tazjin
tazjin / Door.hs
Last active August 31, 2018 12:35
FSM typeclass demonstration
{-# LANGUAGE MultiWayIf #-}
-- | This module implements a door that can be opened and closed, and
-- locked/unlocked with a specified code when in closed state.
--
-- The state diagram looks roughly like this (p. simple):
--
-- <--Open--- <--Unlock--
-- [Opened] [Closed] [Locked]
-- --Close--> ----Lock-->
@tazjin
tazjin / Migratatable.hs
Last active August 9, 2018 09:31
Type-level Haskell programming to ensure that type versions are "migratable"
-- | A type-level, constraint-writing function that ensures that some
-- versioned type is migratable throughout its entire version history.
--
-- Assumes that type version history starts at '1'.
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
-- | Test something with an in-memory acid-state
acidTest :: forall state event query result.
(IsAcidic state, UpdateEvent event, MethodState event ~ state,
QueryEvent query, MethodState query ~ state,
MethodResult query ~ result)
=> String -- ^ Test description
-> state -- ^ Initial state for test
-> event -- ^ Event to test
-> query -- ^ Query to check
-> (result -> Bool) -- ^ Function to test query result
@tazjin
tazjin / magit-push-advise.el
Last active July 13, 2018 11:25
Advise magit-git-push to ask for user confirmation
;; This demonstrates how to advise[1] magit functions that perform
;; potentially destructive operations (for example `magit-git-push')
;; with a confirmation prompt.
;;
;; The TL;DR of advising is that a function is "wrapped" around the
;; function to be advised, with various different behaviours that can
;; be used (e.g. only conditionally executing the original function).
;;
;; [1]: https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html#Advising-Functions
;;
#!/usr/bin/env bash
set -e
function cleanup {
git checkout src/ibrowse.erl
}
trap cleanup EXIT
echo "Patching in main/1 function with hex.pm test"
# Generate an immutable /etc/resolv.conf from the networking.nameservers setting:
environment.etc."resolv.conf" = with lib; with pkgs; {
source = writeText "resolv.conf" ''
${concatStringsSep "\n" (map (ns: "nameserver ${ns}") config.networking.nameservers)}
options edns0
'';
};
@tazjin
tazjin / crius-struct.rs
Created May 10, 2018 14:51
Storing Rust crius circuit breakers in structs
extern crate crius;
use crius::command::{RunnableCommand, Command, CommandError};
/// Convenience type alias for breaker function pointers.
pub type BreakerFn<I, O> = fn(I) -> Result<O, Box<CommandError>>;
/// Convenience type alias for working with crius commands:
pub type Breaker<I, O> =
RunnableCommand<I, O,
BreakerFn<I,O>,