Skip to content

Instantly share code, notes, and snippets.

View yihuang's full-sized avatar
🏠
Working from home

yihuang yihuang

🏠
Working from home
  • Shenzhen, China
  • 16:16 (UTC -12:00)
View GitHub Profile
@yihuang
yihuang / cyclic_type_reference.rs
Last active July 26, 2019 14:45
cyclic type reference in rust
use std::fmt;
trait Listener where Self: Sized + fmt::Debug {
fn on_event(&self, obj: &TestObject<Self>, args: &str);
}
#[derive(Debug)]
struct TestObject<F> where F:Listener {
listener: F
}

1、Run the docker version of PostgreSQL 12

$ docker run --rm -p 5432:5432 -v /tmp:/data -e POSTGRES_USER=exchange -e POSTGRES_DB=exchange -e POSTGRES_PASSWORD=123456 postgres:12-alpine

2、Download the attached files to /tmp 3、Import the schema and data

$ docker exec -it $CONTAINER psql -U exchange exchange -f /data/t_order_schema.sql
$ docker exec -it $CONTAINER psql -U exchange exchange -f /data/t_order_data.sql
@yihuang
yihuang / validator_stat_spec.md
Last active February 5, 2020 09:56
Using relational database concepts to clarify validator stat logic
-- current validator state, in memory.
create table validator (
  staking_address primary key,
  bonded_coins btree_indexed,
  voting_power = bonded_coins / 10000_0000,
  validator_address unique_indexed,
  council_node_info json,
  proposer_stat int,  -- or vote_stat
  punishment json null,
@yihuang
yihuang / api.md
Created March 25, 2020 03:51
api description

Mock enclave

helpers

// called by client to encrypt tx
fn encrypt(tx: PlainTxAux) -> TxObfuscated {
  TxObfuscated {
    key_from: 0,
    init_vector; [0; 12],
@yihuang
yihuang / websocket-jsonrpc-multiplex.rs
Last active May 27, 2020 17:01
Multiplex concurrent jsonrpc request on one websocket connection with smol
use std::cell::RefCell;
use std::collections::HashMap;
use std::net::TcpStream;
use std::rc::Rc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use anyhow::Result;
use easy_parallel::Parallel;
use futures::channel::{mpsc, oneshot};

tree math

struct LeafSize(u32);
struct ParentSize(u32);
struct NodeSize(u32);

impl LeafSize {
    // returns None when leafs in (0, 1)
    fn sibling(self, leafs: LeafSize) -> Option<LeafSize>;
@yihuang
yihuang / Cargo.toml
Created July 26, 2020 09:34
test open rpc
[package]
name = "open-rpc-test"
version = "0.1.0"
authors = ["yihuang <[email protected]>"]
edition = "2018"
[dependencies]
schemars = "0.7"
serde = "1.0"
serde_json = "1.0"
@yihuang
yihuang / deps.nix
Last active September 27, 2020 04:01
ultimate go module major version test case
# file generated from go.mod using vgo2nix (https://github.com/adisbladis/vgo2nix)
[
{
goPackagePath = "github.com/cespare/xxhash/v2";
fetch = {
type = "git";
url = "https://github.com/yihuang/test-golang-module-major-version";
rev = "4a13e4bfd5a9";
sha256 = "0i1bpw3v73jhwnpa8vv276qhy39fk6qhgyci0wng9mwr2pxfha5y";
moduleDir = "";
@yihuang
yihuang / Cargo.toml
Last active March 8, 2025 15:31
build rust project using bindgen with nix
[package]
name = "test-rust"
version = "0.1.0"
authors = ["yihuang <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]