Skip to content

Instantly share code, notes, and snippets.

View monadplus's full-sized avatar
🐧
Arch btw

Arnau Abella monadplus

🐧
Arch btw
View GitHub Profile
@monadplus
monadplus / webauthn.md
Last active June 3, 2022 16:58
Web Authentication : Distilled

Actors

  • A Relying Party: like github.com or google.com.
  • A User Agent: a browser or smartphone.
  • A Authenticator: security key manager.

Registration

@monadplus
monadplus / hash_map_macro.rs
Created May 4, 2022 07:21
Rust: hash_map!()
#[macro_export]
macro_rules! hash_map {
($($key:expr => $val:expr),* ,) => (
$crate::hash_map!($($key => $val),*)
);
($($key:expr => $val:expr),*) => {
{
let mut dict = ::std::collections::HashMap::new();
$( dict.insert($key, $val); )*
dict
@monadplus
monadplus / lazy.markdown
Last active April 12, 2022 08:24
Lazy pattern matching

If the pattern was strict, the tuples must have been evaluated to WHNF
forcing the whole list to be traversed before p x could be evaluated. This would not work on infinite lists nor bottom values.

partition :: (a -> Bool) -> [a] -> ([a],[a])
partition p xs = foldr (select p) ([],[]) xs
  where
    select :: (a -> Bool) -> a -> ([a], [a]) -> ([a], [a])
 select p x ~(ts,fs) | p x = (x:ts,fs)
@monadplus
monadplus / svec.rs
Created April 11, 2022 11:27
Rust: indexed vectors
use std::{cmp::Ordering, fmt::Debug, marker::PhantomData, ops::Add};
trait Nat {
fn new() -> Self;
fn usize() -> usize;
}
#[derive(Copy, Clone, PartialEq, Eq)]
struct Z;
@monadplus
monadplus / README.md
Last active March 19, 2025 21:46
Nix: runCommand, writeShellApplication
@monadplus
monadplus / trait_object_associated_type.rs
Last active March 24, 2022 10:52
Rust: trait object with existential associated type
// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c7d98a91435963f2cc8568b7dfd04366
use std::fmt::Debug;
trait MyTrait {
type R: Debug;
fn get_r(&self) -> Box<Self::R>;
}
#[derive(Debug)]
@monadplus
monadplus / JsonSchema.hs
Last active April 10, 2022 08:39
Json schema in 10 minutes
{-# LANGUAGE RecordWildCards #-}
module JsonSchema where
import Control.Monad (unless, when, zipWithM_)
import Data.Foldable (for_)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Maybe (isJust, isNothing)
type Key = String
@monadplus
monadplus / coercible.hs
Created October 10, 2021 20:40
Coercible a b => Coercible (f a) (f b) using QuantifiedConstraints
{-
coerceFirst :: (Coercible a b) => [f a] -> Maybe (f b)
coerceFirst [] = Nothing
coerceFirst (x:_) = Just (coerce x)
* Couldn't match representation of type `f a' with that of `f b'
arising from a use of `coerce'
NB: We cannot know what roles the parameters to `f' have;
we must assume that the role is nominal
@monadplus
monadplus / FizzBuzz.hs
Last active September 26, 2021 17:08
FizzBuzz
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneKindSignatures #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
@monadplus
monadplus / bitcoin-core.md
Last active October 1, 2021 15:44
Bitcoin Core: docker-compose

Create file docker-compose.yml (fix the parameters to your configuration):

version: "3.9"
services:
  bitcoin-core:
    container_name: bitcoin-server
    image: ruimarinho/bitcoin-core
    command:
      -printtoconsole