Skip to content

Instantly share code, notes, and snippets.

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

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

View gist:b403c3b07015faee0e41b5f40fbcbb24
# Utility macros to define oasis packages.
(defn oasis-src
[&keys {:name name :rev rev :hash hash}]
:url (string "" name "/tarball/" rev)
:hash hash
:fname (string name ".tar.gz")))
andrewchambers / output.txt
Created December 3, 2019 01:29
View output.txt
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.
View janetsh
{ stdenv, fetchFromGitHub, janet, pkgconfig, readline80}:
stdenv.mkDerivation rec {
pname = "janetsh";
version = "0.0.1";
src = fetchFromGitHub {
owner = "andrewchambers";
repo = "janetsh";
rev = "72253ce31bee9974a2fee232cce5d049b2ade215";
andrewchambers / sysrc
Last active May 28, 2019 23:52
Janetsh sysrc nixos
View sysrc = {
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")))
View gist:9627b028b76fe376655052bbd13a1939
(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:

andrewchambers /
Created August 28, 2018 22:49
Error values feedback

In my own code, I use my own error package. My observation is that a root cause of an error is special, most values in the error chain are useless except to preserve line information. Users and debuggers usually only care about the first error and the last error in the chain.

A typical formatting of an error is "Unable to ${TOP_ACTION}: ${ROOT_CAUSE}"

A typical usage of my package is: