Skip to content

Instantly share code, notes, and snippets.

View wrfly's full-sized avatar
💻
enjoy coding

Shaun wrfly

💻
enjoy coding
View GitHub Profile
@wrfly
wrfly / selectErrors.go
Last active October 23, 2018 08:57
error selection
package main
import (
"fmt"
"time"
)
type e struct{}
func chanErr(produceErr bool, d time.Duration, noErrChan chan e) chan e {
@wrfly
wrfly / tee.go
Last active October 18, 2018 07:18
io tee problem
package main
import (
"flag"
"fmt"
"io"
"time"
)
func newReader() io.Reader {
@wrfly
wrfly / race.go
Created October 8, 2018 08:43
golang test race (pointer is not safe neither)
package main
// ➜ race go test -race -run TestNoRace .
// ok _/Users/shaun.fu/test/go/race 1.288s
// ➜ race go test -race -run TestRace .
import (
"sync"
"testing"
)
@wrfly
wrfly / eru-install.sh
Last active September 20, 2018 08:13
#!/bin/bash
# eru install
set -e
now=`date +%s`
function log() {
echo "[$((`date +%s` - now ))] ## $@ ##"
}
@wrfly
wrfly / resize.sh
Created July 26, 2018 10:42
resize window
#!/bin/bash
res() {
old=$(stty -g)
stty raw -echo min 0 time 5
printf '\0337\033[r\033[999;999H\033[6n\0338' > /dev/tty
IFS='[;R' read -r _ rows cols _ < /dev/tty
stty "$old"
@wrfly
wrfly / string2bytes.go
Created July 11, 2018 02:15
golang- string2bytes
package main
import (
"fmt"
"unsafe"
)
func main() {
str := "xxx"
fmt.Printf("%p, %v\n", &str, str)
@wrfly
wrfly / get_ip.sh
Last active June 24, 2018 17:49
get ip address without curl
#!/bin/bash
# HTTP 1.1
exec 3<> /dev/tcp/ident.me/80 && \
echo 'GET / HTTP/1.1' >&3 && \
echo 'Host: ident.me' >&3 && \
echo '' >&3 && while true;do \
read -t 1 -u 3 RESP; echo $RESP;
[ "$RESP" == "" ] && break;
done && \
@wrfly
wrfly / stream-server.go
Created June 6, 2018 03:33
go-gin | http stream server
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"time"
"github.com/gin-gonic/gin"
@wrfly
wrfly / fizz-buzz.go
Created May 9, 2018 04:15
fizz buzz problem
// https://play.golang.org/p/T8Dpm4HzX6x
package main
import "fmt"
func main() {
const (
fizz = 3
buzz = 5
fizzbuzz = 15
@wrfly
wrfly / signal.go
Created May 4, 2018 06:23
golang cat signal
package main
import (
"log"
"os"
"os/signal"
"syscall"
)
func main() {