Skip to content

Instantly share code, notes, and snippets.

func payloadHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
// Read the body into a string for json decoding
var content = &PayloadCollection{}
err := json.NewDecoder(io.LimitReader(r.Body, MaxLength)).Decode(&content)
type Dispatcher struct {
// A pool of workers channels that are registered with the dispatcher
WorkerPool chan chan Job
}
func NewDispatcher(maxWorkers int) *Dispatcher {
pool := make(chan chan Job, maxWorkers)
return &Dispatcher{WorkerPool: pool}
}
var (
MaxWorker = os.Getenv("MAX_WORKERS")
MaxQueue = os.Getenv("MAX_QUEUE")
)
// Job represents the job to be run
type Job struct {
Payload Payload
}
@chsjiang
chsjiang / tmux-cheatsheet.markdown
Created May 14, 2017 04:52 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@chsjiang
chsjiang / pg_to_es.py
Created May 13, 2017 02:23
Postgres to Elasticsearch conversor script. It will assumes: - Database is equivalent as an index - Tables are equivalent as a mapping types You must pass a query for retreive data.
#!/usr/bin/python
import psycopg2
import psycopg2.extras
from pyes import *
import argparse
import traceback
import math
def ResultIter(cursor, arraysize=100):
# An iterator that uses fetchmany to keep memory usage down
@chsjiang
chsjiang / gist:3179122
Created July 25, 2012 22:33 — forked from saetia/gist:1623487
Clean Install – Mountain Lion OS X 10.8 DP3 Update 4