Skip to content

Instantly share code, notes, and snippets.

@chrisdone
chrisdone / README.md
Last active September 27, 2023 10:54
Indexed fields exploration

Exploring possibilities with simple indexed fields

Database records and formlets and optionally populated records can be neatly all represented with the same data type when the fields are all indexed.

class Indexed i a where
  type Index i (a :: *)
@chrisdone
chrisdone / review.md
Last active August 14, 2023 23:40
Email message parsing in Haskell in 2018

Email message parsing in Haskell in 2018

Background: I am moving away from GMail to my own Haskell-based server (SMTP receiver/sender, web-based email client, spam filtering, etc.). All email to @chrisdone.com goes through this server (mx.chrisdone.com) as of today, and chrisdone@gmail.com forwards a copy of everything to it.

This is a summary/tracking document of my efforts to simply parse email messages in Haskell for the SMTP receiver.

@chrisdone
chrisdone / shoe.el
Created July 13, 2023 16:01
shoe.el
(defun shoe-write-script (script)
"Write SCRIPT to the proper place."
(let* ((script-dir (shoe-script-dir script))
(script-path (shoe-script-file-path "/" script-dir)))
(with-temp-file script-path (insert script))))
(defun shoe-script-file-path (script &optional dir)
"Produce the file path for SCRIPT."
(concat (or dir (shoe-script-dir script))
"/"
@chrisdone
chrisdone / Intro.md
Last active April 10, 2023 06:33
Statically checked overloaded strings

Statically checked overloaded strings

This gist demonstrates a trick I came up with which is defining IsString for Q (TExp a), where a is lift-able. This allows you to write $$("...") and have the string parsed at compile-time.

On GHC 9, you are able to write $$"..." instead.

This offers a light-weight way to enforce compile-time constraints. It's basically OverloadedStrings with static checks. The inferred return type

{-
Examples:
> reify @Int $ eval $ A (reflect (abs :: Int -> Int)) (I (-9))
9
> reify @Int $ eval $ A (A (reflect ((*) :: Int -> Int -> Int)) (reflect @Int 3)) (reflect @Int 5)
15

Installing a TLS SSL certificate in HAProxy from Namecheap - Sectigo Limited certificate

When buying an SSL certificate from Namecheap, you generate a CSR, which generates a private key, save that for later as private.key.

After you've paid for your certificate, you recieve a zip file that looks like this:

$ ls -alh
total 52K
FROM ubuntu:20.04
RUN apt-get update -y
RUN apt-get install -y python pip
COPY . /home/chris/Work/alphacephei/vosk-server
WORKDIR /home/chris/Work/alphacephei/vosk-server
RUN pip install -r requirements.txt && pip3 install sounddevice
RUN apt-get install -y libportaudio2
@chrisdone
chrisdone / hoogle.md
Last active September 6, 2022 20:33
stack hoogle

Introducing the stack hoogle feature!

With the release of hoogle5, we can now hoogle all local packages.

This let us implement stack hoogle, which is on the master branch of stack, but is not yet on a stack release. We'd like you to try it out before we do!

To upgrade to the latest stack from git, use:

@chrisdone
chrisdone / BoxedVectors.hs
Last active July 24, 2022 07:35
Mutable Vectors in Haskell
-- This module demonstrates boxed vectors. That means they
-- contain values which are thunks, aka values of kind *, aka
-- values which may contain _|_. You can write any Haskell
-- value in here.
--
-- Optimizations:
--
-- 1) Use unsafeFreeze to avoid copying. See its haddocks.
-- 2) Use unsafeRead/unsafeWrite. These are, clearly, unsafe
import System.Posix.Signals
main = do
mainId <- RIO.myThreadId
_ <-
installHandler
softwareTermination
(CatchOnce
(do S8.putStrLn "Received SIGTERM. Killing main thread."
killThread mainId))