30 June 2008

flickr hack: how to remove the newfangled flash uploader using adblock

When you upload photos to flickr through there web interface, it will try to use their fancy flash file uploader. Personally, I prefer the "basic uploader," which is accessible from a link at the bottom of the uploader page.

Here's a quick hack on how to automatically use the basic uploader using adblock. The trick is this. First, flickr tries to insert the uploader flash object. If javascript on that page determines that it was not loaded, it will fall back to the basic uploader. If you use adblock to block the flash uploader, then you will automatically go to the basic uploader.

So, log in to flickr, go to the upload page, and then block the following url using adblock:

http://flickr.com/images/upload/yuploadcomponent.swf

Quick an easy, and hella useful

27 June 2008

An implementation of SHA-1 on the PIC16 F88

Here's an implementation of the SHA-1 message digest algorithm for the PIC16-family of 8-bit microcontrollers. I wrote it as part of a larger project (secret, until a soon-in-the-future date). I have verified it against several testcases of varying length (up to 1,000,000 characters), and it all seems to work well.

The code for this implementation is 520 instruction words, though a careful coder could chop it down by perhaps as much as 64 words. A more pressing issue is that it requires a lot of RAM--120 bytes, across two banks. For those unfamiliar with these microcontrollers, I give perspective by saing that the PIC16F88--a relatively big PIC16--has 368 bytes of RAM total.

When using the byte-oriented API, simulation shows that an average of 685 instructions cycles are required for each message byte, or reciprocally, about 7KB/sec throughput.

So, please enjoy the source code. It works fine with gpasm and gpsim, though I haven't tried it with the windows-only tools provided by microchip.

Gripe: Abusive rental agreements

Daya and I have recently been considering buying a house. Our logic has been that flipping a house in five years is favorable to renting. In actuality, the equity built over five years in this market is quite small, and (at least for us) renting would save us money. Oh well, I'm disappointed, but I'll get over it.

Having decided not to buy, we instead signed a lease. The last clause of this lease includes this very questionable clause (the bracketed words are my addition, for suspense):

17. The relationship of the [tenant] and the [landlord] shall be that of a guest and an innkeeper, respectively, and nothing herein shall be construed to give the [tenant] any additional rights including, but not limited to, those of a tenant under a residential lease. These parties specifically agree that this agreement does not establish a landlord/tenant relationship and is not governed by NJSA 2A18-61.1 [sic] or NJSA 2A:18-53, commonly known as the New Jersey eviction statute.

So who would write such a dastardly, evil clause into their leases? Princeton University. In the original, "[tenant]" was written as "student", and "[landlord]" was written as "university."

Despite this, the rental market in Princeton, NJ still somehow made this lease favorable; the graduate housing that Princeton will provide is at perhaps half the market rate. We signed. So what did we give up?

NJSA 2A:18-61.1 and NJSA 2A:18-53 limit the circumstances under which a tenant may be legally evicted. The limits laid out in law are mostly reasonable: one can be evicted if they fail to pay rent, if they are a terrorist (I'm not joking), etc. It also allows for the eviction of tenants convicted of drug crimes (questionable...), or if you refuse to pay an increased rent (very questionable...). Because my relationship to Princeton will be that of a guest and their inn, they can evict me not just for being a terrorist, but for whatever reason they wish at any time.

I understand that Princeton basically wants the right to evict me if I drop out of grad school, but still, this is wrong. I am so sick of being shat on by landlords.

17 June 2008

Hacking Firefox 3.0 -- Removing unused menu items

A co-worker convinced me to download Firefox 3.0 for Firefox download day, and I took the bait. So far, Firefox 3.0 seems really, really fast, but I haven't been using it for days yet. I'm going to try to be the first guy to release a cool hack for Firefox 3.0. Please play along here.

When I use Firefox, I've noticed that there are perhaps a dozen menu items that I never use. For instance, I never try to open a new window (instead, I use tabs); I never use any of the send link/page/image to variants, since I use gmail and haven't ever set up a email client within firefox. I never use the Work Offline button (I don't really know what it means).

Same thing with the right-click context menus. I don't right click a page to stop loading, instead I hit escape. I never copy image contents, set desktop background (in fact, my window manager is set up so that my background is a terminal window).

Most importantly of all, I never never never mean to hit the File -> Quit menu item; most likely I mean to hit File -> Close Window, which is inconveniently located in the middle of the menu. In terms of keystrokes, ALT-F down down down is much farther away than ALT-F up.

So, If I never use these menu items, why do I have to filter through them every time I use my web browser?

Well, now I don't, and the screenshot at left demonstrates the newer, smoother, less-crufty layout. Here's how you do it yourself:

It turns out that all of the user interface widgets in firefox are defined in a series of XUL files. By modifying these files, we can make our menu layouts match our personal use cases.

A moment of caution, however. XUL files are XML documents, and they are tightly coupled with other parts of the software. Who know how many calls times firefox calls document.getElementById() and doesn't check the return value. Don't risk it. Instead of removing items from this file, or even commenting them out, we're going to set the XUL hidden="true" attribute for undesirable menu items. Similarly, if you are moving elements, you may want to preserve the parent-child structure of the document, or you may break some XPath query hidden in firefox' gut.

It should also go without saying that you should backup every file you modify. Having said that, I'm not responsible for you.

Find your firefox installation directory. On my computer, this is /usr/local/bin/firefox; on windows, I would guess it's in C:\Program\ Files. Within this directory, you will find a subdirectory called chrome/, which contains a series of .jar files. Our target is browser.jar.

Copy browser.jar to browser.jar-old right now, before you forget. Oh yeah, close firefox.

Now copy browser.jar to a temporary directory, and unzip it with whatever tool you use. If you have trouble with this step, rename it to browser.zip, and unzip that.

You should see a directory called content/browser/, and in this directory, a series of .xul files. We are interested in content/browser/browser.xul. Open it up with vi, and look at it until you understand how it works.

For our purposes, you only need to understand the meaning of a new elements.

  • < popupmenuset > - here, popup refers to popup menu. The main popup set is the main menu bar used in firefox, and it contains the File, Edit, View, etc menus.
  • < menupopup > - this can refer to a popup menu (such as the File Menu) or to a context menu (like when you right-click on the page).
  • < menuitem > - this refers to a menu entry, such as Open under the File Menu.
So, to remove an unwanted menu item, first find the offending item, and then add the attribute hidden="true".

And to re-order misplaced menu items, re-order the elements.

When you are done yicking with the innards, re-zip the entire directory tree into an archive called browser.jar, and put it where you found the original. Start firefox, and see how you did.

If you get weird behavior, re-examine your modifications or revert to the original file. Lather, rinse, repeat. Enjoy.

And while we're on the topic, let me throw-in a few about:config tweaks that I find completely necessary for Firefox 3. I got most of these from LifeHacker.
  • dom.disable_window_open_feature.menubar, dom.disable_window_move_resize, dom.disable_window_move_resize, dom.disable_window_move_resize, dom.disable_window_move_resize, dom.disable_window_open_feature.titlebar, dom.disable_window_open_feature.titlebar must all be set to false to avoid annoying behavior;
  • browser.tabs.closeButtons = 2, to put the close tab button on the right, not on each tab (like firefox 1.5);
  • browser.backspace_action = 0, so that backspace is equivalent to the Back button;
  • browser.chrome.toolbar_tips = false, to hide tool-tips; and,
  • browser.tabs.tabMinWidth = 75, so it will show more tabs before scrolling them.