Skip to content

Instantly share code, notes, and snippets.

View lucasdicioccio's full-sized avatar

dicioccio lucas lucasdicioccio

View GitHub Profile
@lucasdicioccio
lucasdicioccio / example-tf-role.hs
Last active March 30, 2023 20:49
example TypeFamilies-based roles to mitigate risk of dev backdoors in applications
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE KindSignatures #-}
-- | Simple type families for limiting things to some given roles.
module TF where
-- | Lookup for a value in a list.
type family Find x ys where
@lucasdicioccio
lucasdicioccio / Main.hs
Created September 21, 2022 17:28
validation-based test suites
-- using https://hackage.haskell.org/package/validation-1.1.2/docs/Data-Validation.html#t:Validate to bundle multiple "asserts" in a same "check"
module Main where
import Control.Lens
import Prelude
import Data.Validation
type Message = String
@lucasdicioccio
lucasdicioccio / scripts.md
Last active September 9, 2021 15:42
nautilus scripts for Ubuntu

convert a screencast

If you record screen with (ctrl+shift+alt+R) in Ubuntu, you'll get a webm file, GitHub wants mp4. So you need to convert from webm to mp4.

The ffmpeg command allows such a conversion. Ubuntu's file navigator allows to have some right-click scripts shortcuts.

To be dropped and chmod +x in something like ~/.local/share/nautilus/scripts/ffmpeg convert to mp4

@lucasdicioccio
lucasdicioccio / example-usage.md
Created June 5, 2021 08:27
a Haskell script to detect garbled files on a shitty SD

Compile then run

$ ghc --make -O2 suspicious.hs
$ find . -name "IMG_*" -exec './suspicious' '{}' \; > suspicious-list

Excerpt of the output in suspicious-list:

@lucasdicioccio
lucasdicioccio / bookmarklet.md
Created February 26, 2021 18:30
postgrest-table bookmarklet

Postgrest-Table bookmarklet

https://postgrest-table.netlify.app/ turns you PostgREST endpoint in some default view to discover and browse tables.

The bookmarklet to save is:

javascript:location.href='https://postgrest-table.netlify.app?postgrest='+document.location.href;
@lucasdicioccio
lucasdicioccio / mzn.vim
Last active September 11, 2023 11:54
a VIM syntax highlight for MiniZinc
" Vim syntax file
" Language: MiniZinc
" Maintainer: Lucas DiCioccio
" Latest Revision: 02 May 2020
if exists("b:current_syntax")
finish
endif
" keywords
user@vm051:~/wai$ git diff
diff --git a/warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs b/warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs
index 3000baa..7bd8604 100644
--- a/warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs
+++ b/warp/Network/Wai/Handler/Warp/HTTP2/Receiver.hs
@@ -165,26 +165,29 @@ frameReceiver ctx mkreq recvN = loop 0 `E.catch` sendGoaway
Nothing
| isResponse streamId -> return Nothing
| otherwise -> do
- when (ftyp `notElem` [FrameHeaders,FramePriority]) $
@lucasdicioccio
lucasdicioccio / freet.hs
Last active April 12, 2016 22:34
subtle free monads
{-# LANGUAGE DeriveFunctor #-}
module Main where
import Control.Monad.IO.Class
import Control.Monad.State
import Control.Monad.Trans.Free
data MyFunctor next = PrimitiveA next | PrimitiveB next deriving Functor
type MyFreeT m = FreeT MyFunctor m
type Program = MyFreeT (StateT Int IO)
@lucasdicioccio
lucasdicioccio / GildedTulip.hs
Last active March 19, 2019 02:39
What an immutable GildedRose would look like
-- An alternative GildedRose using an immutable approach.
-- Context on the GildedRose:
-- * http://blog.lunarlogic.io/2015/what-ive-learned-by-doing-the-gilded-rose-kata-4-refactoring-tips/
-- * my comment in the linked blog post
-- One could take this GildedTulip approach and encapsulate a similar "immutable API"
-- to re-create the "mutable API" of the GildedRose.
--
-- This example is written in Haskell. This example uses three notable features (available in other languages):
-- - pattern matching: a way to hide a lot of "if"