Skip to content

Instantly share code, notes, and snippets.

View Profpatsch's full-sized avatar
🌮

Profpatsch

🌮
View GitHub Profile
@Profpatsch
Profpatsch / llm_replace_commandline.fish
Created March 14, 2025 22:35
pass everything after :: to an LLM and replace the output in the fish shell command line
function llm_replace_commandline
set -l cmdline (commandline)
# Extract everything after '::' (last captured group), and use the name as template
set -l extracted (string match --groups-only -r '.*::(\S+)?\W?(.*)$' -- $cmdline)
# If no match, do nothing
if test -z "$extracted"
notify-send "no :: match"
return
module Builder where
import Data.ByteString.Builder qualified as Bytes
import Data.ByteString.Lazy qualified as Bytes.Lazy
import Data.Functor.Contravariant
import Data.String
import Data.Text.Lazy qualified as Text.Lazy
import Data.Text.Lazy.Builder qualified as Text
import Data.Text.Lazy.Builder.Int qualified as Text
import MyPrelude
@Profpatsch
Profpatsch / Permission.hs
Created September 2, 2024 12:16
A simple capability-based type- and value-level permission system for Haskell projects
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Permissions
( Permission,
PermissionLabel,
HasPermission,
let
pkgs = import <nixpkgs> {};
lib = pkgs.lib;
allOptions = (import <nixpkgs/nixos> {}).options;
# ** some helpers
# Like mapAttrs, but if `null` is returned from the mapping function,
# the element is removed from the attrset.
#
@Profpatsch
Profpatsch / JsonWithSummedTypes.hs
Created November 12, 2023 16:26
Parser for a json dialect which supports tagged values/sums of the syntax: `< "key": value >`
module Abc (jsonWith') where
import Data.Aeson hiding (Value (..))
import Data.Aeson.Key qualified as Key
import Data.Aeson.KeyMap qualified as KM
import Data.Aeson.Parser.Internal hiding (jsonWith')
import Data.Attoparsec.ByteString qualified as A
import Data.Attoparsec.ByteString.Char8 (Parser, char, string)
import Data.Function (fix)
import Data.Functor (($>))
@Profpatsch
Profpatsch / PostgresDecoder.hs
Created October 25, 2023 19:31
nest json parser into postgres parsers
module Postgres.Decoder where
import Control.Applicative (Alternative)
import Data.Aeson qualified as Json
import Data.Aeson.BetterErrors qualified as Json
import Data.Error.Tree
import Data.Typeable (Typeable)
import Database.PostgreSQL.Simple.FromField qualified as PG
import Database.PostgreSQL.Simple.FromRow qualified as PG
import Json qualified
@Profpatsch
Profpatsch / summary.org
Last active October 19, 2023 11:53
Summary of the Talk “Literate DevOps With Emacs”
@Profpatsch
Profpatsch / !nix-build-if-changed.py
Last active July 13, 2023 18:35
build a nix expression, but only if it isn’t already available in substituters; skip downloading the results if that is the case.
#!/usr/bin/env python3
# Small wrapper around nix-instantiate and `nix-store --realize`
# that checks whether the output path is already in a cache
# and if it isn’t, builds it.
#
# The arguments you pass will be given to nix-instantiate,
# not to nix-store --realize
# (This might be a TODO for the future).
@Profpatsch
Profpatsch / Label.hs
Last active May 19, 2023 11:12
Labelled Tuples/Enums in GHC >9.2 Haskell (Hackage: https://hackage.haskell.org/package/pa-label)
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE LambdaCase #-}
module Label
( -- * Labels
Label,
label,
label',
getLabel,
@Profpatsch
Profpatsch / IntegerLiteralOnly.hs
Last active April 3, 2023 17:01
Implement only `fromInteger` for types where num-literals are possible, with less boilerplate
-- | Implement this class if you want your type to only implement the part of 'Num'
-- that allows creating them from Integer-literals, then derive Num via 'NumLiteralOnly':
--
-- @
-- data Foo = Foo Integer
-- deriving (Num) via (NumLiteralOnly "Foo" Foo)
--
-- instance IntegerLiteral Foo where
-- integerLiteral i = Foo i
-- @