Skip to content

Instantly share code, notes, and snippets.

@mikeplus64
mikeplus64 / routeStateMachine.ts
Last active July 20, 2020 14:31
router5 + typescript + effort
import { UnionToIntersection, DeepWritable } from 'ts-essentials';
import { State as RouteState } from 'router5';
import { Switch, createState, createEffect, createMemo } from 'solid-js';
import useRoute, { MatchRoute } from './context';
import { Routes } from './definition';
export type RenderTreeOf<Tree> =
Owned<Tree> | RenderNode &
UnionToIntersection<
Tree extends readonly (infer Node)[]
@mikeplus64
mikeplus64 / haskell-reformat
Last active March 1, 2019 07:25
apply stylish-haskell to only module preamble+imports, if stylish-haskell fails on entire module first
#!/usr/bin/env bash
INPUT="$(cat)"
IFS=''
ERRORS="$(mktemp)"
EXIT_OK=true
if ! (echo "$INPUT" | stylish-haskell 2>>"$ERRORS") ; then
#!/usr/bin/env bash
CURDIR="$PWD"
findconfig() {
# via https://unix.stackexchange.com/questions/293393/find-a-specific-file-in-the-nearest-ancestor-of-the-current-working-directory
# from: https://www.npmjs.com/package/find-config#algorithm
# 1. If X/file.ext exists and is a regular file, return it. STOP
# 2. If X has a parent directory, change X to parent. GO TO 1
# 3. Return NULL.
@mikeplus64
mikeplus64 / nix-fish-env.fish
Last active March 10, 2020 14:35
Runs nix.sh, then reads its env, and re-exports to fish anything that was found to have been exported in the script.
#!/usr/bin/env fish
# source this within config.fish
# set -l NIX_SH ~/.nix-profile/etc/profile.d/nix-daemon.sh
set -l NIX_SH ~/.nix-profile/etc/profile.d/nix.sh
# get all the vars exported by the script
set -l VARS (cat $NIX_SH | grep '^ *export' | sed 's/^ *export *//g' | cut -d= -f1 | sort | uniq)
set -l VARS_REGEX '^('(echo $VARS | tr ' ' '|')')$'
@mikeplus64
mikeplus64 / export.js
Created March 1, 2018 01:30
Export images from a table from a HTML file
/*
* Unholy script of helping to rename images exported from LibreOffice Calc.
*
* instructions:
* 1. open sheet in libreoffice calc
* 2. ensure all images entirely fit *within* the boundaries of their row
* 3. export as html
* 4. inject this script to the end of the html <body>
* 5. open html file in browser of choice
* 6. save script when prompted to same directory as html file
@mikeplus64
mikeplus64 / parser.js
Created July 21, 2017 04:09
check if arbitrary objects match some schema, allowing them to be flowtyped; better than ((thing: any): Something)
/* @flow */
export type ParseError = {
expected: string,
got: mixed,
at?: mixed,
children?: ParseError[],
};
export type Result<T> =
@mikeplus64
mikeplus64 / teamsplit.hs
Created March 15, 2017 15:11
elo db api
{- stack runghc
--package servant-server
--package servant-js
--package servant
--package text
--package mtl
--package lens
--package esqueleto
--package persistent
--package persistent-template
@mikeplus64
mikeplus64 / generated Core
Last active August 29, 2015 14:23
the magical dissappearing GHC.Generics
[1 of 1] Compiling Main ( test.hs, test.o )
==================== Simplified expression ====================
quoteExp stmt (unpackCString# "SELECT 123"#)
==================== Tidy Core ====================
Result size of Tidy Core
= {terms: 663, types: 1,112, coercions: 349}
$fSelectorAsdf4 :: [Char]
@mikeplus64
mikeplus64 / gist:f8ac7c96908e2abcba9c
Created June 24, 2015 05:41
typesafe database layer?
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE Rank2Types #-}
@mikeplus64
mikeplus64 / Main.hs
Created April 5, 2015 02:25
compiled heist not working?
{-# LANGUAGE OverloadedStrings #-}
import Blaze.ByteString.Builder
import Control.Lens
import Control.Monad.Trans.Either
import qualified Data.ByteString as B
import Data.Map.Syntax
import Heist
import Heist.Compiled
main = do