Skip to content

Instantly share code, notes, and snippets.

View purcell's full-sized avatar

Steve Purcell purcell

View GitHub Profile
@purcell
purcell / taskqueues.sql
Last active March 19, 2021 08:35
Easy task queues using PostgreSQL
-- Let's say you have a table full of work:
CREATE TABLE tasks (
id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(),
status TEXT NOT NULL DEFAULT 'pending',
payload JSON NOT NULL, -- or just have meaningful columns!
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);
@purcell
purcell / auto-python-venv.md
Last active July 27, 2021 19:12
Sane automatic python + virtualenv

Automatic python version plus venv

Goal

For easy editor integration and command-line usage, we'd like to be able to specify a Python version per project, with its own virtualenv to isolate its libraries from those of other projects.

We're willing to change $PATH globally once, but not per project. And we'd like to avoid having to run every python command invocation in a special subshell created by a shell wrapper. Instead, simply invoking "python" or "pip" etc. should do the right thing, based on the directory in which it is invoked.

It turns out this is possible!

@purcell
purcell / eglot-with-flycheck.el
Created October 10, 2019 20:39
Make eglot use flycheck
(defvar-local flycheck-eglot-current-errors nil)
(defun flycheck-eglot-report-fn (diags &rest _)
(setq flycheck-eglot-current-errors
(mapcar (lambda (diag)
(save-excursion
(goto-char (flymake--diag-beg diag))
(flycheck-error-new-at (line-number-at-pos)
(1+ (- (point) (line-beginning-position)))
(pcase (flymake--diag-type diag)
@purcell
purcell / Req-reformatted.hs
Created November 3, 2019 02:52
Reformatter slowness
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
@purcell
purcell / shell.nix
Last active May 22, 2020 02:43
shell.nix with nimlsp
let
# Assumes niv sources, which should include the repos for
# nimlsp, ast-pattern-matching and jsonschema.
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs {};
unpackedSource = d: d.overrideAttrs (orig: {
name = "${orig.pname}-source";
phases = ["unpackPhase" "patchPhase" "installPhase"];
installPhase = "mkdir $out; cp -aR . $out/.";
@purcell
purcell / 0001-Use-upstreamed-poetry2nix-overrides-for-hid-and-pyus.patch
Created May 11, 2021 03:12
Use upstreamed poetry2nix overrides for hid and pyusb
From 96f7801fd773242cb584d68415b6c72b7db1e123 Mon Sep 17 00:00:00 2001
From: Steve Purcell <steve@sanityinc.com>
Date: Tue, 11 May 2021 15:10:45 +1200
Subject: [PATCH] Use upstreamed poetry2nix overrides for hid and pyusb
---
nix/sources.json | 12 ++++++++++++
shell.nix | 32 +++++---------------------------
2 files changed, 17 insertions(+), 27 deletions(-)
@purcell
purcell / keybase.md
Created June 23, 2023 12:37
keybase

Keybase proof

I hereby claim:

  • I am purcell on github.
  • I am sanityinc (https://keybase.io/sanityinc) on keybase.
  • I have a public key ASD6Zb31etK_0lSccFnXOXQKEk2S1137StrRR5dfWAn4Jgo

To claim this, I am signing this object:

This file has been truncated, but you can view the full file.
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/8lsf1rrc5d3cgn2i1as76l2k3yr16k9r-ocaml-5.0.0.tar.xz
source root is ocaml-5.0.0
setting SOURCE_DATE_EPOCH to timestamp 1671176928 of file ocaml-5.0.0/yacc/wstr.c
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
updateAutotoolsGnuConfigScriptsPhase
Updating Autotools / GNU config script to a newer upstream version: ./build-aux/config.sub
@purcell
purcell / icfpcs.md
Created July 10, 2023 18:46
My ICFP Contest history
@purcell
purcell / wrap-aws-auth
Created August 17, 2023 14:16
Invoke a command with AWS auth obtained from 1password
#!/bin/bash -e
error_exit() {
echo "$1" >&2
exit 1
}
usage_exit() {
cat <<EOF >&2
Looks up your AWS keys from your 1Password and exports them before running the next command