Skip to content

Instantly share code, notes, and snippets.

@nmattia
nmattia / .envrc
Created Jul 31, 2021
Dune: Uncomplicated Nix Environments
View .envrc
res=$(nix-build --no-link ./default.nix -A load)
watch_file ./default.nix
. "$res"
@nmattia
nmattia / foo.js
Last active Feb 24, 2020
rotating divs
View foo.js
let clientX_0 = 0;
let clientX_d = 0;
const MIN_WIDTH = 10;
const MIN_HEIGHT = 10;
let w0 = getpc("inner-width");
let h0 = getpc("inner-height");
let w = w0;
@nmattia
nmattia / gsop.hs
Last active Jun 26, 2018
Config with generics-sop
View gsop.hs
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
module Foo where
import Control.Monad
import qualified GHC.Generics as GHC
import qualified Generics.SOP as SOP
@nmattia
nmattia / decision_tree.py
Created May 30, 2018
Decision trees python
View decision_tree.py
import pandas as pd
import math as math
def loop(df, target):
if df.columns.size > 1:
gains = info_gains(df, target)
res = max(gains, key=gains.get)
df.groupby(res).apply(lambda v: loop(v, target))
@nmattia
nmattia / tasty-names.hs
Last active Apr 29, 2018
Access the test name in tasty
View tasty-names.hs
{-# LANGUAGE LambdaCase #-}
{-# OPTIONS_GHC "-Wall" #-}
import Data.Semigroup
import Data.Char (toLower, isAlphaNum)
import Data.List (group)
import Data.Tagged (Tagged(..))
import Test.Tasty hiding (testGroup)
import Test.Tasty.HUnit ((@=?), Assertion, testCase)
import Test.Tasty.Options (IsOption (..))
@nmattia
nmattia / pg-nix
Created Mar 12, 2018
postgresql in a shell
View pg-nix
#!/usr/env/bin bash
# vim: set ft=bash
ROOT=$PWD
read -r -d '' ADJECTIVES <<'EOF'
agreeable
brave
calm
@nmattia
nmattia / shell.nix
Created Feb 1, 2018
IHaskell and R nix shell file
View shell.nix
let
# Use pinned packages
_nixpkgs = import <nixpkgs> {};
nixpkgs = _nixpkgs.fetchFromGitHub
({
owner = "nmattia";
repo = "nixpkgs";
rev = "02359c639193103812f7356564326556cbb41ca4";
sha256= "1rg0czkxqynycw23v0dmk0vd2v17d6v3yr06bg23wqwpm3b5z0nd";
});
@nmattia
nmattia / protocols.hs
Last active Dec 4, 2017
type level protocol
View protocols.hs
{-# 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 Dec 7, 2018
Ugly nix incremental haskell build
View default.nix
# 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 Mar 4, 2017
shell.nix for crack.sh
View shell.nix
{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