Skip to content

Instantly share code, notes, and snippets.

View sanae10001's full-sized avatar

sanae10001 sanae10001

  • Sloan Great Wall
View GitHub Profile
@sanae10001
sanae10001 / latency.txt
Created January 13, 2017 09:31 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@sanae10001
sanae10001 / myip.go
Created February 9, 2017 09:05 — forked from jniltinho/myip.go
Get My IP Golang
package main
/*
URL: https://github.com/mccoyst/myip/blob/master/myip.go
URL: http://changsijay.com/2013/07/28/golang-get-ip-address/
*/
import (
"net"
"os"
@sanae10001
sanae10001 / brew
Created February 14, 2017 13:21
Brew install a specific version of a formula
Find the commit history of the desired software and version in github. e.g. "https://github.com/Homebrew/homebrew-core/commits/master/Formula/git.rb"
Click `raw` button, get raw url e.g. "https://raw.githubusercontent.com/Homebrew/homebrew-core/6f85b5c82436b2f8beb3c0fd64f36d6f466cf0f7/Formula/git.rb"
brew unlink `formula` e.g. "brew unlink git"
brew install `url`
You can use `brew switch` switch version
@sanae10001
sanae10001 / mgoExample.go
Created March 10, 2017 02:36 — forked from border/mgoExample.go
mgo example
package main
import (
"fmt"
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"time"
)
type Person struct {
@sanae10001
sanae10001 / ca.md
Created April 21, 2017 09:17 — forked from soarez/ca.md
How to setup your own CA with OpenSSL

How to setup your own CA with OpenSSL

For educational reasons I've decided to create my own CA. Here is what I learned.

First things first

Lets get some context first.

@sanae10001
sanae10001 / read_line.go
Created April 24, 2017 12:18 — forked from kendellfab/read_line.go
Golang --> Read file line by line.
func readLine(path string) {
inFile, _ := os.Open(path)
defer inFile.Close()
scanner := bufio.NewScanner(inFile)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
fmt.Println(scanner.Text())
}
}
@sanae10001
sanae10001 / readlines.go
Last active April 25, 2017 08:30
Read lines from file
import (
"bufio"
"io"
)
type FileLineFunc func(line []byte) (isExit bool, err error)
func ReadLines(file io.Reader, bufLen int, f FileLineFunc) error {
buffer := make([]byte, 0, bufLen)
scanner := bufio.NewScanner(file)
@sanae10001
sanae10001 / stringtobytes.go
Created April 25, 2017 07:56
Convert string to bytes array
// Convert string to bytes array, don't allocate extra memory
// General: []byte(string), this may allocate memory more than len(string)
func StringToBytes(s string) []byte {
b := make([]byte, len(s))
copy(b[:], s)
return b
}
@sanae10001
sanae10001 / verify.go
Created May 5, 2017 07:42 — forked from jedy/verify.go
use publib key to verify in golang
package main
import (
"crypto"
"crypto/rsa"
"crypto/sha1"
"crypto/x509"
"encoding/base64"
"fmt"
)
@sanae10001
sanae10001 / ComputerName.txt
Created August 21, 2017 07:22
Get computer name via command line
macos:
1. networksetup -getcomputername
2. scutil --get ComputerName
windows:
1. echo %ComputerName%