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
  • 11:31 (UTC +04:00)
View GitHub Profile
@guibou
guibou / sub-cut.lua
Created February 22, 2021 17:18
Mpv plugin to cut file using shortcut (uses ffmpeg)
local utils = require "mp.utils"
function srt_time_to_seconds(time)
local major, minor = time:match("(%d%d:%d%d:%d%d),(%d%d%d)")
local hours, mins, secs = major:match("(%d%d):(%d%d):(%d%d)")
return hours * 3600 + mins * 60 + secs + minor / 1000
end
function seconds_to_srt_time(time)
local hours = math.floor(time / 3600)
@guibou
guibou / ParseErrorTest.hs
Last active February 18, 2021 09:43
Work in progress on GHC context for the parser
{-# LANGUAGE TypeApplications #-}
-- Based on https://gitlab.haskell.org/ghc/ghc/-/issues/19097#note_321796
{-
action NewEventAction = do
now <- getCurrentTime
let event = newRecord @Event
|> set #createdAt now -- THIS LINE NEEDS MORE INDENTATION
render NewView { .. }
-}
@guibou
guibou / default.nix
Created November 4, 2020 22:36
Nix shell for my compilation course
let
# Fetch a reproducible clone of nixpkgs.
# That one is a pull request to nixpkgs which includes antlr 4.8.
pkgs = import (fetchTarball {
url = "https://github.com/guibou/nixpkgs/archive/d4cfc8694c7536a79c9d0260b171ee7983394896.tar.gz";
}) {};
in
rec {
# Create an alias for "spike $(which pk)" to run-spike.
@guibou
guibou / bench.py
Last active June 8, 2020 13:31
A small performance benchmark for string concatenation in python.
import time
import contextlib
N = 10000
@contextlib.contextmanager
def timeit(label):
t = time.time()
yield
t2 = time.time()
@guibou
guibou / STUArray generic
Created May 10, 2020 18:28
STUArray generic, help on IRC.
{-# LANGUAGE QuantifiedConstraints #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE PartialTypeSignatures #-}
import Data.Array.MArray
import Data.Array.Unboxed
import Data.Array.ST
import Data.Function (fix)
@guibou
guibou / Range.hs
Last active October 28, 2020 17:46
Natural instance of `Applicative` for a range of value.
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DerivingVia #-}
module Range where
import qualified Data.List.NonEmpty as NonEmpty
import Data.List.NonEmpty (NonEmpty)
import Data.Functor.Compose
import Data.Monoid
@guibou
guibou / SafeInt.hs
Last active March 10, 2020 22:48
Experimenting a `SafeInt` wrapper for Int which triggers exception when overflow / underflow.
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
import Criterion.Main
newtype SafeInt t = SafeInt t
deriving (Show, Ord, Eq)
instance (Bounded t, Num t, Integral t) => Num (SafeInt t) where
(+) (SafeInt a) (SafeInt b)
@guibou
guibou / PyFTrim.hs
Created March 2, 2020 17:09
How PyF can handle trimming whitespaces in front of multiline
-- Solution 0, do nothing
let foo = [fmt|\
this
is
a
|]
-- Will return " this\n is\n a\n "
-- Solution 1, trim common alignement
.circleci/config.yml:416:25: info:
still Open: https://github.com/haskell/unix/issues/102
.gitlab-ci.yml:649:7: info:
still Open: https://gitlab.com/gitlab-org/gitlab-runner/issues/3856
compiler/backpack/RnModIface.hs:155:13: error:
now Closed: https://github.com/haskell/cabal/issues/3633
compiler/main/DriverPipeline.hs:355:10: info:
@guibou
guibou / Palindrom.hs
Created February 3, 2020 09:03
Check the number of calendar palindrom in a range.
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TemplateHaskell #-}
import PyF
import Data.Time.Calendar
import Control.Monad (guard, mzero)
-- | Format a date without dots.
fmtDate :: Day -> String