Skip to content

Instantly share code, notes, and snippets.

@carymrobbins
carymrobbins / dataclass_csv.py
Last active January 23, 2023 23:50
Example CSV row deserializer using Python dataclasses
import csv
from dataclasses import dataclass, fields, is_dataclass
from typing import TypeVar
@dataclass
class Widget:
name: str
amount: int
#!/bin/bash
set -e
n=1
sep=-
while [ $# -ne 0 ]; do
case "$1" in
-n) n=$2; shift; shift;;
@carymrobbins
carymrobbins / PSQL-Style.txt.groovy
Created November 23, 2022 17:18
Copy from IntelliJ using PSQL style output. To use it, navigate to the Project pane, expand Scratches and Consoles, and copy this script to: Extensions/Database Tools and SQL/data/extractors
// Adapted from Pretty-Groovy.txt.groovy
import com.intellij.openapi.util.text.StringUtil
/*
* Available context bindings:
* COLUMNS List<DataColumn>
* ROWS Iterable<DataRow>
* OUT { append() }
* FORMATTER { format(row, col); formatValue(Object, col); getTypeName(Object, col); isStringLiteral(Object, col); }
@carymrobbins
carymrobbins / http-client-logger.hs
Created September 15, 2022 01:09
Proof-of-concept HTTP client request logging for Haskell
#!/usr/bin/env stack
{- stack
--resolver lts-18.27
--install-ghc runghc
--package aeson
--package containers
--package http-client
--package http-types
--package monad-logger
--package text
module ContextLifted where
import Control.Monad.Catch (MonadMask)
import Control.Monad.IO.Class
import qualified Context
import qualified Context.Internal
import qualified Control.Monad.Catch as Monad.Catch
adjust :: (MonadIO m, MonadMask m) => Context.Store ctx -> (ctx -> ctx) -> m a -> m a
@carymrobbins
carymrobbins / curl-post-with-query-and-body.sh
Last active February 28, 2022 21:24
Example curl to send a POST request with URL-encoded query params and a request body
% curl \
-XPOST https://httpbin.org/post \
-G \
--data-urlencode foo=bar \
--data-urlencode baz=quux \
-T <(echo -n '{"spam": "eggs"}')
{
"args": {
"baz": "quux",
module STMUtil where
import Prelude
import Control.Concurrent.STM (STM)
import Data.HashMap.Strict (HashMap)
import Data.Hashable (Hashable)
import qualified Data.HashMap.Strict as HashMap
import qualified Debug.Trace
#!/usr/bin/env python3
import itertools
import sys
import re
vowels=set('aeiou')
alpha_only = re.compile('^[a-z]+$')
@carymrobbins
carymrobbins / THPlayground.Main.hs
Created December 20, 2021 23:57
Expect Pattern Template Haskell assertion for HUnit / Hspec
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
module THPlayground.Main where
import Control.Exception
@carymrobbins
carymrobbins / git-cleanup-untracked
Created November 4, 2021 17:38
Cleanup untracked files in your git index with fzf
#!/bin/bash
while IFS= read -r -d $'\n'; do
rm "$REPLY"
done < <(
git ls-files --others --exclude-standard \
| fzf -m \
--header='Select untracked files to delete (press TAB to select multiple)' \
--layout=reverse
)