2010
03.08

A new semester, and some more hacking on the ‘dumpstream’ script. Now it is a little smarter because it can read the playlist file given by lectopia, and extract the rtsp stream URL from it:

#!/usr/bin/env bash

# Snip the URL from the playlist file
URL=`wget -q -O - $1 | grep rtsp | sed 's/.*src="\(.*\)".*/\1/'`

# Store the DATE from the file
DATE=`echo $URL | sed 's/.*iLectures.\{10\}\(.\{10\}\).*/\1/'`

# re-encode the file data, using the DATE as the name
`mencoder $URL -oac mp3lame -lameopts cbr:br=56 -ovc x264 -x264encopts bitrate=100 -rtsp-stream-over-tcp -o $DATE.avi`
2009
11.01

Lectopia is used by my university to publish recordings of lectures. Many of the lecturers make downloadable copies of the lectures available. Unfortunately, some lecturers only make streams of their lectures available. This sucks because skipping back and forth in a lecture is extremely slow, and unlike youtube or similar, if you want to skip back and re-watch a section of the lecture, that section has to be downloaded again – no caching. The streams are not capturable using standard utils – it isn’t possible to rip the stream directly using either vlc -demux=dump or mplayer -dumpstream.

eg. mplayer -dumpstream gives:

unsupported RTSP server. Server type is 'QTSS/6.0.2 (Build/526.2; Platform/MacOSX; Release/Mac OS X Server; )'.
...
Cannot dump this stream - no file descriptor available.

Instead, if you want to make a copy of the stream you must re-encode it. Fortunately, this is easy with mencoder. Below is a script I wrote, which takes a command line argument of the stream address and saves the file using the first 10 characters of the stream name – which is usually YYMMDDTTTT (year, month, day and time).

#!/usr/bin/env bash
DATE=`echo $1 | sed 's/.*iLectures.\{10\}\(.\{10\}\).*/\1/'`
`mencoder $1 -oac mp3lame -lameopts cbr:br=56 -ovc x264 -x264encopts bitrate=100 -rtsp-stream-over-tcp -o $DATE.avi`

The default video bitrate of 100 kbits/second is fine for “slides+voiceover” lecture recordings and results in ~1MB/minute filesize (with the audio bitrate of 56). You may want to use a higher video bitrate if you’ve got more action on-screen. I set up 6 instances of at the same time and yanked

Hopefully someone will find this useful.

2009
09.17

When I first started using Vim, I watched a fascinating talk given by the author, Bram Moolenaar, titled “7 Habits For Effective Text Editing 2.0” (click the link to see the presentation. It’s 80 minutes long so maybe grab a coffee first ;-) ). One of the ideas he talks about, and something which seems to be a pervasive philosophy of Vim, is the “Three basic steps”:

1. Detect inefficiency
2. Find a quicker way
3. Make it a habit

I think this is an excellent philosophy for computing in general – why do something repetitive yourself, when the computer can do it much more quickly and accurately? An obvious (and trivial) example is “search & replace”, which saves you from having to scroll through a file to find all the occurences of a string, then manually type in its replacement.

Since watching that talk, and as I got more familiar with Vim, I started “detecting” such inefficiencies everywhere; often in apps which are not nearly as flexible, which usually makes these inefficiencies more frustrating because they are harder to solve. I had one of these moments while browsing stackoverflow today.

Stackoverflow is a great resource, with lots of good information, however there is so much discussion that you could never read it all. That’s why every now and then I like to browse the Hottest Questions This Week, which does a pretty good job of distilling out the good stuff.

Now, I like to browse all those articles in full because it’s difficult to tell from the question whether or not it’s going to have one of those “gem” answers. So I started middle clicking all the links down the page to open them in new tabs as I normally do, when I suddenly realised how inefficient I was being. If only there was some kind of macro that could open all these links for me…

Well as it turns out, there’s an extension for that! It’s called Links Like This and does exactly what it sounds like it should. Just right click on a link, select “Open Links Like This…”, and all the similar links on the page are highlighted, with the option to open them all presented in a very slick interface. I’m not sure what heuristics it uses to determine which links are alike, but it does exactly what I want it to do: open all the “Hottest Questions This Week” in new tabs, saving me a full minute of my life and 48 mouse clicks. It even differentiates between visited links and unvisited links, so if I view the page twice in one week, it can open only those links that I haven’t visited! Awesome :D .

This illustrates to me a couple of things. Firstly, for repetitive computing tasks there is always an easier way. I wonder where else am I doing something manually which is more suited to some clever code?
And secondly, this is the power of open source software. Firefox’s value lies in it’s openness and the ease of writing extensions. There is no other browser which can compete with firefox’s features, because whenever someone sees an inefficiency or wants to add a feature, mozilla has made it simple for them to code a solution and share it with the world. I doubt very much that any other browser (especially a proprietary one like IE or Opera) would add support for a feature like this.

That’s also why I think KDE’s plasma is so important and exciting: it’s doing for the desktop just what firefox is doing for the web. Plasma widgets are really just “extensions” for your desktop, and you can code them in Javascript (just like a firefox extension), as well as Python, C, C++ and Ruby. Anyway, enough of a braindump. Back to work.

2009
09.04

git: simple!

I’ve been working on a project at home, using git for source control, and needed to make the project available from anywhere, so that I could work on it wherever I needed to. I have an ssh account at the university, so I decided I’d try setting up a git repo I could access through that. I was expecting it to be complicated and difficult, but in fact it was incredibly simple.

Google found these instructions, which I based my setup off; most of what’s below is quoted from that article, but I’ll put it here anyway for reference.

# login to remote server
ssh -l myUsername REMOTE_SERVER
# once logged in
mkdir /path/to/example.git
cd /path/to/example.git
git init

Note: the link above recommends

git --bare init

in the last line. using the –bare switch will create a repo without a working tree, which is great if you don’t need to work on the code on the machine where the repository is housed. However I need to work on the code on that machine too when I’m at uni.

Then, on my home machine I just run:

git remote add origin myUsername@REMOTE_SERVER:/path/to/example.git
git push origin master

The first command adds a the remote repository we just created and names it ‘origin’. The second command then pushes your ‘master’ branch to the remote repo.

And that’s it! You can now push/pull/clone from this repo to your heart’s content. For example after I work on the code at uni then want to work on it at home with those changes I just do:

git pull origin master

Simple!

2009
06.11

I’ve recently been teaching myself vim, and it’s amazing how much faster coding is already! Just moving around a document is so much more efficient when you don’t have to resort to a mouse.

I’ve been using the non-gui version of vim in konsole, partly because I can’t “cheat” with the mouse this way, and partly because it’s so much cooler having a “native” kde-style vim that fits in with font styles of the rest of my system automatically. ;)

Update: I should have guessed it was possible given vim’s flexibility, but enabling mouse support is as simple as:

set mouse=a

Still, I’m leaving it disabled for learning purposes. :)

Anyway, I’ve spent some time learning how vim and konsole can work together, so I thought I would document it somewhere.

First, how do you get cool gvim colour schemes working in konsole? Get CSApprox, a very clever little vim script that will translate a colour scheme designed for gvim, and approximate it in the 256 colours available to you in the konsole.

For vim + konsole, you also have to tell vim that it can use 256 colours (by default it only thinks it can use 8, thus colours won’t work properly). So add to your ~/.vimrc:

set t_Co=256

Then I found an awesome theme called darkspectrum, and now my vim experience really rocks.

Another advantage of konsole over gvim is that fullscreen vim is only a <ctrl> + <shift> + <f11> away. Sweet! :D