Skip to content

Instantly share code, notes, and snippets.

View divarvel's full-sized avatar

Clément Delafargue divarvel

View GitHub Profile
@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 / 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
@divarvel
divarvel / gist:998e5d9d4d384e9dbdb5b0b9bae62c25
Last active October 30, 2016 18:41
Rust on Clever Cloud
https://www.clever-cloud.com/doc/rust/rust/
@divarvel
divarvel / ParserDerivation.scala
Last active April 28, 2017 12:48
Anorm parser derivation
def generateParser[Entity, LHL <: HList, HL <: HList](
implicit labelledGen: LabelledGeneric.Aux[Entity, LHL],
gen: Generic.Aux[Entity, HL],
keys: Keys[LHL],
toParser: FieldToParser[LHL]) = {
val functionList = FieldToParser[labelledGen.Repr].apply()
val parsers = functionList zipApply keys().unifySubtypes[Symbol]
@divarvel
divarvel / gif2webm.sh
Created December 16, 2015 10:28
cltdl.fr/gifs
#!/bin/sh
set -e
shopt -s nullglob
for gif in /mnt/data/gifs/*.gif; do
basename=$(basename "${gif%.gif}")
if [[ ! -e "$basename.webm" ]]; then
ffmpeg -i "$gif" -b:v 1000k -v 0 "$basename.webm";
extern crate amqp;
use amqp::session::Options;
use amqp::session::Session;
use amqp::protocol;
use amqp::table;
use amqp::basic::Basic;
use amqp::channel::Channel;
use std::default::Default;