Skip to content

Instantly share code, notes, and snippets.

View harry830622's full-sized avatar

Harry Chang harry830622

View GitHub Profile
// Play 就是一個精彩好球,比如說 LBJ 的 The block,
// 所有的卡片只會包含一個 play,
// 但同一個 play 可以被很多卡片或是系列包含
pub struct Play {
// 每個 play 會有一個獨特的 ID 表示
pub let playID: UInt32
// 每個 play 也會有相應的 metadata,
// 這裡的儲存方式是使用一個 string -> string 的 map
// 目前正在進行的 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}
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)
pub contract TopShot: NonFungibleToken
package main
import (
"context"
"fmt"
"google.golang.org/grpc"
"github.com/onflow/cadence"
// "github.com/onflow/flow-go-sdk"
@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_;
}
@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 / iterate_files_in_dir.sh
Last active January 13, 2020 08:39
Iterate over files in a directory
#!/bin/env bash
# For example, iterate over files in the home directory.
dir=~
for f in $dir/*; do
echo $f
done
@harry830622
harry830622 / shuffle.js
Last active March 19, 2022 07:17
js utils
// Fisher-Yates shuffle algorithm
function shuffle(arr) {
const result = [...arr];
for (let i = result.length - 1; i >= 0; i -= 1) {
const j = Math.floor(Math.random() * (i + 1));
[result[i], result[j]] = [result[j], result[i]];
}
return result;
}
#!/usr/bin/env python
# l: final length
# e: epsilon
# d: lambda
# u: mu
# dd: derivative of lambda
from mpmath import *