Skip to content

Instantly share code, notes, and snippets.

View qbig's full-sized avatar

Liang qbig

  • @us3r-network
  • Singapore
View GitHub Profile
@qbig
qbig / config.yml
Created November 25, 2020 16:02 — forked from asselstine/config.yml
Run Truffle Tests on CircleCI 2.0
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
@qbig
qbig / go-concurrency-patterns.md
Created September 27, 2018 04:53 — forked from yosssi/go-concurrency-patterns.md
Go Concurrency Patterns

Go Concurrency Patterns

Generator: function that returns a channel

package main

import (
	"fmt"
	"math/rand"
@qbig
qbig / ethereum_ecrecover_native_contract.go
Created September 16, 2018 14:48 — forked from dominiek/ethereum_ecrecover_native_contract.go
ethereum_ecrecover_native_contract.go
// ECRECOVER implemented as a native contract.
type ecrecover struct{}
func (c *ecrecover) RequiredGas(input []byte) uint64 {
return params.EcrecoverGas
}
func (c *ecrecover) Run(input []byte) ([]byte, error) {
const ecRecoverInputLength = 128
@qbig
qbig / elliptic_signing.js
Created September 16, 2018 14:48 — forked from dominiek/elliptic_signing.js
elliptic_signing.js
EC.prototype.sign = function sign(msg, key, enc, options) {
if (typeof enc === 'object') {
options = enc;
enc = null;
}
if (!options)
options = {};
key = this.keyFromPrivate(key, enc);
msg = this._truncateToN(new BN(msg, 16));
@qbig
qbig / metamask_ethereum_signing.js
Created September 16, 2018 14:48 — forked from dominiek/metamask_ethereum_signing.js
metamask_ethereum_signing.js
// For eth_sign, we need to sign arbitrary data:
signMessage (withAccount, data) {
const wallet = this._getWalletForAccount(withAccount)
const message = ethUtil.stripHexPrefix(data)
var privKey = wallet.getPrivateKey()
var msgSig = ethUtil.ecsign(new Buffer(message, 'hex'), privKey)
var rawMsgSig = ethUtil.bufferToHex(sigUtil.concatSig(msgSig.v, msgSig.r, msgSig.s))
return Promise.resolve(rawMsgSig)
}
@qbig
qbig / ethereum_smart_contract_ecrecover.sol
Created September 16, 2018 14:47 — forked from dominiek/ethereum_smart_contract_ecrecover.sol
ethereum_smart_contract_ecrecover.sol
function getOriginAddress(bytes32 signedMessage, uint8 v, bytes32 r, bytes32 s) constant returns(address) {
bytes memory prefix = "\x19Ethereum Signed Message:\n32";
bytes32 prefixedHash = keccak256(prefix, signedMessage);
return ecrecover(prefixedHash, v, r, s);
}
@qbig
qbig / ethereum_web3_signing.js
Created September 16, 2018 14:47 — forked from dominiek/ethereum_web3_signing.js
Ethereum Web3 Signing
const message = web3.sha3('Hello World');
const signature = await web3.eth.sign(account, message);
const { v, r, s } = ethUtil.fromRpcSig(signature);
@qbig
qbig / gzip.go
Created September 7, 2018 08:30 — forked from alex-ant/gzip.go
golang: gzip and gunzip
package main
import (
"bytes"
"compress/gzip"
"fmt"
"io"
"log"
)
@qbig
qbig / ecverify.sol
Created August 23, 2018 02:07 — forked from axic/ecverify.sol
Ethereum ECVerify
//
// The new assembly support in Solidity makes writing helpers easy.
// Many have complained how complex it is to use `ecrecover`, especially in conjunction
// with the `eth_sign` RPC call. Here is a helper, which makes that a matter of a single call.
//
// Sample input parameters:
// (with v=0)
// "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad",
// "0xaca7da997ad177f040240cdccf6905b71ab16b74434388c3a72f34fd25d6439346b2bac274ff29b48b3ea6e2d04c1336eaceafda3c53ab483fc3ff12fac3ebf200",
// "0x0e5cb767cce09a7f3ca594df118aa519be5e2b5a"
@qbig
qbig / reflection.go
Created August 20, 2018 08:33 — forked from drewolson/reflection.go
Golang Reflection Example
package main
import (
"fmt"
"reflect"
)
type Foo struct {
FirstName string `tag_name:"tag 1"`
LastName string `tag_name:"tag 2"`