Skip to content

Instantly share code, notes, and snippets.

View kseo's full-sized avatar

Kwang Yul Seo kseo

  • CodeChain
  • Seoul
View GitHub Profile
@kseo
kseo / transaction_group.rs
Created May 4, 2018 00:26
TransactionGroup
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 03:09
AssetOutPoint
pub struct AssetOutPoint {
pub transaction_hash: H256,
pub index: usize,
pub asset_type: H256,
pub amount: u64,
}
@kseo
kseo / DockerAPI.hs
Created January 23, 2017 15:10
Docker API: SSL authentication
{-# 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 December 7, 2016 14:57
DOM parser
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE TypeFamilies #-}
module Beard.DOM
( Element(..)
, Node(..)
, parseDOM
) where
import Control.Monad (when)
@kseo
kseo / ForLoop.hs
Created March 23, 2016 12:02
for loop in Haskell
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 March 8, 2016 15:00
The Constraint kind
-- 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 March 7, 2016 02:13
fold and Monoid
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 March 7, 2016 02:12
Monad Transformers Step by Step
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 March 5, 2016 10:53
Monad transformer
{-# 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 February 13, 2016 13:31
Type-directed memoization
-- 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