Skip to content

Instantly share code, notes, and snippets.

@nmattia
nmattia / pg-nix
Created March 12, 2018 22:10
postgresql in a shell
#!/usr/env/bin bash
# vim: set ft=bash
ROOT=$PWD
read -r -d '' ADJECTIVES <<'EOF'
agreeable
brave
calm
@nmattia
nmattia / shell.nix
Created February 1, 2018 10:30
IHaskell and R nix shell file
let
# Use pinned packages
_nixpkgs = import <nixpkgs> {};
nixpkgs = _nixpkgs.fetchFromGitHub
({
owner = "nmattia";
repo = "nixpkgs";
rev = "02359c639193103812f7356564326556cbb41ca4";
sha256= "1rg0czkxqynycw23v0dmk0vd2v17d6v3yr06bg23wqwpm3b5z0nd";
});
@nmattia
nmattia / protocols.hs
Last active December 4, 2017 15:44
type level protocol
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
@nmattia
nmattia / default.nix
Last active December 7, 2018 10:27
Ugly nix incremental haskell build
# Store the nix-created `dist` in `localSrc/.nix-cache` after build (whether
# successful or not) and re-injects it for subsequent builds.
#
# `./mask` should contain a haskell project with an `out.nix` file. That file
# should describe a typical cabal derivation with the extra field:
#
# preUnpack = ''
# localSrc=${toString ./.}
# '';
#
@nmattia
nmattia / shell.nix
Created March 4, 2017 23:16
shell.nix for crack.sh
{anyPkgs ? import <nixpkgs> { }}:
let
pkgs = import (anyPkgs.fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
rev = "deec3c1dae62e8345451cd8c4ad41134ab95e88d";
sha256 = "1l951xzklxfi2c161mcrps9dfsq76sj8fgq8d60y093bry66d3yc";
}) {};
ghc = pkgs.haskell.compiler.ghc7103;
# tweak haskellSrc2nix to disable (failing) tests
@nmattia
nmattia / crack.sh
Created March 4, 2017 23:15
Script to crack a LUKS partition given a fuzzy passphrase pattern
#!/usr/bin/env bash
set -e
the_pattern=$1
# We need to export because xargs runs in a subshell
export the_file=$2
if [ -z "${the_pattern}" ]; then
echo pattern missing
@nmattia
nmattia / neo.md
Created March 4, 2017 15:35
Simple neo4j type system + inference

CREATE (:Value {value_ref: 42})

CREATE (:Value {value_ref: 1789})

CREATE (:Function)

MATCH (f:Function) WHERE id(f) = 33 SET f.function_name = "inc"

@nmattia
nmattia / metamorph.hs
Created December 28, 2016 19:44
Metamorphing types in Haskell
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeInType #-}
integer/serialise/small positive -14%
integer/serialise/small negative -10%
integer/serialise/large positive -10%
integer/serialise/large negative -8%
integer/deserialise/small positive -62%
integer/deserialise/small negative -61%
integer/deserialise/large positive -27%
integer/deserialise/large negative -33%
time/serialise UTCTime -18%
time/deserialise UTCTime -21%
@nmattia
nmattia / compare-crit-csv.hs
Last active July 14, 2016 22:00
Compare criterion outputs for regression
#!/usr/bin/env stack
-- stack --install-ghc runghc --package cassava --package vector
{-|
Compare two criterion outputs. Results are displayed in percent. Takes two
filepaths: original csv and new csv.
To generate csvs:
stack bench my-project:my-bench --benchmark-arguments "--csv out.csv"