Skip to content

Instantly share code, notes, and snippets.

Avatar

Kwang Yul Seo kseo

  • CodeChain
  • Seoul
View GitHub Profile
View transaction_group.rs
pub struct TransactionGroup {
/// Nonce.
pub nonce: U256,
/// Amount of CCC to be paid as a cost for distributing these transactions to the network.
pub fee: U256,
/// Transactions
pub transactions: Vec<Transaction>,
/// Mainnet or Testnet
pub network_id: u64,
}
@kseo
kseo / transaction.rs
Last active May 1, 2018
AssetOutPoint
View transaction.rs
pub struct AssetOutPoint {
pub transaction_hash: H256,
pub index: usize,
pub asset_type: H256,
pub amount: u64,
}
@kseo
kseo / DockerAPI.hs
Created Jan 23, 2017
Docker API: SSL authentication
View DockerAPI.hs
{-# LANGUAGE NamedFieldPuns #-}
import Control.Monad (when)
import qualified Data.ByteString.Char8 as BSC
import Data.Default.Class (def)
import Data.Monoid ((<>))
import System.IO.Error (ioError, userError)
import Data.X509 (CertificateChain (..), HashALG(..))
import Data.X509.CertificateStore (makeCertificateStore)
@kseo
kseo / DOM.hs
Created Dec 7, 2016
DOM parser
View DOM.hs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
module Beard.DOM
( Element(..)
, Node(..)
, parseDOM
) where
import Control.Monad (when)
@kseo
kseo / ForLoop.hs
Created Mar 23, 2016
for loop in Haskell
View ForLoop.hs
import Control.Monad
import Control.Monad.ST
import Data.STRef
sumST :: Num a => [a] -> a
sumST xs = runST $ do
n <- newSTRef 0
forM_ xs $ \x -> modifySTRef n (+x)
readSTRef n
@kseo
kseo / MonadSet.hs
Last active Mar 8, 2016
The Constraint kind
View MonadSet.hs
-- https://jeltsch.wordpress.com/2013/02/14/the-constraint-kind/
{-# LANGUAGE ConstraintKinds, TypeFamilies #-}
import Prelude hiding (Monad (..))
import Data.Set
import GHC.Exts (Constraint)
setReturn :: el -> Set el
setReturn = singleton
@kseo
kseo / Fold.hs
Created Mar 7, 2016
fold and Monoid
View Fold.hs
import Prelude hiding (foldr)
import Data.Monoid
foldComposing :: (a -> (b -> b)) -> [a] -> Endo b
foldComposing f = foldMap (Endo . f)
foldr :: (a -> (b -> b)) -> b -> [a] -> b
foldr f z xs = appEndo (foldComposing f xs) z
@kseo
kseo / Eval.hs
Created Mar 7, 2016
Monad Transformers Step by Step
View Eval.hs
odule Eval where
import Control.Monad.Identity
import Control.Monad.Error
import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Writer
import Data.Maybe
import qualified Data.Map as Map
@kseo
kseo / MaybeT.hs
Created Mar 5, 2016
Monad transformer
View MaybeT.hs
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UndecidableInstances #-}
import Control.Monad
import Control.Monad.State
import Control.Monad.Trans
newtype MaybeT m a = MaybeT {
runMaybeT :: m (Maybe a)
@kseo
kseo / Memo.hs
Created Feb 13, 2016
Type-directed memoization
View Memo.hs
-- http://research.microsoft.com/en-us/um/people/simonpj/papers/assoc-types/fun-with-type-funs/typefun.pdf
{-# LANGUAGE TypeFamilies #-}
class Memo a where
data Table a :: * -> *
toTable :: (a -> w) -> Table a w
fromTable :: Table a w -> (a -> w)
instance Memo Bool where
data Table Bool w = TBool w w