Monday, December 17, 2012

Using a Wiimote in Mupen64plus

After much head-wall-banging, I got a Wiimote to pair successfully with my computer and work as a controller in Mupen64plus! There was a lot of trial and error, so I've created a guide to getting a working setup so future generations don't have to go through what I did. The details are in this git repo, which includes detailed instructions and config files.

Wednesday, December 12, 2012

Trying an Android ROM

Against my better judgment, I am going to take another shot at installing a ROM on my phone. The battery life could use some improvement, and people have claimed that some of the 3rd-party ROMs can help with that. I know I have promised myself not to play with ROMs on my phone again, since the result is usually a big waste of time with nothing to show for it, but this time is different.

Brace yourselves for a follow-up in which I immediately regret this decision.

Tuesday, December 11, 2012

Another Ubuntu update, another b0rked system


I updated to 12.10, and Alt+middle-click to resize windows was broken. After about an hour of circular Googling, I found the correct incantation to sprinkle. For some strange reason, the setting org.gnome.desktop.wm.preferences.resize-with-right-button was set to true. Set it back to false and the system returns to its former functioning state.

Sunday, November 18, 2012

Better than "Understanding OOP"

I came across a page talking about the joys of OOP via this blog post. The original page was a thing of horror. I modified the Elisp code from Irreal, adding a few additional features:

In addition to equality matches, it can match using regexps and arbitrary functions. Let's see Java do that in 20 SLOC.

Saturday, September 29, 2012

Voting third party and government job "creation"

This is copy of an email I sent to my dad just now.

My concern about the libertarian candidate, besides the fact that he cannot win,

That's no reason not to vote for him. A well-functioning democracy requires a choice of more than the people who are "obviously" going to win. Otherwise, it isn't democracy so much as a decree by the political parties who will be the next president.

My is that his economic plans are hopelessly naive. He pretends that, given Congressional cooperation, one could dramatically cut spending in 2013.

Again, for democracy to work, you need people who are going to do more than what will easily pass.

My The prospect of a much smaller cut is labeled the fiscal cliff and would send us into recession.

I'm not so sure it would be quite that bad. It strains credulity for a trillion-dollar increase in federal spending to be little more than an academic nuisance, but a symmetric decrease to bring about the apocalypse.

I might love to see federal spending go down to 15% of GDP, but if that happened in one day we would have a depression that would make the 1930's look like the good old days.

It just seems weird that spending can shoot up by an enormous margin in one year, but for it to drop by the exact same amount would throw the country into ruin. As a counter-example, I would point to the demobilization following WWII. Government spending fell through the floor, yet the economy boomed, even as it had to absorb the mass of people coming home from the war.

Since Obama will carry MA by a landslide, I want the message of my protest vote to be unambiguous. Voting for Romney says my concern is economic. Voting for a fringe candidate could mean anything.

Well, the fringe candidate has a much clearer message: that neither of the two parties offer particularly attractive directions for the country and that both parties are to blame for the mess we're in.

Besides, whether you vote Democrat, Republican, Libertarian, Green, Wizard, or not at all doesn't make a measurable difference in the outcome of the election, so you might as well vote for your highest preference. See the paradox of voting.

Since you personally are never going to be the tiebreaker, vote for the person who most closely matches your preferences. But what if everyone thought that way? They don't. You are not a collective. And your choice of candidate does not effect a change in other people's voting behavior.

As long as the Republicans hold the House we may stave of the Spanish food riots here. I have great sympathy for them, but they are still thinking there is the alternative of just spending more of that free money.

Incidentally, this is one of the reasons I am in favor of a smaller role for government: there's no one to whom to complain when things don't go your way. People riot against the government in the hopes that the bureaucrats will deign to bestow to each according to his need. Against whom do I riot if the ending of Mass Effect 3 is a major letdown? I can raise money for charity in protest of the botched opportunity, or send ending-related colored cupcakes to the developer's offices (both of which people did), but that's about it. The most impactful thing I can do is refuse to buy their products in the future, since I possess all of the power in that relationship. I bear the burdens and benefits of my actions.

When the target of protest is the government, on the other hand, I can lobby or attempt to vote myself a job and cash. Politicians can try to sell me a free lunch, and since my vote is infinitesimal, which way I vote doesn't have any personal ramifications. It is quite understandable that the Spanish and Greeks want jobs, but when the government is seen to be the solution to unemployment, the focus changes from job creation to job bestowment.

