Skip to content

Instantly share code, notes, and snippets.

@MaxGabriel
MaxGabriel / parser.ts
Created September 24, 2018 20:27
Date parsing code
import * as P from 'parsimmon'
import Day from '~/utils/Day'
import Month from '~/utils/Month'
const shortMonths = {
jan: 1,
feb: 2,
mar: 3,
apr: 4,
may: 5,
- aeson
- aeson-casing
- aeson-iproute
- aeson-pretty
- aeson-typescript
- amazonka
- amazonka-core
- amazonka-s3
- amazonka-sqs
- async
@MaxGabriel
MaxGabriel / file.sql
Created June 2, 2023 19:56
Postgres database wiping in tests, only deleting from tables with rows, using triggers to track inserts
CREATE TABLE tables_with_insertions (
name TEXT PRIMARY KEY
);
CREATE OR REPLACE FUNCTION track_insert_for_tests()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO tables_with_insertions VALUES (TG_TABLE_NAME) ON CONFLICT ON CONSTRAINT tables_with_insertions_pkey DO NOTHING;
RETURN NEW;
@MaxGabriel
MaxGabriel / file.sql
Created August 18, 2022 19:34
Tables without primary keys
SELECT relname FROM pg_class pgc
JOIN pg_namespace pgns ON pgns.oid = pgc.relnamespace
WHERE pgns.nspname = 'public'
AND pgc.relkind = 'r'
AND pgc.oid NOT IN
(SELECT pgc.oid
FROM pg_class pgc
JOIN pg_index pgi ON pgi.indrelid = pgc.oid
JOIN pg_namespace pgns ON pgns.oid = pgc.relnamespace
@MaxGabriel
MaxGabriel / gist:80b31479813fe0f8521e0bbfa4faa597
Created June 27, 2018 19:12
Top 100,000 passwords 10 or more characters long
[
"qwertyuiop",
"1234567890",
"q1w2e3r4t5",
"1q2w3e4r5t",
"4815162342",
"0987654321",
"12345qwert",
"123456789a",
"1234554321",
@MaxGabriel
MaxGabriel / gist:eacdae1d5948d29f32fd4ed2263d5dd8
Created May 17, 2021 02:21
Table of Contents for Alexandrian Remix Fancy Props
Kalain's letter to Dalkhar
- page 118
- Four days after Dalakhar’s death, a letter arrives at the Inn of the Dripping Dagger for him.
- The late arrival of the letter is designed to push a clue to PCs after their initial visit: Those who leave their names with the owners of the Dripping Dagger, particularly those who specifically ask the owners to contact them if any new information crops up, will be rewarded with a proactive follow-up. (Alternatively, but probably less likely, it can reward PCs who follow-up on old leads.) Since the clue is non-essential for the current investigation, the slightly heightened risk of them missing the clue is offset by the benefit of adding depth to the game world: Little details like this make the players feel as if the game world is a fully functional, living environment that persists beyond their immediate line of sight. (Largely because that is, in fact, what you’re doing.)
LORD DAGULT’S PAPERS
- page 118
- Found in Kalain's Tower
- DOCUMENT LOCKBOX: A document lock
@MaxGabriel
MaxGabriel / DeriveLoadAllModels.hs
Created November 22, 2020 20:12
Template Haskell to load all Persistent models, stream them from the database, and validate they deserialize correctly
{-# LANGUAGE AllowAmbiguousTypes #-}
module Mercury.Database.Persist.DeriveLoadAllModels (mkLoadAllModels) where
import ClassyPrelude
import Control.Monad.Logger (MonadLogger, logInfoN)
import Data.Acquire (with)
import Data.Conduit (fuse, runConduit)
import qualified Data.Conduit.Combinators as Conduit
import qualified Data.Kind as K
@MaxGabriel
MaxGabriel / ekg-yesod.md
Last active August 6, 2020 09:46
Monitoring a Yesod app with EKG

Monitoring a Yesod app with EKG

Monitoring is critical to a well-functioning production system. OS-level metrics like CPU load and RAM usage are a good start, but you'll eventually want to record application-level metrics like how long it's taking you to service each HTTP request, or how much time is spent in garbage collection. Once tracked, this data can be used by humans and machines (like monitoring systems) to gain insight into how your app is running.

In this post I'll show how you can use EKG, a popular Haskell metrics library, to add application-level metrics to your Yesod app.

A Brief Overview of EKG Metric Types

EKG allows reporting four different types of metrics from your app:

@MaxGabriel
MaxGabriel / gist:167eadb8548286177ffbea95ca73757d
Created June 21, 2020 01:05
ghcid bug user error (could not create file system event stream)
This file has been truncated, but you can view the full file.
(130) ❄️ ~/D/M/h/mercury-web-backend> ghcid -o ghcid.txt --command 'cabal new-repl lib:mercury-web-backend' --allow-eval --warnings --verbose 20:58:35
%OS: darwin
%ARCH: x86_64
%VERSION: 0.7.6
Loading cabal new-repl lib:mercury-web-backend ...
%STDOUT: Build profile: -w ghc-8.6.5 -O0
%STDOUT2: Build profile: -w ghc-8.6.5 -O0
Build profile: -w ghc-8.6.5 -O0
%STDOUT: In order, the following will be built (use -v for more details):
%STDOUT2: In order, the following will be built (use -v for more details):
@MaxGabriel
MaxGabriel / gps-parser.hs
Created May 9, 2020 15:41
Degrees minutes seconds parser in haskell, for parsing e.g. 37 deg 8' 21.26" N, 80 deg 34' 41.84" W
latToDecimal :: DMSLat -> Double
latToDecimal (DMSLat dms direction) =
let decimal = dmsToDecimal
in case direction of
North -> decimal
South -> decimal * -1
lonToDecimal :: DMSLat -> Double
lonToDecimal (DMSLon dms direction) =
let decimal = dmsToDecimal