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)
@fumieval
fumieval / lazy.scm
Created March 28, 2012 05:05
Lazy K (unlambda style) interpreter for lazier
(load "lazier.scm")
(load "prelude.scm")
(load "prelude-numbers.scm")
(lazy-def '(main input) '(parse-unlambda i input))
(lazy-def 'parse-unlambda
'((lambda (x) (x x))
(lambda (self cont input)
((nth (car input) dispatch-list) (self self) cont (cdr input)) )))
@fumieval
fumieval / ideal.hs
Created January 3, 2013 18:04
an example of an example of ideal monads
import Data.Char
data Ideal f a = Pure a | Ideal (f a)
class Idealize f where
(>>~) :: f a -> (a -> Ideal f b) -> f b
instance Idealize f => Monad (Ideal f) where
return = Pure
{-# 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
@fumieval
fumieval / FBX.hs
Created April 28, 2015 07:50
FBX 7.4 parser
{-# LANGUAGE LambdaCase, TypeFamilies, DataKinds, TypeOperators, FlexibleContexts, OverloadedStrings, StandaloneDeriving #-}
module Codec.Container.FBX where
import qualified Data.Vector.Unboxed as UV
import Data.Binary
import Data.Binary.Get
import Data.Binary.Put
import Data.Int
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
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
{-# LANGUAGE TemplateHaskell, DataKinds, LambdaCase, KindSignatures, MultiParamTypeClasses, FunctionalDependencies, TypeFamilies, Rank2Types #-}
module Idiom.Lens where
import Language.Haskell.TH
import Language.Haskell.TH.Lens
import Data.Proxy
import Control.Lens
import GHC.TypeLits
class Has (s :: Symbol) a where
@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,