Skip to content

Instantly share code, notes, and snippets.

@guoxingx
guoxingx / Exercise-Stringers.go
Last active May 18, 2018 07:50
A Tour of Go - Exercise: Stringers
package main
import "fmt"
type IPAddr [4]byte
// TODO: Add a "String() string" method to IPAddr.
func (ip IPAddr) String() string {
return fmt.Sprintf("%v.%v.%v.%v", ip[0], ip[1], ip[2], ip[3])
}
@guoxingx
guoxingx / Exercise-Fibonacci-closure.go
Created May 18, 2018 07:55
A Tour of Go - Exercise: Fibonacci closure
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
a, b, n := 0, 1, 0
return func() int {
a, b, n = b, a + b, n + 1
@guoxingx
guoxingx / Exercise-Errors.go
Created May 18, 2018 08:20
A Tour of Go - Exercise: Errors
package main
import (
"fmt"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
return fmt.Sprintf("cannot Sqrt negative number: %v", float64(e))
@guoxingx
guoxingx / Exercise-Readers.go
Created May 18, 2018 10:12
A Tour of Go - Exercise: Readers
package main
import (
"golang.org/x/tour/reader"
)
type MyReader struct{}
// TODO: Add a Read([]byte) (int, error) method to MyReader.
func (reader MyReader) Read(b []byte) (int, error) {
@guoxingx
guoxingx / Exercise-rot13Reader.go
Created May 18, 2018 10:59
A Tour of Go - Exercise: rot13Reader
package main
import (
"io"
"os"
"strings"
)
type rot13Reader struct {
r io.Reader
@guoxingx
guoxingx / Exercise-Images.go
Created May 18, 2018 11:21
A Tour of Go - Exercise: Images
package main
import (
"golang.org/x/tour/pic"
"image"
"image/color"
)
type Image struct{}
@guoxingx
guoxingx / Exercise-Equivalent-Binary-Trees.go
Created May 18, 2018 17:16
A Tour of Go - Exercise: Equivalent Binary Trees
package main
import (
"golang.org/x/tour/tree"
"fmt"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int) {
@guoxingx
guoxingx / grab_ropsten_ether.py
Created June 13, 2018 05:30
Script to request ether in testnet
#!/usr/bin/env python
import os
import enum
import time
import asyncio
import hashlib
import argparse
import requests
@guoxingx
guoxingx / memcheck.py
Created June 13, 2018 05:31
Get memory info
"""
basic memory check functions.
"""
import subprocess
def get_memory_info(remote_addr=None):
"""
All messages from /proc/meminfo
@guoxingx
guoxingx / solcdocker.py
Created July 5, 2018 03:13
docker solc cmd
#!/usr/bin/env python
"""
chmod a+x solcdocker
mv solcdocker /usr/local/bin
usage:
solcdocker <path-to-sol-file>
output: