Skip to content

Instantly share code, notes, and snippets.

View guibou's full-sized avatar
🛩️
Diving in a sky full of escaped skolems

Guibou guibou

🛩️
Diving in a sky full of escaped skolems
  • Saint-Paul - Reunion - France
  • 06:52 (UTC +04:00)
View GitHub Profile
@guibou
guibou / HaskellCheck.hs
Last active June 9, 2021 18:02
Check that module name inside an haskell file (e.g. "module Foo.Bar where") match the filename (e.g. `prefix/Foo/Bar.hs`)
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}
import System.Process
import qualified Data.Text as Text
import qualified Data.Text.IO as Text
import Data.Foldable (for_)
import Data.Char (isLower)
import Control.Monad (when)
import Control.Applicative ((<|>))
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
import Data.Word
data family Address arch
type family InterpreterState arch
type family State arch :: (* -> *) -> *
data instance Address Int = AddressInt Int
data instance Address Char = AddressChar Word8 Word8 Word8 Word8
Inductive Nat :=
Z : Nat
| S : Nat -> Nat.
(* This version of Add is not tail recursive *)
Fixpoint Add a b :=
match a with
| Z => b
| S n => S (Add n b)
end.
@guibou
guibou / ExprAlp.hs
Created May 8, 2021 14:57
Define a small expression language, which overload Num and Fractional (And perhaps other types) and works correctly with defaulting.
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
f :: Num a => a -> a -> a
f x y = x * y
@guibou
guibou / run_obs_config.py
Created April 8, 2021 11:48
This runs my xephyr windows for OBS and ensure that window manager and interesting tools are started
import subprocess
import time
import sys
import os
# Start xephyr
xephyr = subprocess.Popen(
"Xephyr -br -ac -noreset -screen 1920x1080 -dpi 300 :1".split()
)
@guibou
guibou / NatNat.hs
Last active April 5, 2021 18:56
`matchNR` implements a `ViewPatterns` in order to match for an arbitrary deep `(R1 (R1 (R1 (L1 x)))` from `GHC.Generics`
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
@guibou
guibou / Algebra.hs
Created March 31, 2021 13:24
This is a type safe API for https://github.com/guibou/streamray which hides the `V3` from `Linear` under a `newtype` qualified with a type phantom describing if it is a position, direction (normalized or not) or color. The typeclass `Add`, `Mul`, `Sub` describes the allowed operations.
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE TypeFamilies #-}
module Algebra
( pattern P,
@guibou
guibou / license.nix
Created March 30, 2021 20:16
Find licenses in a bunch of nix sets.
licensesIn = acc: p: {
res = if builtins.isAttrs p && builtins.hasAttr "meta" p then
pkgs.lib.unique (acc.res ++ [{
package = p.pname or p.name or "N/A";
version = p.version or "N/A";
url = p.meta.homepage or "N/A";
licenses = (if builtins.isList (p.meta.license or "oops") then
map (l: l.spdxId) p.meta.license
else
[ p.meta.license.spdxId or "N/A" ]);
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
import GHC.Float
class RealToFrac a where
convert :: a -> Double
{-# OPTIONS -Wall #-}
queueTime :: [Int] -> Int -> Int
queueTime l n = go (take n l) (drop n l) 0
where
go [] [] res = res
go workers remains res = let
faster = minimum workers
workers' = filter(/= 0) $ map (subtract faster) workers
l' = workers' ++ remains