Saturday, November 17, 2007

Global Media Keyboard Shortcuts for Bongo

I am now currently on hour 9 of my current stay in the Electrical Engineering lab of Barus & Holley, and going a little insane. Luckily, I figured out a neat little trick that will make my media playing under Bongo that much more pleasant.

In Ubuntu, at least for me, the media keys on my Thinkpad T60 work great with Rhythmbox without any fancy configuration. This is great if I wanted to use that particular player, but I have bigger plans. I want Emacs to be my jukebox as well.

Unfortunately, those lovely keyboard shortcuts do not work with Bongo by default. Luckily, with the help of KeyTouch, I was able to get it working. KeyTouch is a fairly straightforward program, and there is plenty of additional info available here.

What I learned is that you have to disable the shortcuts you want to manage with KeyTouch in Ubuntu's System > Preferences > Keyboard Shortcuts since they will take precedence over anything you define in KeyTouch.

In KeyTouch, you will have a list of keys and their actions. Let's say we want to map the play/pause command for Bongo to the "Fn-Down" combination (this happens to be the play/pause key on my laptop). We can give KeyTouch a program to execute, but which one to do? We already have a running Emacs instance, so opening a new one would be just wrong. Whatever shall we do?

Enter EmacsClient. It's basic goal is to allow the environment to set it as $EDITOR variable and open files in an existing Emacs instance. One lovely thing about it is that it allows invocation of arbitrary elisp expressions as well.

Once you have it set up, you can use the following to pause the currently playing Bongo file:


emacsclient -e '(bongo-pause/resume)'

To pause or resume (shocker, I know). The elisp functions bongo-next and bongo-previous allow you to jump forward or back through your current playlist.

Now I have one less reason to ever leave trusty ole Emacs behind. Stay tuned for when I switch all of my email over from Gmail to Emacs!

Friday, November 16, 2007

Many TeXnicalities

So it has been a while since my last post. Life has been busy.

Specifically I spent most of last weekend dancing and all of this week working. Starting at about 3:00PM on Friday, November 9th and lasting until about 8:00PM on Sunday, I was doing some form of dance. It started with about an hour of Swing practice with Sarah for another showing of our Aladdin piece followed by the actual performance of it at 5. After that I had an hour of free time before Ballroom practice. You see, there was a competition Sunday, so every free moment I could find was spent meeting with partners.

After that, rather than take the smart route out and go to sleep, I made the long trek over to Machado for about three hours of... dancing.

Saturday was similar. I was meeting with ballroom partners up until it was time to prepare for the one and only SexPowerGod. While that may not have been purely dancing per se, it was most definitely tiring. After that, I had two hours to shower and change into something halfway respectable for the Brown Ballroom Competition for which I had to leave at 5:30AM. Being the largest single-day ballroom comp on the east coast, it went for a while and took the last bits of energy out of me until I could not even successfully point a video camera at stationary dancing couple.

My exhausting weekend aside, this post is about the glories of LaTeX. I picked it up sometime last year when CS22 suggested that all homework be done with it and have become so hooked on it that I almost wrote a $ before a mathematical equation in class today.

For those of you who don't know it, LaTeX is what you would turn to if you feel that word processing should be a subset of programming or feel the need to use Emacs for all aspects of their lives (I added music player to that list last night). Rather than pressing Ctrl-B to make text bold, you would write something like this:

\textbf{Bold text!}

The main point of this post is to gush over two related discoveries I recently made regarding LaTeX and Emacs. They are WhizzyTeX and Active-DVI.

