Skip to content

Instantly share code, notes, and snippets.

View simonmichael's full-sized avatar

Simon Michael simonmichael

View GitHub Profile
@simonmichael
simonmichael / a.bash
Created July 8, 2023 17:56
options parsing in bash
declare -A FLAGS
declare -a ARGS
while [[ $# -gt 0 ]]; do
key="$1"
@simonmichael
simonmichael / accounts.txt
Last active May 30, 2023 09:43
a sample *ledger chart of accounts (first 3 levels): combined personal & business, eg for a freelancer
assets
business
accounts receivable
bank
personal
accounts receivable
bank
cash
gifts
online
@simonmichael
simonmichael / gist:1185421
Created September 1, 2011 03:59
ghc-pkg-clean, ghc-pkg-reset
# unregister broken GHC packages. Run this a few times to resolve dependency rot in installed packages.
# ghc-pkg-clean -f cabal/dev/packages*.conf also works.
function ghc-pkg-clean() {
for p in `ghc-pkg check $* 2>&1 | grep problems | awk '{print $6}' | sed -e 's/:$//'`
do
echo unregistering $p; ghc-pkg $* unregister $p
done
}
# remove all installed GHC/cabal packages, leaving ~/.cabal binaries and docs in place.
@simonmichael
simonmichael / init.el
Last active March 16, 2023 09:30
emacs: simple window splitting policy
;; Try to ensure sensible window splitting, independent of frame and font size.
;; Things I don't want:
;; - excessive horizontal splitting (generally I prefer no more than 2 windows across)
;; - horizontal splitting when frame is tall and narrow (causing eg useless narrow man page formatting)
;; So, aim for a simple policy: popup windows shall be half width in a wide frame,
;; half height in a tall frame.
;;
;; Emacs' window splitting behaviour is complex and must be read carefully.
;; In particular, note: it checks split-window-height first, and if that permits it to
;; split vertically, it does that and split-window-horizontally is ignored.
@simonmichael
simonmichael / pricing.ledger
Created May 14, 2019 15:09
Testing ledger cost/price syntax, lots, revaluation, capital gains
; Test ledger cost/price syntax, lots, revaluation, capital gains
P 2019-01-01 ETC 11 EUR
P 2019-02-01 ETC 12 EUR
; Fluctuating cost/price
; @, @@ https://www.ledger-cli.org/3.0/doc/ledger3.html#Posting-cost
; { }, {{ }} https://www.ledger-cli.org/3.0/doc/ledger3.html#Commodity-prices
; "functionally.. no difference" https://www.ledger-cli.org/3.0/doc/ledger3.html#Prices-versus-costs
@simonmichael
simonmichael / part1.md
Last active December 24, 2022 19:47
haskell programming with chatgpt, parsec task, from galactic_starfish on Haskell chat, reformat of https://gitlab.com/-/snippets/2476602

Parser P.1

Human: write me an example parser using the applicative style and 3 different tokens using the latest version of parsec in haskell.


Assistant:

Sure! Here is an example parser using the applicative style and 3 different tokens using the latest version of Parsec in Haskell:

  Copy code
import Text.Parsec

-- Our three tokens are integers, floating point numbers, and strings data Token = IntToken Int | FloatToken Double

@simonmichael
simonmichael / 20221218.org
Last active December 21, 2022 18:37
Results from a run of hledger's ledger-compat test suite

Tested 2022-12-18 with hledger 1.28.99-g016b7759f-20221209, mac-aarch64

@alias

../regress/1384C1D8.test: [Failed]

Command (at line 20): hledger -f- check Expected stderr:

Got stderr: hledger: Error: -:1:1:

@simonmichael
simonmichael / hledger-lib.ghctimes.org
Last active March 25, 2022 22:10
GHC 9.0.2 -ddump-timings output for hledger-lib on a macbook air m1, showing the stack command and some emacs viewing tricks

stack build hledger-lib –force-dirty –ghc-options=’-fforce-recomp -ddump-timings’ -*- mode:org; eval:(hi-lock-mode 1); -*-

Hi-lock: ((“alloc=\w+” (0 ‘hi-blue-b t))) Hi-lock: ((“time=\w\w\w.*” (0 ‘hi-red-b))) Hi-lock: ((“time=\w\w\w\w.*” (0 ‘highlight))) Hi-lock: end

hledger-lib-1.25.99: unregistering (–force-dirty specified) hledger-lib> configure (lib) Configuring hledger-lib-1.25.99…

initializing unit database:

@simonmichael
simonmichael / SM's Haskell Survival Guide.md
Last active March 5, 2022 03:26
SM's Haskell Survival Guide (draft)

SM's Haskell Survival Guide

Somewhat-repeatable recipes for getting a reliable haskell build toolchain installed as of 2022Q1. You might need to make adjustments, eg on Windows, but hopefully not too many.

Set up with ghcup

Current most popular method. Best way to get native arm tools on mac m1. You can use it to install the compiler ghc, build tools cabal and/or stack, and IDE/editor language server hls (under $HOME/.ghcup). Actively maintained.

  • install latest ghcup (manages haskell core tools)
@simonmichael
simonmichael / sm-Ledger.st
Created May 3, 2014 17:15
a prototype squeak port of Ledger, 2007
"
prototype ledger file parser in squeak
Simon Michael
test scripts:
s1 := LedgerParserTests sample1 readStream
PositionableStream
2007/10/7 the fairmont sonoma mission inn & spa
expenses:food:dining $11