Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / tasty-names.hs
Last active April 29, 2018 21:30
Access the test name in tasty
{-# 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 / decision_tree.py
Created May 30, 2018 18:54
Decision trees python
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 / gsop.hs
Last active June 26, 2018 13:04
Config with generics-sop
{-# 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 / default.nix
Last active October 19, 2023 22:04
Report for runtime dependencies of a derivation
# MIT License, see below
#
# These are some helpers for figuring out the derivations attributes of runtime
# dependencies of a derivation, in particular the function `runtimeReport`. At
# the bottom of the file you can see it used on `hello`. Spoiler: glibc is a
# runtime dependency.
# For more info see
#
# https://nmattia.com/posts/2019-10-08-runtime-dependencies.html
@nmattia
nmattia / foo.js
Last active February 24, 2020 20:59
rotating divs
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 / .envrc
Created July 31, 2021 15:54
Dune: Uncomplicated Nix Environments
res=$(nix-build --no-link ./default.nix -A load)
watch_file ./default.nix
. "$res"
@nmattia
nmattia / gcc.patch
Last active January 4, 2023 10:42
Patch GCC's avr build to not try to write to the source tree
diff --git a/gcc/config/avr/t-avr b/gcc/config/avr/t-avr
index deadbeef..deadbeef 100644
--- a/gcc/config/avr/t-avr 2023-01-03 21:56:23
+++ b/gcc/config/avr/t-avr 2023-01-03 21:56:32
@@ -91,9 +91,6 @@
$(srcdir)/config/avr/avr-arch.h $(TM_H)
$(CXX_FOR_BUILD) $(CXXFLAGS_FOR_BUILD) $< -o $@ $(INCLUDES)
-$(srcdir)/doc/avr-mmcu.texi: gen-avr-mmcu-texi$(build_exeext)
- $(RUN_GEN) ./$< > $@