Skip to content

Instantly share code, notes, and snippets.

@inhies
inhies / prettyprint.go
Created August 14, 2017 06:32
pretty print structs
func PrettyPrint(v interface{}) {
b, _ := json.MarshalIndent(v, "", " ")
println(string(b))
}
package main
import (
"fmt"
"os"
)
func main() {
a := []int{1, 2, 3, 4, 5}
for len(a) > 0 {
@inhies
inhies / useproxy.go
Created December 16, 2016 19:28
This code changes http.DefaultClient to use a SOCKS5 proxy
// create a socks5 dialer
dialer, err := proxy.SOCKS5("tcp", PROXY_ADDR, nil, proxy.Direct)
if err != nil {
fmt.Fprintln(os.Stderr, "can't connect to the proxy:", err)
os.Exit(1)
}
// setup a http client
httpTransport := &http.Transport{}
// set our socks5 as the dialer
@inhies
inhies / topic.go
Created October 21, 2016 17:09
Checks an MQTT topic against an MQTT subscription to see if it matches. Supports MQTT wildcards.
package main
import (
"log"
"strings"
)
type check struct {
Sub, Topic string
ShouldMatch bool
@inhies
inhies / server.go
Last active October 13, 2023 22:21
A basic web server that will serve templates and reload them when they are changed on disk
package main
import (
"fmt"
"html/template"
"io/ioutil"
"log"
"net/http"
"strings"
@inhies
inhies / Raspberry Pi L2TP VPN Setup Scripts.md
Last active October 1, 2016 02:45 — forked from alryaz/Raspberry Pi L2TP VPN Setup Scripts.md
RPi SoftEther Installer | v4.20-9608-rtm-2016.04.17

Install raspbian, set up your users however you would like, so long as you have sudo access on the user you are running this with. You probably want to resize the image so it fills the SD card as well.

  1. Copy this entire gist to your raspberry pi
  2. Do chmod +x step1.sh step2.sh iptables.sh in the gist folder (so that
  3. Run step1.sh a) This script does a few things - it first updates your raspberry pi, then it installs a few needed utilities, then it upgrades the firmware on your
@inhies
inhies / btccny.go
Last active December 30, 2015 13:58
Console ticker for btc china
package main
import (
"encoding/json"
"fmt"
"github.com/kylelemons/godebug/pretty"
"io/ioutil"
"net/http"
"strconv"
"time"
package main
import (
"bytes"
"fmt"
"net/http"
"strconv"
)
func handler(w http.ResponseWriter, r *http.Request) {
@inhies
inhies / subtree
Last active November 18, 2016 21:15
Subtree is a helper utility for working with git subtrees. Easily add, update, and remove subtrees from your git repo.
#!/bin/bash
# subtree -- a utility to help working with git subtree's
# creator: inhies
# 24 November 2013
version=1.1.1
function usage() {
case "$1" in
@inhies
inhies / ddd.go
Created November 17, 2013 06:06
Demonstration of using tons of go routines to http.Get lots of web pages.
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
"runtime"
"sync"
)