Skip to content

Instantly share code, notes, and snippets.

View fumieval's full-sized avatar
🐦
Birb

Fumiaki Kinoshita fumieval

🐦
Birb
View GitHub Profile
@fumieval
fumieval / rfc7638.hs
Created April 3, 2024 10:05
Calculating JWK thumbprint of a X.509 certificate
import Crypto.Hash
import Crypto.JWT
import Crypto.JOSE.Types
import Data.Aeson as J
import Data.ByteArray.Encoding qualified as BA
import Data.ByteString.Lazy qualified as BL
import RIO
import Data.X509.File qualified as X509
import Data.Text.IO (putStrLn)
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Data.Aeson.Extras where
import Data.Aeson
{-# LANGUAGE RankNTypes, TemplateHaskell, GeneralizedNewtypeDeriving, DeriveGeneric #-}
module Main where
import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.IO.Class
import Control.Lens
import Data.Barbie
import GHC.Generics
@fumieval
fumieval / fieldnames.hs
Created August 30, 2019 04:04
Can't derive Generic1 though
class FieldNamesB b where
bFieldNames :: IsString a => b (Const a)
default bFieldNames :: (Generic1 b, FieldNamesB (Rep b), IsString a) => b (Const a)
bFieldNames = to bFieldNames
instance FieldNamesB U1 where
bFieldNames = U1
6 Island (RIX) 193
3 Aviation Pioneer (M19) 46
2 Aven Wind Mage (M19) 45
1 Divination (DAR) 52
3 Waterknot (RIX) 61
1 Riddlemaster Sphinx (M19) 287
1 Murmuring Mystic (GRN) 45
1 Roc Charger (GRN) 24
7 Plains (RIX) 192
4 Azorius Guildgate (RNA) 243
module Parser where
import Control.Applicative
import Data.Text
-- the shape of the problem
--
-- we want a list of Parsers, all of different types.
-- we will apply each of them, one after another,
-- in the context of asking questions in some monadic
-- context.
@fumieval
fumieval / extensible.hs
Last active March 17, 2018 20:48 — forked from cdepillabout/extensible.hs
small example of hlist from extensible library
{-# LANGUAGE TypeOperators #-}
import Control.Applicative
import Data.Extensible
import Control.Monad.Trans.Maybe
import Data.Text
-- the shape of the problem
--
-- we want a list of Parsers, all of different types.
-- we will apply each of them, one after another,
insert_rp0_entry() // [R4, R3, R2]
{ [(c2ds,
block_c2ds_info:
const 2;
const 32;),
(c2dz,
insert_rp0_info:
const 12884901911;
const 0;
const 15;),

extensible is a library for extensible data types. It provides extensible product and sum types parameterized by type-level lists.

This tutorial introduces extensible records, an application of the extensible products.

First, we pass a space-separated list of field names to mkField:

{-# LANGUAGE TemplateHaskell, DataKinds, TypeOperators, FlexibleContexts #-}
{-# OPTIONS_GHC -fno-warn-unticked-promoted-constructors #-}
newtype Zombie t a = Zombie { unZombie :: [Spine t (Zombie t) a] }
instance Functor (Zombie t) where
fmap = liftM
instance Applicative (Zombie t) where
pure = return
(<*>) = ap