Skip to content

Instantly share code, notes, and snippets.

@pwm
pwm / default.nix
Last active March 25, 2024 13:14
Drop-in devshell
# https://gist.github.com/pwm/1380feaa134ec7f7d99d8b34a07908ad
#
# Copy this file into the root dir of the project and run `nix-shell`
#
{ compiler ? "ghc948" }:
let
pkgs = import
(builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/f8e2ebd66d097614d51a56a755450d4ae1632df1.tar.gz";
sha256 = "03cxv9h218dj7kc5hb0yrclshgbq20plyrvnfdaw5payyy9gbsfr";
#!/usr/bin/env bash
set -euo pipefail
cd "$(git rev-parse --show-toplevel)"
if [[ "$(uname)" == "Linux" ]]; then
my_cores=$(nproc)
elif [[ "$(uname)" == "Darwin" ]]; then
my_cores=$(sysctl -n hw.ncpu)
else
echo "Unknown number of cores ¯\_(ツ)_/¯"
-- Solving Fix / Mu / Nu exercise in
-- https://stackoverflow.com/questions/45580858/what-is-the-difference-between-fix-mu-and-nu-in-ed-kmetts-recursion-scheme-pac
{-# LANGUAGE RankNTypes, GADTs #-}
----------------------------------------
-- Fix / Mu / Nu
newtype Fix f = Fix { unFix :: f (Fix f) }
@pwm
pwm / DynamicBFS.hs
Created February 22, 2023 10:04 — forked from ChrisPenner/DynamicBFS.hs
Effectful, lazy, BFS using LogicT.
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module BFS where
import Control.Applicative
import Control.Monad.Logic
import Control.Monad.Reader
@pwm
pwm / hls.log
Last active March 24, 2022 20:24
HLS
~/w/haskell-language-server (master|…) $ cat notes.txt
mkdir -p /Users/$USER/.cabal/bin/8107
git clone https://github.com/haskell/haskell-language-server.git
cd haskell-language-server
cachix use haskell-language-server
nix-shell --argstr compiler ghc8107
cabal update && cabal build
cabal install --overwrite-policy=always --installdir=/Users/$USER/.cabal/bin/8107
@pwm
pwm / giffer.sh
Created February 4, 2022 10:23
Gif gen
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p ffmpeg pngquant gifski gifsicle
# shellcheck shell=bash
set -euo pipefail
if [[ "$#" -ne 3 ]]; then
echo "Usage: gif.sh <name> <scale> <fps>"
exit 1
fi
@pwm
pwm / gif.sh
Created May 24, 2021 15:26
gif.sh
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p ffmpeg pngquant gifski gifsicle
# shellcheck shell=bash
set -euo pipefail
if [[ "$#" -ne 3 ]]; then
echo "Usage: gif.sh <name> <scale> <fps>"
exit 1
fi
@pwm
pwm / A.hs
Created December 8, 2020 15:31
Generic Lens Labels
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE OverloadedLabels #-}
module A where
import Control.Lens
import Data.Generics.Labels ()
import GHC.Generics (Generic)
import Prelude
@pwm
pwm / pool_check.sh
Last active November 13, 2020 09:46
lnd_pool_check
#!/usr/bin/env bash
set -euo pipefail
function getBatchInfo() {
batch=$(sudo su - pool -c "pool auction s ${1:-""}")
batch_id=$(echo "$batch" | jq -r '.batch_id')
prev_batch_id=$(echo "$batch" | jq -r '.prev_batch_id')
batch_tx_id=$(echo "$batch" | jq -r '.batch_tx_id')
asks=$(echo "$batch" | jq -r '[.matched_orders[].ask.rate_fixed] | max')
@pwm
pwm / gisto.sh
Created November 4, 2020 20:28
gisto
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")"
if [ "$#" -ne 1 ]; then
echo "Usage: gisto.sh <user>"
exit 1
fi