Skip to content

Instantly share code, notes, and snippets.

@andrewchambers
andrewchambers / benchmark.go
Last active August 22, 2021 12:11
go-collectd-benchmark
func BenchmarkWriteEncryptedPacket(bench *testing.B) {
bench.ReportAllocs()
out := make([]byte, 65535)
ctx := context.Background()
b := NewBuffer(0)
b.Encrypt("user", "password")
vl := &api.ValueList{
Identifier: api.Identifier{
Host: "example.com",
Plugin: "golang",

A DSL for scripting

In most programming languages to run a sub command you need to go through quite a lot of ceremony. This post covers my design of a domain specific language to solve this problem for Janet (One of my favourite programming languages).

First, let's set compare simple tasks you might perform during

(import https://raw.githubusercontent.com/andrewchambers/hpkgs/49aa40b0776789c1741124bb4ebd35c52c23e7f5/core)
# Utility macros to define oasis packages.
(defn oasis-src
[&keys {:name name :rev rev :hash hash}]
(fetch
:url (string "https://github.com/michaelforney/" name "/tarball/" rev)
:hash hash
:fname (string name ".tar.gz")))
@andrewchambers
andrewchambers / gist:1c473fd1595f4fcedbcfc634ee1decb0
Last active March 19, 2020 00:41
full disk encrypted nixos install
#! /bin/sh
set -e
set -u
set -x
# configure this!
hostname="nixos"
password="abc123"
diskdev=/dev/sda
@andrewchambers
andrewchambers / output.txt
Created December 3, 2019 01:29
self-test
running suite tester-self-test-suite
✔✔
passed 2/2

Concept for coolpkg

Coolpkg is a new decentralized, time traveling package manager that ...

  • Solves dependency hell.
  • Gives you reproducible builds.
  • Makes it easy to share programs with your friends (or worst enemy, it doesn't care.).
  • Works well with existing tools (docker, various operating systems and more).
  • Is fun to use.
{ stdenv, fetchFromGitHub, janet, pkgconfig, readline80}:
stdenv.mkDerivation rec {
pname = "janetsh";
version = "0.0.1";
src = fetchFromGitHub {
owner = "andrewchambers";
repo = "janetsh";
rev = "72253ce31bee9974a2fee232cce5d049b2ade215";
@andrewchambers
andrewchambers / sysrc
Last active May 28, 2019 23:52
Janetsh sysrc nixos
users.extraUsers.ac = {
shell = "${janetsh}/bin/janetsh-posix-wrapper";
};
environment.etc."janetsh.rc".text = ''
(import posixsh)
(def env-blacklist @{"_" true})
(when (not (= "1" (os/getenv "__NIXOS_SET_ENVIRONMENT_DONE")))
(set *hist-file* (first (sh/expand "~/.janetsh.hist")))
(def tc
{
# The wrapping \x01 ... \x02 tell readline the surrounded string has zero length.
# Without it we get strange artifacts in the string history.
:bold "\x01\x1b[1m\x02"
:none "\x01\x1b[0m\x02"
})

My observation is that a root cause of an error is special, I usually only care about the first error and the last error in the chain except for logs.

In the end I disliked pkg/errors naming conventions and wrote my own small package.

A typical usage of my package in a server: