Skip to content

Instantly share code, notes, and snippets.

@bemasher
bemasher / subparse.go
Last active December 17, 2015 17:19
Parses SubRip format subtitles using a finite state machine. Handles malformed index and time ranges.
package main
import (
"bufio"
"fmt"
"os"
"regexp"
"strings"
"sync"
"time"
package main
import (
"fmt"
"sort"
"time"
"math/rand"
)
const (
@bemasher
bemasher / char_pairs.sql
Created December 18, 2012 14:35
Query for collecting id's of sequential character pairs matching a particular tuple of characters.
INSERT INTO Merge SELECT
a.SemanticID,
MIN(b.SemanticID)
FROM SubtitleSemantic a
JOIN SubtitleSemantic b ON
a.SemanticID < b.SemanticID
AND a.SubtitleID = b.SubtitleID
AND a.Line = b.Line
AND b.CharID = :second
WHERE a.CharID = :first
@bemasher
bemasher / bodybugg_log.java
Created November 18, 2012 06:52
Download all session data from a BodyBugg and clear device memory.
package com.bypass;
import com.bodymedia.common.applets.CommandException;
import com.bodymedia.common.applets.device.util.LibraryException;
import com.bodymedia.device.serial.SerialPort3;
import com.bodymedia.device.usb.Usb;
import com.bodymedia.common.applets.logger.Logger;
import java.io.FileWriter;
import java.io.IOException;
@bemasher
bemasher / auth.go
Created October 26, 2012 23:10
OAuth example creating an event using google's calendar api.
package main
import (
"os"
"fmt"
"time"
"net/http"
"errhandler"
"encoding/json"
"code.google.com/p/goauth2/oauth"
\documentclass[twocolumn,10pt]{article}
\usepackage[top=0.5cm, bottom=0.5cm, left=0.5cm, right=0.5cm]{geometry}
\usepackage{amssymb, amsmath, amstext}
\usepackage{datetime}
\usepackage{listings}
\usepackage[pdftex]{graphicx}
\usepackage{subfigure}
\usepackage{siunitx}
\usepackage{enumitem}
\setlist{nosep}
@bemasher
bemasher / intput.txt
Created July 10, 2012 12:51
Named Binary Tag parser written in Golang using reflection to populate native types.
// This is the structure of the binary nbt file
TAG_Compound('Level') {
TAG_Compound('nested compound test') {
TAG_Compound('egg') {
TAG_String('name'): 'Eggbert'
TAG_Float('value'): 0.5
}
TAG_Compound('ham') {
TAG_String('name'): 'Hampus'
TAG_Float('value'): 0.75
@bemasher
bemasher / generate_table.go
Created April 13, 2012 22:24
A program for formatting tables copied from excel into the LaTeX tabular environment.
package main
import (
"os"
"fmt"
"math"
"strconv"
"strings"
"errhandler"
"text/template"
@bemasher
bemasher / imageset_test.go
Created April 8, 2012 09:24
Benchmark for comparing safe and unsafe methods for setting a pixel in the golang image package.
package ImageSet
import (
"image"
"image/color"
"testing"
)
const (
DIM = 128
@bemasher
bemasher / dates.go
Created March 23, 2012 07:59
Days of the year which are powers of 2 starting from both beginning and end of the year.
package main
import (
"fmt"
"time"
)
const (
DateFormat = "2006-01-02: Jan 02"
)