WhizzyTeX is a minor mode for LaTeX editing in Emacs which opens an external viewer to mirror changes made to the source file in real time. So as you type, the dvi file gets update, AUTOMAGICALLY! For plain text this is not that big of a deal, but for complicated mathematical expressions or manipulation of parameters to get a look right, this cuts down on the edit-compile-review loop which can suck time away from creating masterful works. It also has the benefit of real-time error checking beyond what AucTeX already provides, so it can catch mismatched braces or unrecognized control sequences as you (mis-)type them. It is kind of like what I think flymake is like (I have never actually used flymake, so I don't know for sure). Finally, it has some fancy features which depend on Active-DVI (advi) like mouse-editing of LaTeX documents, such as dragging a control to size an hbox. Neat, but not often used.

Advi is like xdvi on steroids. It is a viewer as well as a document style for making snazzy presentations. Seriously, check out some of the stuff on the site. It can embed videos, launch external applications, and even embed those applications in the same window as the presentation, so you could potentially run Emacs within a dvi or even run advi within itself recursively! The possibilities are endless.

Unfortunately I have not had to make a presentation any time within the last couple years, so it is unlikely I will get to take advantage of all of that sweetness, but it is cool to know it's there.

My only gripe so far is that WhizzyTeX necessarily opens a new window for the preview. I have the screen real-estate, but it would be nice not to have to leave Emacs for anything (soon I'll have email in there as well). I did some searching for the possibility of embedding an X11 application within an emacs buffer (like how it displays pictures, but again on some fat 'roids). That way I could have advi sitting in an Emacs buffer and put that in a separate window from the source and have all of that wonderful interaction. I did some searching but was unable to find anything suggesting that this is possible. If anyone knows anything about it, please let me know. My X11 hacking skills are insufficient to just do it myself, so that's out.

Anyway, I'm off to TA CS31. Get more sleep than I did this week!

Tuesday, October 9, 2007

Join this Group to Save Facebook!

Newsflash: Petitions have exactly zero effect on the outcome of federal cases. Don't get me wrong, I love protest season as much as the next guy; I mean who wouldn't want to make a difference by holding a 8.5x11 piece of paper emblazoned with the words "save the pigeons" written in magic marker? It bothers me a bit when I get multiple invitations to groups which lack even a cursory Googling of the structure of the federal judicial system (hint: they aren't elected).

Also, when a company reaches a certain size, it gets sued. That's how litigation works. If there is even a minute chance that you could make a buck off of someone else's good fortune and hard work, you sue them. That's the American Way™. This is what will happen: the case will brew for a little while, the other guy will run out of money and give up, and nobody will remember that anything happened.

Saturday, September 15, 2007

I Want it that WAE

Whew! I just now finished my very first programming language, WAE. That's right, I wrote a parser and interpreter from (sort of) scratch. Unfortunately it has nothing to do with the Backstreet Boys.

The part I'm not telling you is that it's for CS 173: Programming Languages and that everyone in that class did the same, but it is still big.

Out of all of this I have realized that it is good to get started on work early so you can start your Friday night earlier than 12:30 or so you can eat sometime between 4PM and then. Honestly though, as CompSci projects go, this one was not that bad. It was only about 6 hours in total and only 400 lines of code, which pasted into a typical word processor would be about 10 pages single-spaced or about 19 double-spaced. Obviously this is comparing apples to oranges a bit since a good number of my lines are blank. On the other hand, code (especially scheme) is much more dense than most prose.

Anyway, this wonderful language is pretty simplistic compared with something that people would actually use, but seeing as I banged it out in one 6-hour session, it's not bad.

Here is a very brief overview of how it works:

The syntax is similar to Scheme/Lisp and uses prefix notation with curly braces {}. This is not by mistake. Scheme has the wonderful feature that it can tokenize parenthesized strings merely by adding a single quote to the beginning. So this:


'(a b c)

would return a list with the elements "a" "b" and "c". This is amazingly useful because it allows me to skip the entire step of scanning, which is a bitch. Seriously, I spent a good part of my summer fighting with Java over whether I could actually use if for scanning.

Normally, I would show a "Hello World," but since this language doesn't support strings, that won't happen. Like I said, simple language.

Instead, I will have it add 1 and 1. Behold:


{+ 1 1}

To most people this looks weird, but it has some nice advantages. First, it is very simple to parse; secondly, it makes nesting very trivial like so:


{+ 1 {+ 2 3}}


That means "add 1 to the sum of 2 and 3."

It even has scoped variables!


{with {{x 1}
{z x}
{x 2}
{y 3}
{w x}}
{+ 3 {+ {- z w} {+ y x}}}}


The result of which is 7. See if you can figure out why!

If you are really interested in this and other languages, I highly recommend CSCI1730 by Shriram. You can take a look at his book (for free!) here.

Now off to Joe's!

Wednesday, September 12, 2007

Universal Serial Numbers

No, this is not a post about cracks or keygens for some software. It is an idea I have had kicking around in my head for a bit that needed to get out. The motivation for this idea is best captured in story form.

At the dawn of time, Man had a scant few possessions. The idea of assigning numbers to these possessions was absurd for a couple of reasons:

  1. He wouldn't have gotten very far past 1: Rock. 2: Wife. 3: Shank of meat.
  2. Numbers weren't invented yet.

As time went on, Man began to add things to his list of possessions: sticks, bigger stones, and eventually land! For most of human history, there were few enough things that you could just kind of remember all of them.

But what happens when you have thousands of items for sale in the same store? Should the clerk simply memorize the price of each and every different kind of spiced ham and make a tally of how many of each kind he has sold? If that's how things worked, the apocalypse would have occurred about 30 seconds after the opening of the first Wal-Mart.

What happened is that some guy, who I can only assume was named Joseph Bar, invented the Bar code to shift the tedium of matching an item to a product description to computers. Since then a number of different bar code schemes have evolved.

The invention of barcodes has also led to such things as barcodepedia, which lets you look up any barcode of a common format.

But what of other products? Network interface devices have MAC addresses, cars have VINs, people have passport numbers, books have ISBNs and so on. Wouldn't it be nice if all of these different identifiers could coexist peacefully in the same database?

That's what I am proposing. A unique identifier for each and every thing on planet Earth.

In the words of Keanu Reeves: "Whoa."

This idea would need a lot of fleshing out, and gets complicated quickly. Let's take the example of books for the sake of argument. Each individual book has a universal serial number. It does not need any more identifying information than that, no ISBN, no barcode, no Library of Congress catalog card number. If you had a graphical scheme for encoding it like a barcode, that would be the end of the story as far as what's printed on it.

Things get messy when you try to do something useful with this. So you have your lovely sha1 (why not?) string and you want to find some stuff out about it. Well, it would be nice to know what the product is. So if you have a copy of The Bourne Ultimatum, and all that's on the book itself is its unique hash code, how do you figure out that it is actually Robert Ludlum's smash hit? Well, let's invent a relationship between USNs (Universal Serial Numbers). Your individual copy could be a "member of the product line $FOO." So we add that to our database, publish a website with all of that and run off fat and happy.

But wait! We now know that the USN 173a18cf0b9835a0a0c67808ca20bb82a4c20dc7 is an instance of the book The Bourne Ultimatum and we could certainly store some info about the authors and publishing company. But we wanted everything. So the book might be "authored by $BAR," "published by company $BAZ," "edited by $FOB," and so on. Now we have tons of kinds of relationships which all have to be recorded.

What if we wanted to take it further? Say I have my copy of the aforementioned book but it gets lost or (gasp!) stolen? If I record somewhere that the book 173a18cf0b9835a0a0c67808ca20bb82a4c20dc7 belongs to me, I could help someone return it or prove that it was mine in the first place.

Here we hit the problem of privacy. Others may be different, but I certainly would not like everyone on the Internet to know about all of my possessions. One possible solution is to have the database work in a distributed manner, similar to DNS. That way if you looked up 173a18cf0b9835a0a0c67808ca20bb82a4c20dc7 in the global database, it would point you to my server, which would have its own rules for deciding how much to reveal. Because the keyspace is so large, there is a low probability of sniping keys and figuring out what someone has. There is far more to consider here, but again, this is a very rough draft.

So there it is. A rough idea which, given an enormous amount of work, could define and organize the relationships between all identifiable objects known to man.

Including his rock, his wife, and his shank of meat.

Tuesday, August 14, 2007

My Public Projects

After recently having made the switch from Subversion to Git I created a GitWeb site of all of the projects of mine which can be publicly distributed (i.e. no homework or encryption keys).

Without further ado, here it is:

https://git.haxney.org

The https part is important, since it is hosted on a computer behind the evil veil of RCN's inbound port 80 filter. Note that I use a self-signed certificate, so you will have to accept that if you want to view my work.

Should you decide to check something out, you will need to tell git to ignore the self-signedness of my certificate with the following command:

$ GIT_SSL_NO_VERIFY=true git clone https://git.haxney.org/git/.git


To make git ignore the unverifiable certificate in the future, run

$ git config http.sslVerify false


This will tell git to ignore invalid certificates for this project. If you throw a "--global" between the "config" and "http.sslVerify", you can set this behavior for the current user. This may not be a good idea, but can save you hassle if you are pulling from a lot of self-signed repositories.

In which I Introduce this Blog

Welcome, loyal readers, to This Week in Hax. This is my personal blog and will include such wonderful topics as:
  • Goings on
  • Programming-related things
  • Shenanigans
  • Version Control Systems
  • Pretty pictures
So, as you may have guessed, I'm a geek. Luckily, I'm a geek who enjoys figuring out how to do various useful things so you don't have to, like connecting to a WPA2 Enterprise wireless router using Linux.

Stay tuned for more!