Skip to content

Instantly share code, notes, and snippets.

View hangyan's full-sized avatar
🌴
On vacation

Hang Yan hangyan

🌴
On vacation
View GitHub Profile
@hangyan
hangyan / connect.go
Last active May 28, 2019 09:30
A simple golang reverseproxy backup
package proxy
import (
"io"
"net"
"net/http"
"time"
)
func transfer(destination io.WriteCloser, source io.ReadCloser) {
@hangyan
hangyan / main.go
Created May 17, 2019 07:24 — forked from ncdc/main.go
Simple Kubernetes client-go example code
package main
import (
"flag"
"fmt"
"os"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
@hangyan
hangyan / multiple-host-reverse-proxy.go
Created May 17, 2019 06:21 — forked from ego008/multiple-host-reverse-proxy.go
Multiple host reverse proxy in Go
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
var (
@hangyan
hangyan / context.go
Created April 10, 2019 03:31 — forked from iamralch/context.go
An example that illustrates how to work with https://godoc.org/golang.org/x/net/context
package main
import (
"bufio"
"fmt"
"os"
"strings"
"time"
"golang.org/x/net/context"
@hangyan
hangyan / git-tag-delete-local-and-remote.sh
Created February 12, 2019 06:51 — forked from mobilemind/git-tag-delete-local-and-remote.sh
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@hangyan
hangyan / channel-manager-server.go
Created January 31, 2019 07:17
Golang web channel example
// This version of the server protects all shared data within a manager
// goroutine that accepts commands using a channel.
//
// Eli Bendersky [http://eli.thegreenplace.net]
// This code is in the public domain.
package main
import (
"fmt"
"log"
kubectl config set-cluster default-cluster --server=https://master_ip --certificate-authority=ssl/ca.pem
kubectl config set-credentials default-admin --certificate-authority=ssl/ca.pem --client-key=ssl/admin-key.pem --client-certificate=ssl/admin.pem
kubectl config set-context default-system --cluster=default-cluster --user=default-admin
kubectl config use-context default-system
# obviously you need the CA used to bootstrap your cluster and all the certificates
@hangyan
hangyan / zshrc
Last active October 4, 2015 10:02
check tools installed via brew on mac
function brew_check() {
brew $2 info $1 | grep -q "Not installed"
}
function brew_install() {
tool=$(echo $1 | awk '{print $1}')
cask=$(echo $1 | awk '{print $2}')
brew_check $tool $cask
[[ $? -eq 0 ]] && echo -e "Installing $tool..." && brew $cask install $tool
@hangyan
hangyan / simpleprocess.cpp
Last active September 9, 2015 09:46 — forked from massenz/simpleprocess.cpp
libprocess simple HTTP server
/*
* simpleprocess.cpp
*
* Created on: Jun 26, 2015
* Author: Marco Massenzio
*/
#include <iostream>
#include <process/dispatch.hpp>
@hangyan
hangyan / git-multi-user-ssh-config
Created February 26, 2015 08:01
git multi user ssh config file settings
Host work.github.com
HostName github.com
User WORK_GITHUB_USERNAME
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_work_rsa
IdentitiesOnly yes
Host personal.github.com
HostName github.com
User PERSONAL_GITHUB_USERNAME