Skip to content

Instantly share code, notes, and snippets.

@oneleo
oneleo / Bank.sol
Created November 13, 2018 16:11
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.25+commit.59dbf8f1.js&optimize=true&gist=
pragma solidity ^0.4.25;
contract Bank {
// 此合約的擁有者。
address private _owner;
// 儲存所有會員的 ether 餘額。
mapping (address => uint256) private _balance;
// 儲存所有會員的 bank coin 餘額。
@oneleo
oneleo / ChunghwaTelecomToken.sol
Last active December 9, 2018 08:47
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.1+commit.c8a2cb62.js&optimize=true&gist=
pragma solidity >0.3.99 <0.6.0;
/**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
@oneleo
oneleo / Address.sol
Created December 16, 2018 15:58
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.1+commit.c8a2cb62.js&optimize=true&gist=
pragma solidity >=0.4.24;
/**
* Utility library of inline functions on addresses
*/
library Address {
/**
* Returns whether the target address is a contract
* @dev This function will return false if invoked during the constructor of a contract,
* as the code is not actually created until after the constructor finishes.
@oneleo
oneleo / Address.sol
Created December 19, 2018 03:29
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.1+commit.c8a2cb62.js&optimize=true&gist=
pragma solidity >=0.4.24;
/**
* Utility library of inline functions on addresses
*/
library Address {
/**
* Returns whether the target address is a contract
* 回傳目標地址是否為合約
* @dev This function will return false if invoked during the constructor of a contract,

詳解 HD Wallet、BIP-0032、BIP-0039、BIP-0043 及 BIP-0044

加密貨幣錢包(Cryptocurrency Wallet)

  1. 在加密貨幣的世界中,錢包並非儲存加密貨幣的地方。

  2. 反倒是錢包的主要功能是一個儲存私鑰(Private Key)的工具,私鑰是一串很長的英文字母、數字組成的字串(通常是 64 個 16 進制位元 = 256 Bits = 32 Bytes 所組成),而這條很長的字串讓您有權力把自己的加密貨幣傳送給別人。

  3. 錢包可在使用者產生交易(Transaction)時使用私鑰將交易簽章(Digital Signature),而簽章的目的除了確認使用者為貨幣擁有者外,還可確保在交易完成後不可否認(Non-Repudiation)此交易;而儲存加密貨幣的地方則是負責維護區塊鏈(Blockchain)的礦工節點內。

  4. 加密貨幣錢包形式多樣,分為離線的冷錢包(Cold Wallet)、在線的熱錢包(Hot Wallet)、印在紙上的紙錢包(Paper Wallet)… 等。無論何種形式的錢包,錢包的開發商均需要有一個共同遵循的規範(例如:私鑰為多少位元、如何依據一個亂數產生私鑰等)。

橢圓曲線加密演算法 ECDSA 與 RFC6979 改進提案

橢圓曲線加密演算法(Elliptic Curve Digital Signature Algorithm,ECDSA)是比特幣、以太坊區塊鏈所使用的非對稱式金鑰加密技術,

可輕易讓貨幣持有者透過私鑰 Private Key(變數:d_A)對資訊進行簽章(Digital Signature),讓所有人使用 Public Key(變數:d, e, p, n, G, Q_A)來進行驗證(或是反向進行秘密傳遞)。

然而,早期的 ECDSA 演算法中,有一個僅產生一次性使用的臨時簽名變數 k(Ephemeral Key)

因不夠隨機,又或是忽略了其重要性(如每次收發訊息都使用相同的 k 值),導致駭客可透過反推方式求得 k 值,

@oneleo
oneleo / InstallTensorflowKerasInUbuntu18.04
Last active March 5, 2019 10:10
Install Tensorflow/Keras in Ubuntu 18.04
# 在 Ubuntu 18 安裝 Tensorflow/Keras 開發環境
## 安裝 nVidia 顯示卡驅動程式
```
$ sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
$ sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt-get update
$ sudo apt-get -y install nvidia-driver-415 htop git
@oneleo
oneleo / InstallTensorflowKerasInUbuntu18.04.md
Last active March 13, 2019 10:52
Install Tensorflow/Keras in Ubuntu 18.04

在 Ubuntu 18 安裝 Tensorflow/Keras 開發環境

安裝 nVidia 顯示卡驅動程式

$ sudo apt-key adv --fetch-keys  http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
$ sudo bash -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
$ sudo add-apt-repository ppa:graphics-drivers/ppa
$ sudo apt-get update
$ sudo apt-get -y install nvidia-driver-415 htop git
@oneleo
oneleo / golang_new.md
Last active September 25, 2020 09:08
Go 語言基礎課程修訂草稿

Go 語言入門班

課程說明

  • Go 語言(又稱 Golang)是 Google 推出新一代的強大語言,2019 年 3 月 Google 公佈了去年底統計的問卷結果,發現 65% 用 Go 來寫網站,39% 用來開發系統程式,41% 用來做 DevOps(多重選擇),可想而知 Go 語言可以拿來從底層寫到上層。高效能的 Goroutine(併發)表現優於 Parallelism(並行),語法上簡潔又簡單,這也就是為什麼我們要來嘗試 Go 語言。

  • 註:因學院學員的電腦不用被切換畫面,原來的 Homework 的時間可以改成:直接讓學員手把手跟著老師一起操作。

  • 原因:學員常在自由的 Homework 的時間跑去做別的事,使得前段上課凝聚的集中力較容易散掉

@oneleo
oneleo / installgo_part1.cmd
Last active January 5, 2021 02:05
透過 Chocolatey 安裝 Go 環境
:: Run as administrator through CMD.exe
@echo off
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command " [System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
choco install -y git.install --params "/NoShellIntegration"
choco install -y vscode golang vscode-go googlechrome chrome-remote-desktop-host dontsleep.install winrar notepadplusplus.install
echo RAR registration data> "C:\Program Files\WinRAR\rarreg.key"
echo yaokai.org>> "C:\Program Files\WinRAR\rarreg.key"
echo Unlimited Company License>> "C:\Program Files\WinRAR\rarreg.key"
echo UID=75ced9c73b51fdd111d1>> "C:\Program Files\WinRAR\rarreg.key"
echo 641221225011d14d1c98ba62a152232016b11806608201f0e0460d>> "C:\Program Files\WinRAR\rarreg.key"