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 / ipcalc.go
Created November 2, 2017 07:12 — forked from kotakanbe/ipcalc.go
get all IP address from CIDR in golang
package main
import (
"net"
"os/exec"
"github.com/k0kubun/pp"
)
func Hosts(cidr string) ([]string, error) {
@sanae10001
sanae10001 / graceful.go
Created November 1, 2017 06:54 — forked from peterhellberg/graceful.go
*http.Server in Go 1.8 supports graceful shutdown. This is a small example.
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"time"
)
@sanae10001
sanae10001 / gist:fa908fda6420b6c90567e202ae19cc42
Created October 25, 2017 10:48 — forked from bringhurst/gist:1693075
How to create a tun in osx without installing 3rd party crap
#include <netinet/in.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/kern_control.h>
#include <sys/ioctl.h>
#include <sys/sys_domain.h>
#include <sys/kern_event.h>
#include <sys/errno.h>
#define UTUN_CONTROL_NAME "com.apple.net.utun_control"
@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%
@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 / 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 / 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 / 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 / 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 / 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 {