Skip to content

Instantly share code, notes, and snippets.

Avatar
🌵

Qian Chen elgs

🌵
View GitHub Profile
@elgs
elgs / gist:c7fe4c3c83d8c3048f5e
Created Aug 25, 2014
reverse string in Golang
View gist:c7fe4c3c83d8c3048f5e
func reverse(input string) string {
n := 0
rune := make([]rune, len(input))
for _, r := range input {
rune[n] = r
n++
}
rune = rune[0:n]
// Reverse
for i := 0; i < n/2; i++ {
@elgs
elgs / Nodejs_Cluster.md
Last active Aug 29, 2015
Nodejs cluster
View Nodejs_Cluster.md
var cluster = require('cluster');
var http = require('http');
var numWorkers = 2;

if (cluster.isMaster) {
    // Fork worker.
    for (var i = 0; i < numWorkers; ++i) {
        console.log('master: about to fork a worker');
        cluster.fork();