Skip to content

Instantly share code, notes, and snippets.

View ninegua's full-sized avatar

Paul Liu ninegua

View GitHub Profile
@ninegua
ninegua / gist:5fe22eea4f238866c0052692b9b28095
Last active April 8, 2024 10:14
Tokens and Multi-chain programming - ICP HK Hacker House
# practice 1
# check cycle wallet balance
dfx wallet balance --ic
# if wallet has not been setup, ask for a coupon and redeem to create a cycle wallet on mainnet
# dfx wallet redeem-faucet-coupon $COUPON_CODE
# dfx.json
--------------------------------
@ninegua
ninegua / Makefile
Last active May 6, 2022 16:30
Get started to call NNS from command line (using dfx)
FILES=governance.did cmc.did canister_ids.json dfx.json
setup: $(FILES)
@echo You are all set! Run 'dfx canister --network=ic call nns get_monthly_node_provider_rewards' to test if it works.
@echo Please read the governance.did file to find the complete interface.
governance.did:
@curl -L https://github.com/dfinity/ic/raw/master/rs/nns/governance/canister/governance.did -o $@
cmc.did:
@ninegua
ninegua / certified_assets.mo
Created February 24, 2022 00:21
Certified Assets Type Definitions in Motoko
module {
public type BatchId = Nat;
public type BatchOperationKind = {
#CreateAsset : CreateAssetArguments;
#UnsetAssetContent : UnsetAssetContentArguments;
#DeleteAsset : DeleteAssetArguments;
#SetAssetContent : SetAssetContentArguments;
#Clear : ClearArguments;
};
public type ChunkId = Nat;
@ninegua
ninegua / ledger.did
Last active May 18, 2021 22:27
Internet computer ledger utility supporting 2 step transfer (separate sign and send)
type ICPTs = record {
e8s : nat64;
};
type Duration = record {
secs: nat64;
nanos: nat32;
};
type TimeStamp = record {
@ninegua
ninegua / Schnorr.hs
Last active November 26, 2019 02:24
A Haskell Schnorr Signature Tutorial
-------------------------------------------------------------------------------------
-- Schnorr Signatures - A Haskell Tutorial
--
-- While studying Schnorr Signatures, I find most online materials either
-- imprecise, or inadequate. Often mathematical notations are being quoted
-- without fully explaining conditions, expecations, and variables/functions
-- domain and/or range. They are confusing enough that any attempt to turn them
-- into real programs is doomed, either producing something that is wrong, or
-- even worse, something that you think is correct but is actually wrong.
--
@ninegua
ninegua / blackscholes.jl
Created January 20, 2016 02:26
Blackscholes ported from Python to Julia for use with ParallelAccelerator
using ParallelAccelerator
const RISKFREE = 0.02
const VOLATILITY = 0.30
#ParallelAccelerator.ParallelIR.PIRSetFuseLimit(0)
#ParallelAccelerator.CGen.setvectorizationlevel(ParallelAccelerator.CGen.VECDISABLE)
@acc begin
@ninegua
ninegua / mflow-backt
Created May 2, 2015 07:17
BackT (in MFlow) is not a monad
import Control.Monad
import Control.Monad.Trans
-- The following is taken from the paper "MFlow, a contiuation-based web
-- framework without continuations" by Alberto Gomez Corona, April 23, 2014,
-- with minor modifications to make it runnable in GHCi.
data FailBack a = BackPoint a | NoBack a | GoBack
newtype BackT m a = BackT { runBackT :: m (FailBack a ) }
instance Monad m => Monad (BackT m) where
@ninegua
ninegua / scrapper.hs
Created April 22, 2015 04:37
Weibo Scrapper (using conduit == 0.2.*) written in 2012
{-# LANGUAGE OverloadedStrings, RankNTypes, ScopedTypeVariables,
NoMonomorphismRestriction, DeriveDataTypeable #-}
module Main where
import Prelude hiding (and, catch)
import Data.Char (toLower)
import Data.Conduit
import Data.Conduit.Util
import Data.Conduit.ImageSize (sinkImageInfo)
import Data.Conduit.Binary (sourceFile, conduitFile, sinkFile)