Thursday, September 20, 2012

Change GTK keybindings from Emacs back to default

Like any virtuous person, I use Emacs for everything, and so tried out using Emacs key bindings for all GTK applications generally. After a year or so of working like this, I have decided to go back. The main problem is that other applications can't handle the awesome power of Emacs. Firefox, for example, uses C-k to jump to the search box, but if you are in the location bar, C-k will run the equivalent of kill-line which means that in order to get to the search bar, you have to remove focus from the location bar. Not convenient.

Since I do all serious typing within Emacs anyway (using the It's All Text! addon to edit textareas in Emacs), I figured I might as well take full advantage of the standard key bindings of the lesser programs.

A lot of the guides online talk about editing .gtkrc-2.0 or setting /desktop/gnome/interface/gtk_key_theme through Gconf, but this has ceased to work under Gnome/GTK 3. To fix it, you need to set the value through gsettings (which uses dconf>) rather than gconf:

$ gsettings reset org.gnome.desktop.interface gtk-key-theme

Why would they break backwards compatibility? Who knows. Also, due to the brilliance of the Gnome 3 developers, the data for dconf is stored in some opaque binary blob, rather than the straightforward XML files used by gconf. This is a huge step backwards from the Unix philosophy for what appears to be no change in functionality.

It's things like this, along with brain-dead vomit that is Gnome Shell (or Unity), that have convinced me that all of the Linux desktop developers have simultaneously taken crazy pills and have gone insane. Why else break perfectly good code and interfaces in favor of less functional and less useful crap?

Thursday, September 6, 2012

Those Dumb Pipes

This is an older idea which had been floating around in my head, half-finished for a few years.

I was inspired by this Ars Technica article to think about the relationship between network operators — both cellular and landline — and consumers. The key quote from the article is by "one mobile operator" and is:

Some people like 3 may be in a position where it could make sense to accept that. But if you spend upwards of £40m per year building your brand, you don't want to be just a dumb pipe do you?

This is the fundamental tension between consumers and network operators: one wants internet access to be a commodity, the other doesn't. Why should I care about their brand? Electricity or water utilities don't have a brand. In most (all?) cases, they are government-granted monopolies, so there isn't any choice, but still, the only time I think about a water or electric company is once a month when the bill comes due. The only thing in the world I want from those companies is that when I plug in a lamp or turn the faucet, electricity or water comes out, (hopefully!) respectively. I want the same to be true of ISPs. It annoys me that the word "Verizon" is printed on back of my phone; we would think it bizarre if refrigerators had "National Grid" printed on the doors.

Luckily, we have been moving in this direction since the article was written. The incredible explosion of smartphones has put huge competitive pressure on text messaging, to the point where basically all plans have unlimited voice time and text messages, removing that significant avenue of differentiation. There's less and less room for the networks to do much of anything aside from providing a pipe to the public internet. Despite the fears of Network Neutrality advocates (of which I was formerly one) and a lack of legislative action, no traffic discrimination has taken place. Gradually, the carriers are being ground down into commodities, forced to compete only on quality, coverage, and price, and having their profit margins squeezed ever tighter.

We live in glorious times.

Thursday, August 2, 2012

Correctly Dispatching on Generic Methods in `*apply()` in R

I've been hacking in R recently for work, and it is a bizarrely amazing
language. I just ran into a situation in which I needed to apply an S3 generic
function to a list (actually, a row-wise iterator on a data.frame)
and hit an annoying rough patch

For those not as well-versed in R (I've been learning it for about two weeks at
this point), "method dispatch" is done in a quirky yet effective way. You define
a generic function, say foo like this:

Which means "when foo() is called, dispatch to the function
matching the class of bar". Setting the class and calling the
generic method is simply:

Calling foo(bar) causes R to look for a function named
foo.myClass and calls that. If foo.myClass is not
defined, it will try to call foo.otherClass, then
foo.default and if none of those functions exist, it will throw an

You might have noticed that UseMethod("foo") doesn't pass along the
arguments to foo. R passes the arguments along automagically.

If you want to apply a function to each element to a list, R makes it easy:

identity() and identical() do what you would expect.
There are a bunch of variants of apply; RTFM for the details.

Now let's say we want to call foo() within lapply()
rather than identity. There are some complications:

This throws an error because UseMethod() tries to dispatch on the
class of its first argument, which is a string
("character", in R parlance). One way to make this work is to
reverse the order of the arguments so the iteration variable comes first and
force UseMethod() to dispatch on a different argument:

Yuck! Wouldn't it be great if there was an easier way? Preferably one which
doesn't involve hacking R's method dispatch system? Well luckily, there is. We
take advantage of the fact that R can use named arguments:

It's a bit wonky when coming from normal languages, which wouldn't appreciate a
named argument being assigned to a variable earlier in its argument
list. Again, R is amazingly bizarre and bizarrely amazing. The explicit naming
of quux causes it to be "used up" from the argument list, so that
any remaining arguments are assigned to the "unclaimed" variables. Taking
advantage of this feature of R lets you apply a generic function to a list (or
other iterable R objects) without having to mess around with its
method-dispatching system.

Hopefully this spares a fellow hacker the pain of digging through R's
documentation on method dispatch.

Thursday, July 5, 2012

Listing available monospace fonts in Emacs

After finding out that the Monospace font doesn't support italics, I set about trying to find a suitable replacement. This EmacsWiki page lists a way to print some example text in all of the fonts on the system, which is very helpful for comparing what's available. The problem with it is that it displays all fonts, not just the monospace fonts, which isn't useful. (For those of you not in the know, all programming is done with monospace or uniform-width fonts, meaning that l and m are the same size).

I modified the code so that it displays only monospace fonts. There's probably a property on the font family which one could check, but I used a much more primitive method: measure the pixel width of 5 consecutive lowercase L characters and 5 lowercase M characters. If they are the same, then the font is monospaced.

It isn't perfect (it has a couple of false positives, such as courier 10 pitch), but it's close enough to be a big improvement.

Tuesday, June 19, 2012

Use FileMaker Web Publishing in Apache

I've been tasked with nice-ifying the configuration and setup of the systems at work. They store a huge amount (244 GiB) of protein analysis data in a FileMaker database and have PHP scripts accessing the data through the FileMaker XML HTTP API. The problem is that the PHP scripts are running on Apache (as is an SVN repo), but FileMaker wants to publish its API only through IIS. Having spent more than a minute wrestling with configuring IIS, I want it out of my life ASAP. But that can't be done unless scripts have a way of talking XML to FileMaker on port 80. All hope seemed lost.

Monday, June 18, 2012

When European "Austerity" Isn't

I've been skeptical of the rhetoric that there has been "brutal, crushing austerity" in Europe. When these claims are made, I have seldom heard any quantification of how brutal these "brutal" changes have been. So I looked it up.

Short version: there's been minimal to negative austerity since pre-meltdown 2008.

Longer version:

Friday, June 8, 2012

Solving mod_dav_svn loading faliure on Apache in Windows

Yesterday, I spent way too much time trying to get Subversion working under Apache in Windows 7. I really have a new appreciation for GNU/Linux package managers; what would have been sudo aptitude install libapache2-svn under Ubuntu turned into hours of staring at Syntax error on line 270 of C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/httpd.conf: Cannot load C:/Program Files (x86)/Apache Software Foundation/Apache2.2/modules/ into server: The specified procedure could not be found.

I tried copying all of the SVN libraries into bin within the server root, downloading different versions from the web, and "unblocking" the libraries (Windows blocks code downloaded from the internet. Nice idea; I only wish it would tell you about it). Finally, after hours of Googling, I found some post on some forum somewhere that mentioned using the libapr-1.dll from the Subversion distribution rather than Apache's would help. It did.

This would seem to undermine somewhat the idea of the "Apache Portable Runtime". But whatever; I have a working system. Now onto trying to get LDAP set up for SVN and Ubuntu. Wish me luck!

TL;DR: If Apache in Windows fails to start with loaded in your conf/httpd.conf and you get this error in your Event Viewer: Syntax error on line 270 of C:/Program Files (x86)/Apache Software Foundation/Apache2.2/conf/httpd.conf: Cannot load C:/Program Files (x86)/Apache Software Foundation/Apache2.2/modules/ into server: The specified procedure could not be found., you can solve it by copying libapr-1.dll from Subversion/bin to Apache2.2/bin, replacing the version which ships with Apache.

Tuesday, June 5, 2012

Metaphor for Europe's Troubles

Based on my decades of experience in the sovereign debt markets, I have come up with a perfect metaphor for what is going on in the Eurozone. It is as if the Grace government promised 200,000 people one boat each, but now that the boats are due, it turns out that she doesn't have 200,000 boats anywhere, there are only 100,000. Grace tries telling half of the people not to try to use their boat; to pretend that it is sitting in a port somewhere, waiting for them. If some people use their boat half of the week, other people can use it for the other half of the week, so it is "like" having 200,000 boats. Uncle Jeremy has 1.5 million boats, but he isn't so thrilled about just handing over a bunch of his boats to Grace, who knew she promised more than she had. Jeremy says "I'll give you 50,000 of my boats, but only if you tell 50,000 people that they aren't getting a boat at all." Grace is furious, shouting "you're forcing boat austerity on me! I need to implement boat-growth policies!" Of course, "boat-growth policies" is a euphemism for "Jeremy gives me more boats."

Grace then proposes a consolidated "Euroboat" concept, in which all of Grace's, Jeremy's, Ira's, Talia's, and Pete's boats are lumped together and then given out to each of their citizens, regardless of how many boats each person (government) has. It just so happens that Jeremy has 1.5 million boats and has promised 750k of his citizens one boat each, but all of the other governments have promised more boats than they have, and have even promised more than the 750k spare boats that Jeremy has. Jeremy, understandably, doesn't want to give out all of the spare boats he has to people who promised more than they had, but when he tells the other people this, they get angry and call him mean names. Jeremy tries to explain that even if he was to give out all of the extra boats he has, and cut back on a bunch of the boats he already promised to his citizens, there would still not be enough boats for all the people who promised more boats than they knew they had.

Some people want their acquaintance Mario to print them a bunch of boats.

Friday, June 1, 2012

EA support is wonderful

I contacted EA support today to get my reward for participating in last weekend's Mass Effect 3 Bounty Weekend: Operation Shieldwall. I achieved the individual goal, but didn't get the priiiize, so I went to EA for help. Maybe 10 minutes later, it was done. Thank you to "Larry S" for helping me. Here is the log of my chat with him; I want to give credit where credit is due for his professionalism and speed.

Sunday, April 22, 2012

Simple recursive file traversal in Elisp

Really quick: I wrote a simple bit of elisp to eval a body over each of the files in a directory, recursively. Looking around for a little bit, I found a couple of options, including Findr, which has its own queue implementation (pretty short), and whose main function is a whopping 55 lines!

There has to be a quicker way, I thought. I didn't need anything terribly fancy, I just wanted something that worked cross-platform (which ruled out find) and was simple. I ended up with this little guy:

11 lines for the main function, recursive-files itself, and another 3 (including docstring) for simplifying macro. It's main weakness at this point is that it incorrectly ignores any files with leading dots. So not only does it (wisely) avoid . and .., it rather foolishly avoids .foo as well. I couldn't easily figure out how to exclude . and .. in a single regex easily without also excluding leading-dot files. For what I'm doing, it's not important.

Also, note that this barfs on symlinks. It thinks they're directories and tries to call directory-files-and-attributes on them. Again, a more careful implementation would deal with this.

I was surprised that Emacs didn't have a "recursively visit files" function or macro built in, but this gets me close enough. Enjoy!

Monday, February 27, 2012

The Ongoing Saga of Making Ubuntu 11.10 Usable

Alright, I installed Ubuntu 11.10 (aka "lost all common sense" edition) on a new computer, so I have the memory of trying to make it bearable still in my head. The absolute necessary first thing to do is:

And set your login session to "Gnome fallback". This gives you a passable facsimile of Gnome 2 (aka "worked and was not useless" edition). I am a little... offended is to strong, but miffed that "fallback" means "what to use if you want to get work done and are not, in fact, a hipster," but whatever.

Wednesday, February 15, 2012

Set ordering in Python: why I didn't sleep last night

In yesterday's class of the Python-infused Linear Algebra course I'm taking, a fellow student noted the strange ordering of items in a set when printed. It seemed that the printed order of the set items always swapped the first two items, but left the rest unchanged. I don't know what sets he tried, but I was interested in the general behavior, and so began my quest through the Python source code...