Skip to content

Instantly share code, notes, and snippets.

View jostyee's full-sized avatar
💭
脑壳疼

Josta Yee jostyee

💭
脑壳疼
  • Singapore
View GitHub Profile
@jostyee
jostyee / gist:5196067
Last active December 15, 2015 03:39
InetAddress hashCode to IP address
public static String getIpStr(int ip) {
StringBuilder sb = new StringBuilder();
int addr[] = new int[4];
addr[0] = (ip>>24) & 0xff;
addr[1] = (ip>>16) & 0xff;
addr[2] = (ip>>8) & 0xff;
addr[3] = ip & 0xff;
for (int i = 0; i < addr.length; i++) {
sb.append(addr[i]);
@jostyee
jostyee / gist:5196073
Created March 19, 2013 13:25
awk统计Linux下最常用的20条命令的shell
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n20
@jostyee
jostyee / gist:6894925
Created October 9, 2013 01:54
undo last GitHub push
git push -f origin HEAD^:master
public int clearBits(int num, int i) {
int mask = (1 << i) - 1;
return num & mask;
}
package main
// This is a basic example of running an nsqd instance embedded. It creates
// and runs an nsqd with all of the default options, and then produces
// and consumes a single message. You are probably better off running a
// standalone instance, but embedding it can simpllify deployment.
// See https://github.com/bitly/nsq/blob/master/nsqd/options.go and
// https://github.com/bitly/nsq/blob/master/apps/nsqd/nsqd.go for
// more details on how to configure an embedded nsqd instance.
package consumer
import (
"errors"
"testing"
"github.com/bitly/go-nsq"
)
// tests nsq.HandlerFunc. just write the function in line in the test
@jostyee
jostyee / README.md
Last active August 29, 2015 14:20 — forked from jonhoo/README.md

Distributed Read-Write Mutex in Go

The default Go implementation of sync.RWMutex does not scale well to multiple cores, as all readers contend on the same memory location when they all try to atomically increment it. This gist explores an n-way RWMutex, also known as a "big reader" lock, which gives each CPU core its own RWMutex. Readers take only a read lock local to their core, whereas writers must take all locks in order.

@jostyee
jostyee / 0_reuse_code.js
Last active August 29, 2015 14:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jostyee
jostyee / serverdemo.go
Last active August 29, 2015 14:22 — forked from fkautz/serverdemo.go
package main
import (
"bytes"
"fmt"
"github.com/gorilla/mux"
grpc "github.com/gorilla/rpc"
"github.com/gorilla/rpc/json"
"log"
"net/http"