Skip to content

Instantly share code, notes, and snippets.

View azylman's full-sized avatar

Alex Zylman azylman

  • San Francisco, CA
View GitHub Profile
/*
Welcome to April's Go Problem of the Month!
This month's challenge will take you through simulations of slowly degrading services (inspired by a
well-known identity provider whose name rhymes with "Oogle").
Our services return a number, and our challenge is to fetch 500 numbers from the service and sum the
results as quickly as possible.
You'll fill out implementations of the three functions, handling increasingly degraded services as
package main
import (
"net/http"
"net/http/httptest"
"net/http/httputil"
"net/url"
)
func main() {
@azylman
azylman / client.md
Last active August 29, 2015 14:24
Demonstration of a gearman server in go (https://github.com/azylman/gearman). All of the tools written to interact with Gearman still work.
$ echo -n "trolling" | gearman -p 4731 -f test
trolling
// batchChannel takes in a channel and outputs them grouped into batches. The batch will be sent when
// either there are enough to complete the batchSize or the flushInterval has elapsed.
func batchChannel(in chan interface{}, out chan interface{}, batchSize int, flushInterval time.Duration) {
tickChan := time.Tick(flushInterval)
buffer := make([]interface{}, 0)
for {
select {
case el := <-in:
buffer = append(buffer, el)
@azylman
azylman / run.md
Last active August 29, 2015 13:57 — forked from rgarcia/run.md
$ node server.js

output in terminal shows that req.foo is no longer sitting in the heap:

got request with a foo of length 10000000
hello world
got request with a foo of length 0
var DM, Document, PM, Property, Schema, assert, async, docs, mongoose;
mongoose = require('mongoose');
Schema = mongoose.Schema;
async = require('async');
assert = require('assert');