Skip to content

Instantly share code, notes, and snippets.

View Brettm12345's full-sized avatar
:octocat:
Working from home

Brett Mandler Brettm12345

:octocat:
Working from home
View GitHub Profile
@Brettm12345
Brettm12345 / useDiscount.ts
Created September 12, 2021 19:16
Discount Provider With fp-ts
import {AllDiscountsQuery, useAllDiscountsQuery} from '../../generated/graphql';
import * as A from 'fp-ts/Array';
import * as O from 'fp-ts/Option';
import {flow, pipe} from 'fp-ts/function';
import constate from 'constate';
import {ApolloError} from '@apollo/client';
type ProductType = 'variant' | 'product';
type Discount<
@Brettm12345
Brettm12345 / AuthApolloProvider.tsx
Created September 12, 2021 18:21
Apollo Provider with Auth and FP-TS
import {
ApolloLink,
ApolloProvider,
ApolloClient,
InMemoryCache,
HttpLink,
split,
FetchResult,
} from '@apollo/client';
import {BatchHttpLink} from '@apollo/client/link/batch-http';
@Brettm12345
Brettm12345 / sk-hoogle.sh
Created February 11, 2020 16:42
Fuzzy search through hoogle
#! /usr/bin/env nix-shell
#! nix-shell -i sh -p hoogle skim
sk -i -c "hoogle -q --count=50 '{}'" --preview="hoogle -i '{1..2}'" --cmd-prompt="hoogle> "
@Brettm12345
Brettm12345 / nixos-option.sh
Last active February 4, 2021 13:30
nixos-option with fzf
#! /usr/bin/env nix-shell
#! nix-shell -i sh -p jq fzf
OPTION_CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/nixos-options.json"
test -f "$OPTION_CACHE" || {
echo "Building cache..."
cp "$(export NIXPKGS_ALLOW_UNFREE=1; nix-build -Q --no-out-link '<nixpkgs/nixos/release.nix>' -A options)/share/doc/nixos/options.json" "$OPTION_CACHE"
}
OPTION=$(jq -r 'keys | join("\n")' "$OPTION_CACHE" | fzf --height "60%" --preview 'nixos-option {}')
@Brettm12345
Brettm12345 / nix-install.sh
Last active February 10, 2020 05:14
Nixos package install script with FZF
#! /usr/bin/env nix-shell
#! nix-shell -i sh -p jq awk fzf
PKG=$(nix search "$1" --json \
| jq -r '. | to_entries | map("\(.key)|\(.value.version)|\(.value.description)") | join("\n")' \
| awk -F "|" '{ printf "\033[34m%-40s \033[32m%-20s \033[0m%s\n", $1, $2, $3 }' \
| fzf \
| awk '{ print $1 }'
)
@Brettm12345
Brettm12345 / Css.purs
Created January 25, 2020 23:47
Purescript tailwind css parser
module Css
( parseName, parseClass
) where
import Prelude
import Control.Alt ((<|>))
import Data.Array as Array
import Data.Char.Unicode (toUpper)
import Data.List (elem, many)
import Data.Maybe (Maybe, fromMaybe, isNothing)
@Brettm12345
Brettm12345 / localStorage.ts
Last active December 18, 2019 08:42
Safe localStorage with fp-ts for ssr applications
import * as ls from 'fp-ts-local-storage'
import { io } from 'fp-ts/lib/IO'
import { none } from 'fp-ts/lib/Option'
import { fold } from 'fp-ts/lib/boolean'
import { constVoid, flow } from 'fp-ts/lib/function'
import { curry } from 'ramda'
const isBrowser = io.of(typeof localStorage === "undefined");
const foldIo = curry(
@Brettm12345
Brettm12345 / Windows.hs
Created December 6, 2019 06:31
WIndow keybinds
module Bind.Keys.Windows
( windows
)
where
import XMonad.Actions.Promote ( promote )
import Bind.Keys.Internal ( Keymap
, subKeys
, zipKeys
, directionKeys
, directions
@Brettm12345
Brettm12345 / internal.hs
Created December 6, 2019 06:29
Internal Keymaps
module Bind.Keys.Internal where
import XMonad ( XConfig
, KeyMask
, X
, KeySym
, mod4Mask
, xK_Super_L
)
import XMonad.Util.NamedActions ( addName
@Brettm12345
Brettm12345 / Layouts.hs
Created December 6, 2019 06:19
XMonad Layouts
{-# OPTIONS -fno-warn-missing-signatures #-}
module Container.Layout
( layout
)
where
import XMonad ( (|||) )
import XMonad.Layout ( Full(..) )
import XMonad.Hooks.ManageDocks ( avoidStruts )