Skip to content

Instantly share code, notes, and snippets.

View divarvel's full-sized avatar

Clément Delafargue divarvel

View GitHub Profile
/*
Data format: the triangles are represented by a matrix. Each odd line is shifted down by 1/2.
0 represents nothing, 7 represents a full triangle.
[[7,7,7], [7,0,0]] translates to:
|\ |\
| \ | \
@divarvel
divarvel / gist:36aa1d1fd10c21919f3524f1842cccd3
Last active June 3, 2019 12:59
Config as Code? Yes, but cleanly. Try some Dhall

There's always a point where we are tempted to replace config files (json, toml, yaml), with just code. It's handy, we get structure and abstraction, we can have little helper functions, proper comments (I'm looking at you, JSON). It's especially useful when the config is verbose, or very common. The flip side of going the config as code way, is that we lose a lot: updating config is updating the application itself (not very 12 factor compliant, and not user-friendly as well when using compiled languages). Worse, some arbitrary side effects can sneak into your configuration step. Another issue is that it becomes really hard to read or analyze config files without launching the application itself (bye linters, bye dependency checkers, bye organization-wide metrics). If you want to do that properly, it means building a way to output generated configuration, building a sandbox to run the application, and a few other unsavory contraptions.

All this issues stem from two things:

we have removed the boundary

@divarvel
divarvel / Lib.hs
Created December 31, 2018 09:36
A tale of servant clients
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}

Keybase proof

I hereby claim:

  • I am divarvel on github.
  • I am clementd (https://keybase.io/clementd) on keybase.
  • I have a public key whose fingerprint is 78D3 430C 4600 7020 9F7A B0A2 6BFE 863C 2684 AD09

To claim this, I am signing this object:

self: super:
{
kakoune = super.kakoune.overrideAttrs (
drv: rec {
name = "kakoune-perso";
version = "divarvel";
src = super.fetchFromGitHub {
repo = "kakoune";
owner = "divarvel";
rev = "show-trailing-whitespace";
define-command -docstring ":edit with a fuzzy search" fuzzy-edit %{
evaluate-commands %sh{
FILE=$(rg --files | rofi -dmenu -i -p 'file');
[[ -n "$FILE" ]] && printf "edit %s\\n" $FILE
}
}
define-command -docstring ":buffer with a fuzzy search " fuzzy-buffer %{
evaluate-commands %sh{
BUFFER=$(printf "%s\\n" "${kak_buflist}" | rofi -dmenu -i -sep ' ' -p 'buffer');
@divarvel
divarvel / continuation.js
Last active May 11, 2018 08:57
Continuation monad in JS. just run $ node continuation.js
console.log("\033[39mRunning tests…");
function assertEquals(actual, expected, description) {
if(typeof(actual) === "undefined") {
console.error("\033[31m" + description + " not implemented\033[39m");
} else {
if(actual !== expected) {
console.error("\033[31m" + description + " failed, expected " + expected + ", got " + actual + "\033[39m");
} else {
console.log(description + " \033[32m ok\033[39m");
}
data Dependency : String -> Type -> Type
where MkDep : (name: String) -> a -> Dependency name a
DepWrapper : Type -> Type
DepWrapper t = (String ** Dependency _ t)
dep1 : Dependency "toto" Int
@divarvel
divarvel / cabal-rtsopts.cabal
Created July 21, 2017 08:34
Multiple RTSOPTS
¬ cabal-rtsopts cat cabal-rtsopts.cabal
name: cabal-rtsopts
version: 0.1.0.0
-- synopsis:
-- description:
homepage: https://github.com/divarvel/cabal-rtsopts#readme
license: BSD3
license-file: LICENSE
author: Clément Delafargue
maintainer: clement@delafargue.name
CREATE TABLE availability (
dates tstzrange NOT NULL
);
CREATE TABLE reservation (
dates tstzrange NOT NULL
);
COPY availability (dates) FROM stdin;
["2014-01-01 00:00:00+01","2014-01-10 00:00:00+01"]