Skip to content

Instantly share code, notes, and snippets.

@benbjohnson
benbjohnson / videogen.sh
Created August 28, 2013 23:22
Generate a video of frame numbers.
#!/bin/bash
# Generate the frames
for i in {0..1800}
do
echo "Generating frame $i"
convert -background black -fill white -size 480x320 -pointsize 48 -gravity center label:${i} frame${i}.png
done
# Combine frames into H.264 MP4 video. (29.97fps & 30fps)
@benbjohnson
benbjohnson / store.go
Created June 13, 2014 12:04
Session Store Expiration
package store
import (
"fmt"
"github.com/boltdb/bolt"
)
// reap removes sessions older than a given duration.
// This function assumes that all session data is stored in a "sessions" bucket
@benbjohnson
benbjohnson / msgpack_spec.md
Created July 9, 2012 22:59
MessagePack Format Specification

Fixnums

positive fixnum

Save an integer within the range [0, 127] in 1 bytes.

+--------+
|0XXXXXXX|
+--------+
@benbjohnson
benbjohnson / README.md
Created March 3, 2014 03:17
Application-side Interfaces in Go

Application-side Interfaces in Go

By moving the interface to the application-side (application.go), you can still set the implementation-specific configuration details when you instantiate your library structs. If the interface was implemented on the library-side then you would need to provide:

type DB interface {
  Get([]byte) ([]byte, error)
  Put([]byte, []byte) error
  CacheSize() int
 SetCacheSize(int)
@benbjohnson
benbjohnson / slices.txt
Last active June 11, 2019 22:46
Enqueue/Dequeue Slices
^ = The pointer to the initial element of the slice.
---
1. Initial queue (size=0, capacity=3)
-------
| | | |
-------
@benbjohnson
benbjohnson / README.md
Last active February 11, 2019 12:10
LuaJIT + Go Integration Test

Create an empty directory, download the code and run it:

$ mkdir /tmp/lj
$ cd /tmp/lj
$ wget https://gist.github.com/benbjohnson/5622779/raw/e53d227ebdbea8d513b62ad076feb3f6ac1c1594/luajit.go
$ go run luajit.go

And you should see:

@benbjohnson
benbjohnson / main.go
Created May 12, 2014 16:37
Bolt for timestamp data
package main
import (
"encoding/binary"
"log"
"time"
"github.com/boltdb/bolt"
)
package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
@benbjohnson
benbjohnson / README.md
Created August 4, 2014 04:02
Simple Go Deployment on Ubuntu

Steps

  1. Setup Go cross-compile using Dave Cheney's instructions & package.

  2. Copy the myapp.conf file to /etc/init/myapp.conf. Change the name of the service to whatever you want to call it.

  3. Change the name parameter in myapp.conf to your application's name.

  4. Change the script / end script block to whatever you need to startup your app.

@benbjohnson
benbjohnson / gist:8338908
Created January 9, 2014 18:03
Cross Compile w/ drone.io
# This is what I have so far. The Go 1.2 installation doesn't seem to be correct so it's still breaking.
rm -rf /usr/local/go/src/pkg/appengine
rm -rf /usr/local/go/src/pkg/appengine_internal
rm /usr/local/go/src/pkg/os/error_posix.go
wget -O golang-crosscompile-master.zip https://github.com/davecheney/golang-crosscompile/archive/master.zip
unzip golang-crosscompile-master.zip
source golang-crosscompile-master/crosscompile.bash
go-crosscompile-build darwin/amd64