Skip to content

Instantly share code, notes, and snippets.

View huahuayu's full-sized avatar
🎯
Focusing

Shiming huahuayu

🎯
Focusing
View GitHub Profile
@huahuayu
huahuayu / 0xa6D275A23Fd3ED513AA7E82b674960778ca6310C
Created April 8, 2018 06:39
0xa6D275A23Fd3ED513AA7E82b674960778ca6310C
0xa6D275A23Fd3ED513AA7E82b674960778ca6310C
@huahuayu
huahuayu / etherindex.sol
Last active April 10, 2018 14:33
etherindex
pragma solidity ^0.4.21;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";
contract SafeMath {
function safeToAdd(uint a, uint b) pure internal returns (bool) {
return (a + b >= a);
}
function safeAdd(uint a, uint b) pure internal returns (uint) {
require(safeToAdd(a, b));
@huahuayu
huahuayu / Dapp开发-第二讲-习题.txt
Created May 13, 2018 14:49
Dapp开发-第二讲-习题
1. solidity中除了uint外还有uint8,uint32,uint128,uint256等,那么uint默认是多少位的?
2. solidity中如何表示日期、时间?
3. 已知今天是20180513,要求23天后是哪一天?solidity中如何做到?
4. solidity中的now,取到的是一个什么时间?怎么转换为可读的日期+时分秒格式?
5. solidity是否支持uint --> string, string --> uint强制类型转换?如果要转换,如何转?
6. solidity中是否支持浮点数?如果要计算1.4 eth + 0.008 eth,如何做到?
7. solidity如何定义结构体?如何访问结构体中的元素?
8. mapping(address => uint) balances; 这个定义代表什么意思?
9. mapping(address => (uint => string)) vars; 这个定义代表什么意思?如何访问vars中的元素?
10. 数组uint[] numArrary = [1,7,2,4]; 如何访问第二个元素?如何添加元素(到末尾),如何删除元素(删除第二个元素,后面的元素前移),如何插入元素?
// Code generated - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
package main
import (
"math/big"
"strings"
ethereum "github.com/ethereum/go-ethereum"
package main
import (
"fmt"
"log"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)
@huahuayu
huahuayu / filterQuery.go
Last active September 5, 2018 12:36
code snippet to filter ethereum event log
package main
import (
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"context"
"fmt"
"math/big"
"github.com/ethereum/go-ethereum/accounts/abi"
@huahuayu
huahuayu / gocurl.go
Last active January 23, 2019 05:12
[gocurl]用go实现curl命令 #go #init #go调用shell命令 #go获得命令行参数 #HasPrefix
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"os/exec"
"strings"
)
@huahuayu
huahuayu / unbufferedchannel.go
Created January 23, 2019 05:26
[unbuffered channel]使用unbuffered channel goroutine轮询网站 #goroutine #channel #go
package unbuffered
import (
"fmt"
"net/http"
"time"
)
func main() {
links := []string{
@huahuayu
huahuayu / bufferedchannel.go
Created January 23, 2019 06:12
[bufferedchannel]bufferedchannel with waiting group #waiting group #channel
package main
import (
"gpool"
"fmt"
"net/http"
"time"
)
func main() {
@huahuayu
huahuayu / cache.go
Created February 11, 2019 06:58 — forked from zemirco/cache.go
golang database layer with cache
type CacheInterface interface {
Get(key string) ([]byte, error)
Set(key string, value interface{}) error
}
// Cache implements CacheInterface.
type Cache struct {
// wrap redis pool connection
// or whatever you need
}