James Bowes

Purveyor of Pre-eminent Programmes

Moved my blog

leave a comment »

I’ve moved my blog to blog.repl.ca. It’s the same stuff, with a different name. I’ll leave the existing posts up here, for search engines and whatnot.

Written by jbowes

November 21, 2011 at 1:09 pm

Posted in Uncategorized

HOWTO Make a USB Y Cable for Host Mode

leave a comment »

Many smartphones or tablets support USB host mode (or On The Go mode) with an adapter. Unfortunately, a lot of those devices don’t supply power to their client USB devices; you can’t just plug a host mode adapter into an HP TouchPad, for example, then plug a keyboard into the host mode adapter, and expect everything to work.

I put up a video on youtube explaining how to build and use a USB Y cable to inject power to the client devices. If you’d like, you can watch it here

Written by jbowes

November 6, 2011 at 6:52 pm

Posted in tech

An Access Logger for Netty and HTTP

leave a comment »

We needed to do CLF style HTTP access logging for Thumbslug, which is implemented in Java + Netty. I couldn’t find any code to do this with a quick google search, so I wrote my own. If you need such a thing, try here or here (backup).

Written by jbowes

July 5, 2011 at 12:01 pm

Posted in fedora, tech

Measuring Network Speeds with Netcat and Dd

with 6 comments

I’ve seen a few posts on the web about testing your network speeds with netcat, but they all seem to not work with recent versions of netcat.

On one machine, run:

nc -v -l 2222 > /dev/null

(Make sure you’re not blocking connections to 2222!)

On a second machine, run:

dd if=/dev/zero bs=1024K count=512 | nc -v $IP_OF_FIRST_MACHINE 2222

dd will give you your speed:

536870912 bytes (537 MB) copied, 4.87526 s, 117 MB/s

Yay, gigabit!

ymmv, test with /dev/zero at your own risk. Speak with your NOC before starting any network infrastructure changes.

Written by jbowes

October 13, 2010 at 9:18 am

Posted in tech

Converting SVN Commits to Git Patches

leave a comment »

In case you find yourself in need of a way to turn an svn revision into a git patch that can be applied with ‘git am’, keeping the commit message and authorship information, here’s a script I used recently:

# svnrev2git.py - Convert an SVN revsion to a Git patch.
# Author: James Bowes <jbowes@repl.ca>
# Usage:
#   $> cd my-svn-repo
#   $> python svnrev2git.py [AUTHORS_FILE] [REV_RANGE | REVSION [REVISION..]]
#   AUTHORS_FILE - a CSV of  svn username, full name, email
#   REV_RANGE - an svn revision range, like 100-700
#   REVISION - a single svn revision
#   You may specify either a revision range, or a series of individual
#   svn revisions
# Output:
#   A series of git style patch files, one per svn revision, which can then be
#   applied with 'git am'
# Why use this instead of 'git svn'?
#   I had done a large repo conversion via git svn where we wanted no downtime
#   for the switchover. After removing the git svn specific info from our git
#   commits, I used this tool to bring in commits from svn, keeping svn and git
#   in sync, until we were ready to switch.

import sys
import commands

def svnlog_to_gitlog(authors, svnlog):

    lines = svnlog.split("\n")
    lines = lines[1:-1]

    metainfo = lines[0].split(" | ")
    subject = lines[2]
    description = lines[3:]

    author = metainfo[1]

    day = metainfo[2].split("(")[1][:-1]
    time = metainfo[2].split(" ")[1]
    offset = metainfo[2].split(" ")[2]

    gitlog = []
    gitlog += ["From: %s <%s>" % authors[author]]
    gitlog += ["Date: %s %s %s" % (day, time, offset)]
    gitlog += ["Subject: [PATCH] %s" % subject]
    gitlog += [""]
    gitlog += description
    gitlog += [""]

    return '\n'.join(gitlog)

def svndiff_to_gitdiff(svndiff):
    lines = svndiff.split("\n")

    gitdiff = []
    for line in lines:
        if line.startswith("--- "):
            gitdiff.append("--- a/" + line[4:])
        elif line.startswith("+++ "):
            gitdiff.append("+++ b/" + line[4:])

    return '\n'.join(gitdiff)

def make_patch(authors, rev):
    out = commands.getoutput("svn log -c %s ." % rev)

    if len(out.split("\n")) < 2:
        print "skipping r%s" % rev

    patch = open(rev + ".patch", 'w')
    patch.write(svnlog_to_gitlog(authors, out))

    out = commands.getoutput("svn diff -c %s ." % rev)


    print "wrote %s.patch" % rev

def main(args):
    author_file = open(args[0])
    authors = {}

    print "loading authors"
    for line in author_file.readlines():
        parts = line.strip().split(", ")
        authors[parts[0]] = (parts[1], parts[2])


    revs = args[1:]

    if len(revs) == 1 and '-' in revs[0]:
        start, end = revs[0].split('-')
        start = int(start)
        end = int(end)
        revs = [str(x) for x in range(start, end + 1)]

    for rev in revs:
        make_patch(authors, rev)

if __name__ == "__main__":

Written by jbowes

June 23, 2009 at 6:29 am

Posted in SCM, tech

DIY Velcro Cable Ties

leave a comment »

Making your own velcro cable ties is a great idea. $2 in materials made as many cable ties as Wal-Mart was selling for $13. Thrifty!

I’d suggest sewing the velcro together vs stapling, especially if you have cats that are far too curious about staples.

Written by jbowes

October 20, 2008 at 8:15 am

Posted in life, tech

Tagged with , , ,

Perceptions of Toronto

with 2 comments

Growing up on the east coast of Canada, this is how I imagined Toronto to be, like, 24/7.

I’ve been here for nine months or so, and have yet to be invited to any trendy VICE parties. Just so you know, VICE, I am very willing to grow out some stubble and wear vintage clothing or an ironic t-shirt for the event.

Toronto is great though, even without the free Red Stripe.

Written by jbowes

June 4, 2008 at 5:17 pm

Posted in life

Tagged with , , ,


Get every new post delivered to your Inbox.