Skip to content

Instantly share code, notes, and snippets.

@andrewchambers
andrewchambers / benchmark.go
Last active Aug 22, 2021
go-collectd-benchmark
View benchmark.go
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",
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
(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")))
View output.txt
running suite tester-self-test-suite
✔✔
passed 2/2
View coolpkg.md

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
andrewchambers / sysrc
Last active May 28, 2019
Janetsh sysrc nixos
View sysrc
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")))
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"
})
View errors.md

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
andrewchambers / errors.md
Created Aug 28, 2018
Error values feedback
View errors.md

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: