Skip to content

Instantly share code, notes, and snippets.

// RingBuffer reads messages from in and writes them to out.
// Whenever out is full, it will remove the oldest message to make room.
// Adapted from https://blog.pivotal.io/labs/labs/a-concurrent-ring-buffer-for-go.
func RingBuffer(in <-chan Message, size int) <-chan Message {
out := make(chan Message, size)
go func() {
defer close(out)
for m := range in {
select {
case out <- m:
@dmichael
dmichael / httpclient.go
Last active October 18, 2023 20:07
Light wrapper for the Go http client adding (essential) timeouts for both connect and readwrite.
package httpclient
import (
"net"
"net/http"
"time"
)
type Config struct {
ConnectTimeout time.Duration
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this: