Skip to content

Instantly share code, notes, and snippets.

View ncfavier's full-sized avatar
🪻

Naïm Camille Favier ncfavier

🪻
View GitHub Profile
@ncfavier
ncfavier / Susp-Join.agda
Last active July 26, 2022 00:36
Equivalence between two presentations of the suspension
open import 1Lab.Path
open import 1Lab.Path.Groupoid
open import 1Lab.Type
open import 1Lab.Equiv
data Susp {ℓ} (A : Type ℓ) : Type ℓ where
N S : Susp A
merid : A → N ≡ S
data Join {ℓ₁ ℓ₂} (A : Type ℓ₁) (B : Type ℓ₂) : Type (ℓ₁ ⊔ ℓ₂) where
open import Relation.Binary.PropositionalEquality
open ≡-Reasoning
open import Function.Base
open import Data.Empty
open import Data.Nat
open import Data.Nat.Properties
open import Data.Sum
data Bin : Set where
⟨⟩ : Bin
module Lib (shortestLongest) where
import Control.Applicative
import Data.Maybe
steps = go []
where
go l (x:xs) = Nothing : go (x:l) xs
go l [] = Just [reverse l] : repeat (Just [])
Require Import Arith ZArith Lia List Ascii String Program.Basics.
Open Scope string_scope.
Open Scope program_scope.
Import ListNotations.
(** The head character of a string, returned as a new string.
If the string is empty, returns the empty string. *)
Definition head s := match s with
| "" => ""
@ncfavier
ncfavier / SevenTreesInOne.hs
Last active December 25, 2021 16:11
A very explicit bijection from Andreas Blass' "Seven Trees in One" https://arxiv.org/pdf/math/9405205.pdf
{-# LANGUAGE LambdaCase #-}
module SevenTreesInOne where
import Test.QuickCheck
infixl :*
data T = O | T :* T
deriving (Eq, Ord, Show)
type T7 = (T, T, T, T, T, T, T)
@ncfavier
ncfavier / day1.nix
Last active December 2, 2020 18:14
Advent of Code 2020 in Nix
#!/usr/bin/env -S nix-instantiate --eval --strict
# real 0m4.143s
with (builtins.getFlake "nixos").lib;
let
tails = l: if l == [] then [] else [ l ] ++ tails (tail l);
sum = foldl' (x: y: x + y) 0;
product = foldl' (x: y: x * y) 1;
lines = s: splitString "\n" (removeSuffix "\n" s);
nums = map toInt (lines (builtins.readFile ./input1));
@ncfavier
ncfavier / bridge.sh
Last active August 18, 2020 22:59
Syncplay<->IRC bridge
#!/usr/bin/env bash
# dependencies: bash 4+, jq
. ./config.sh
: "${verbose:=0}"
: "${syncplay_host:=syncplay.pl}"
: "${syncplay_port:=8999}"
: "${syncplay_nick:=syncplaybridge}"
: "${syncplay_room:?"can't be empty"}"
: "${irc_host:=chat.freenode.net}"
@ncfavier
ncfavier / ExistentialMaps.hs
Created July 25, 2020 18:25
Stupid utilisation of impredicative polymorphism to merge the key lists of two maps with different value types using `on`. Do not try at home.
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE ImpredicativeTypes #-} -- HIGHLY EXPERIMENTAL
import Data.Map (Map)
import qualified Data.Map as Map
import Data.Function
-- Say we want to define this function:
mergeKeys :: Map k a -> Map k b -> [k]
{- The obvious implementation is of course
@ncfavier
ncfavier / traversoids.md
Last active November 16, 2021 13:03
Summary of Haskell's traversal functions
traverse   :: (Traversable t, Applicative f) => (a -> f b) -> t a        -> f (t b)
traverse_  :: (Foldable    t, Applicative f) => (a -> f b) -> t a        -> f ()
for        :: (Traversable t, Applicative f) => t a        -> (a -> f b) -> f (t b)
for_       :: (Foldable    t, Applicative f) => t a        -> (a -> f b) -> f ()
sequenceA  :: (Traversable t, Applicative f) => t (f a)                  -> f (t a)
sequenceA_ :: (Foldable    t, Applicative f) => t (f a)                  -> f ()
mapM       :: (Traversable t, Monad       m) => (a -> m b) -> t a        -> m (t b)
mapM_      :: (Foldable    t, Monad       m) => (a -> m b) -> t a        -> m ()
forM       :: (Traversable t, Monad       m) => t a        -> (a -> m b) -> m (t b)
@ncfavier
ncfavier / znc2weechat.bash
Last active October 31, 2019 15:30
Convert ZNC logs to WeeChat logs (in French)
#!/usr/bin/env bash
channel=$1
while read -rd ' ' time && read -rd ' ' event && IFS= read -r message; do
time=${time#[} time=${time%]}
case $event in
'***')
if [[ $message =~ ^(.*)' is now known as '(.*)$ ]]; then
event='*'