Skip to content

Instantly share code, notes, and snippets.

View garukun's full-sized avatar
🐢
Taking a stroll away from GitHub for a bit

Steve Jiang garukun

🐢
Taking a stroll away from GitHub for a bit
View GitHub Profile
@garukun
garukun / di.go
Created April 11, 2018 17:15
dependency injection pattern
package main
import (
"net/http"
"net/http/httptest"
)
func main() {
m := mongo{}
h := handler{d: m}
@garukun
garukun / Brewfile
Last active June 26, 2017 13:24
Common Brewfile
# Install Homebrew (http://brew.sh)
# and then install brew bundle, `brew tap Homebrew/bundle`,
# and finally run `brew bundle`!
# Golang
brew 'glide'
brew 'go'
brew 'godep'
brew 'graphviz'
brew 'gnuplot'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!-- saved from url=(0013)http://cb.vu/ -->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>[www@cb.vu]~&gt;</title>
<link rel="icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAAAAABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAQAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////AOBfLwBbX14AWxgYABg8RwC/g14AGBgYAL9OJAB8KhgAfHFeAOCDUgC/g0cAGCo7AOCDXgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
@garukun
garukun / bash_kafka
Created February 20, 2016 06:20
Bash Kafka Script
#!/bin/bash
# kftopic performs several Kafka utility commands on a particular running Kafka
# container. See usage.
function kftopic {
case "_$1" in
_create)
docker exec $2 /bin/bash -c "\$KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 3 --topic $3" ;;
_describe)
docker exec $2 /bin/bash -c "\$KAFKA_HOME/bin/kafka-topics.sh --describe --zookeeper localhost:2181 --topic $3" ;;
@garukun
garukun / bash_go
Created February 20, 2016 06:18
Bash commands for Go
#!/bin/bash
# GO
export GOPATH=~/developments/go
export PATH=$PATH:/usr/local/opt/go/libexec/bin:$GOPATH/bin
# Go vendor feature.
export GO15VENDOREXPERIMENT=1
devgo() {
cd ~/developments/go/src/github.com/$@
@garukun
garukun / bash_docker
Last active February 20, 2016 06:15
Bash script for Docker related commands
#!/bin/bash
# Docker Machine
# dmls lists all available Docker machines.
dmls() {
docker-machine ls
}
# dmclean cleans all Docker containers, dangling imeages, and dangling volumes.
@garukun
garukun / gitconfig
Created February 20, 2016 06:11
Useful Git config
[alias]
ci = commit
cm = commit -am "squash!"
co = checkout
b = branch
cob = checkout -b
s = status
dg = difftool -t intellij -d
tree = log --graph --decorate --oneline
[color]
@garukun
garukun / reflectivejson.go
Created October 28, 2015 01:20
Go reflective with JSON Marshaling
package main
import "fmt"
import "reflect"
import "encoding/json"
func main() {
fmt.Println("Hello, playground")
f([]byte(`{"P":123,"Q":"abc"}`), A{})
@garukun
garukun / status.go
Last active October 23, 2015 17:15
Go Status Page Using expvar
package status
import (
"expvar"
"net/http"
"encoding/json"
)
// Status method dumps application variables and their values in JSON format.
func Status(writer http.ResponseWriter, request *http.Request) {
@garukun
garukun / backpressure-detection.go
Last active April 14, 2023 09:47
Go example regarding channels and backpressure
// https://play.golang.org/p/z2eYKhyoIk
package main
import "fmt"
import "time"
import "sync"
// Blocking detection for when pushing on filled buffered channel by using default.
func main() {
ch1 := make(chan int, 2)