Skip to content

Instantly share code, notes, and snippets.

View harry830622's full-sized avatar

Harry Chang harry830622

View GitHub Profile
@harry830622
harry830622 / to_abs_path.sh
Last active January 13, 2020 08:39
Convert relative paths to absolute paths
#!/bin/env bash
rel_path=../relative/path
cd /path/to/here
abs_path=$(readlink -f $rel_path)
echo $abs_path # /path/to/relative/path
@harry830622
harry830622 / functor.cpp
Created January 21, 2020 08:49
Create a Functor in C++
class Functor {
public:
Functor() :sum_(0) {}
int operator()(int n) {
sum_ += n;
return sum_;
}
private:
int sum_;
}
package main
import (
"context"
"fmt"
"google.golang.org/grpc"
"github.com/onflow/cadence"
// "github.com/onflow/flow-go-sdk"
pub contract TopShot: NonFungibleToken
pub event ContractInitialized()
pub event PlayCreated(id: UInt32, metadata: {String:String})
pub event NewSeriesStarted(newCurrentSeries: UInt32)
pub event SetCreated(setID: UInt32, series: UInt32)
pub event PlayAddedToSet(setID: UInt32, playID: UInt32)
pub event PlayRetiredFromSet(setID: UInt32, playID: UInt32, numMoments: UInt32)
pub event SetLocked(setID: UInt32)
pub event MomentMinted(momentID: UInt64, playID: UInt32, setID: UInt32, serialNumber: UInt32)
// 目前正在進行的 series
pub var currentSeries: UInt32
// 紀錄 play 的資訊
// 是一個 play ID -> play 資訊的 mapping
access(self) var playDatas: {UInt32: Play}
// 紀錄 set 的資訊
// 是一個 set ID -> set 資訊的 mapping
access(self) var setDatas: {UInt32: SetData}
// Play 就是一個精彩好球,比如說 LBJ 的 The block,
// 所有的卡片只會包含一個 play,
// 但同一個 play 可以被很多卡片或是系列包含
pub struct Play {
// 每個 play 會有一個獨特的 ID 表示
pub let playID: UInt32
// 每個 play 也會有相應的 metadata,
// 這裡的儲存方式是使用一個 string -> string 的 map
// Set 就是一個系列,裡面可以包含很多個精彩好球 play
pub struct SetData {
// 每個 Set 有一個獨特的 ID 表示
pub let setID: UInt32
// Set 名字,例如 "Cool Cats" 系列
pub let name: String
// Set 所屬的世代,像現在已經到了世代 3,
// Moment 也就是一張卡片,
pub struct MomentData {
// 是在哪個 set 裡
pub let setID: UInt32
// 是哪個 play
pub let playID: UInt32
// 序號是多少
// TopShotMomentMetadataView 就如變數名字所意,
// 儲存所有 moment 相關的 metadata,
// 像是球員名字、球員生日、所屬球隊等等
pub struct TopShotMomentMetadataView {
pub let fullName: String?
pub let firstName: String?
pub let lastName: String?
pub let birthdate: String?
pub let birthplace: String?