Skip to content

Instantly share code, notes, and snippets.

View chpatrick's full-sized avatar

Patrick Chilton chpatrick

View GitHub Profile
@chpatrick
chpatrick / swim_mp3.py
Created May 8, 2024 10:45
Python script for copying podcasts/audiobooks to an MP3 player. This is useful for waterproof MP3 players like the Shokz OpenSwim that have limited controls. This will take any format, apply loudness normalization, split it into 5 minute chunks and copy it to the player as MP3. Requires ffmpeg and mp3splt.
import argparse
from pathlib import Path
import tempfile
from subprocess import check_call
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--input", type=Path, required=True)
parser.add_argument("--media-dir", type=Path, default=Path("/run/media/your_user/your_device"))
@chpatrick
chpatrick / flashback-xmonad.nix
Last active January 8, 2023 08:59
Gnome Flashback with XMonad on NixOS
{
services.displayManager.extraSessionFilePackages =
let gnome-flashback-xmonad = pkgs.callPackage ({ stdenv, gnome3, bash, haskellPackages, glib, wrapGAppsHook }: stdenv.mkDerivation {
name = "gnome-flashback-xmonad";
buildInputs = [ gnome3.gnome-flashback gnome3.gnome-panel bash haskellPackages.xmonad glib ];
nativeBuildInputs = [ wrapGAppsHook ];
unpackPhase = "true";
@chpatrick
chpatrick / nix-cmake
Created September 15, 2018 11:38
Using CLion with Nix
#!/usr/bin/env python3
# let's say you have a C++ project in Nix that you want to work on with CLion so that the Nix dependencies are available
# put this script in your project directory
# then, in Settings -> Build, Execution, Deployment -> Toolchains set CMake to this script
# if you need any extra nix-shell arguments, add them to the invocation at the bottom
import os
import sys
import shlex
@chpatrick
chpatrick / hs-clamscan.hs
Last active February 22, 2018 10:56
Haskell virus scanner
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC
import System.Process.ByteString
import System.Exit
data VirusScanResult
= VSRClean
| VSRVirusFound BS.ByteString
deriving (Eq, Ord, Show)

Keybase proof

I hereby claim:

  • I am chpatrick on github.
  • I am chpatrick (https://keybase.io/chpatrick) on keybase.
  • I have a public key whose fingerprint is 6201 EA12 3C34 F7ED BD9D 0C12 47F5 0B15 D747 AA30

To claim this, I am signing this object:

@chpatrick
chpatrick / monad-search.hs
Last active July 27, 2016 11:50
monad-dijkstra++
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TupleSections #-}
module Lib where
import Control.Applicative
import Control.Monad.Identity
import Control.Monad.Trans.Free
@chpatrick
chpatrick / solga.hs
Last active April 11, 2017 13:28
Solga - servant but better
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DeriveFunctor, GeneralizedNewtypeDeriving, MultiParamTypeClasses, InstanceSigs, ScopedTypeVariables, RankNTypes #-}
import Control.Monad.Codensity
import Control.Monad.Free
import Control.Monad.State
data Source = Deck | Discard
data Card
data Player
@chpatrick
chpatrick / demote.hs
Last active August 29, 2015 14:24
Demoting DataKinds from Template Haskell
{-# LANGUAGE FlexibleInstances, TypeOperators, PatternSynonyms, LambdaCase, TupleSections, DefaultSignatures, FlexibleContexts, DeriveAnyClass #-}
import Control.Applicative
import Control.Monad.State.Strict
import Language.Haskell.TH
import Language.Haskell.TH.Syntax
import GHC.Generics
newtype DemotedSymbol = DemotedSymbol { getSymbol :: String }
deriving (Eq, Ord, Show)
@chpatrick
chpatrick / lazy-parsers.hs
Last active December 18, 2017 00:39
Regex-style lazy parsers
{-# LANGUAGE FlexibleInstances, GeneralizedNewtypeDeriving, PatternSynonyms, RankNTypes #-}
import Control.Applicative
import Control.Monad.Codensity
import Control.Monad.Trans
import Text.Parser.Combinators
import Text.Parser.Char
import qualified Data.Attoparsec.ByteString.Char8 as AP