My Mac OS X Terminal

So I’ve been doing development on my Mac. The main reason is that I love Mac’s font rendering and the monaco font, it makes programming really enjoyable. Plus I love TextMate and I also use Xcode and Interface Builder for iPhone development. Anyways, as a result I have been using git, which is basically recently popular distributed version control system. I bought hosting at Github to store all of my private source code.

Today I received the Crucial 4GBs of DDR3 RAM (2 sticks in Dual Channel) that I ordered cause my MacBook was crawling when I ran all of my development tools that I absolutely needed. Really, I only had like 145 MB left with all of my dev tools running, and I was idling; not actually working on anything. I believe part of the reason it uses much RAM is cause the video is integrated (Geforce 9400M). Anyways, after installing it, my system is silky smooth. I can actually do stuff now :D

So yeah I’ve been using the terminal a lot (I love the Mac terminal by the way, it’s really nice). The default prompt is pretty boring though, it’s just like macbook:blaenk ~ $ or something. I changed it to be a bit more helpful and colorized certain parts to make the distinct parts stand out. I also created a theme for my terminal which kind of resembles my custom TextMate theme as well. Here’s what it looks like right now:

My Mac OS X Terminal

The Git Manual

If you would like to try out the prompt I’m using, check out this gist:

As for my actual Terminal theme, you can get it here. It’s just an XML file really. Put it somewhere in your file system (Wherever you want, home directory for all I care) and then go to your Terminal.app’s Preferences. In the settings tab, go to the bottom left and click the gear and click Import…, then browse for the .terminal file. It should import the theme, it’s creatively called Blaenk, but you can change that of course.

It’s nothing breath taking, but I figured I’d share it.

Ubiquity Search Script

I wanted to practice my Javascript and I liked the idea of Ubiquity, so I decided to write some search commands for it. Ubiquity already has a utility function to create them, makeSearchCommand, but it’s too limiting. For example, if I do not provide a search query argument, it still takes me to the results page, when in fact it should take me to the home page of the site I’m searching, like Open Search Plugins do. A kind person in #ubiquity in the Mozilla IRC servers filed a ticket saying that makeSearchCommand should allow this behavior. In the mean time, I created some utility functions which would make it simple to create a search command that would do this, but for this I had to use CmdUtils.CreateCommand. But since I wanted to create many of these search commands, I came up with a way to make the creation of these commands a simple function call.

Aside from this, I wanted to make it so that anyone could easily add their own search commands by only providing three necessary pieces of information: the site’s readable name, the command that should be used for it, and the template search URL with {QUERY} as a place holder for the actual query, to mimic makeSearchCommand’s functionality in this aspect. This information is stored in an array of JSON objects which are iterated through and a search command created for each. I also made it possible to automatically find the site’s favicon to use as the command’s icon which adds a nice little touch.

I’m actually really new to Javascript, this is the first thing I write in Javascript from scratch (Other things I’ve done are just little changes to existing scripts), so I am pretty sure it can be done better, but for a first timer I believe I came up with a nice little way to create search commands.

Source

The source is available as a gist on Github. This allows for simple version controlling without providing a completely dedicated repository which would be overkill. The included sites are unnecessary as there are already Ubiquity search commands for them pre-installed when you install Ubiquity. They are simply there to provide you an example and sense of structure.

Installation

First of all, you will of course want to have the Ubiquity extension installed for Firefox. Then you should go to the Command Editor (Right click on the link, copy link location, then paste it into the address bar in a new tab). Once there, paste the script source into the big text box, and change/add/remove any of the sites you want, it should be pretty straightforward. You can test the script on the fly without having to save it or anything by triggering Ubiquity and typing the command names. If the command doesn’t show up or work, it is most likely because you ‘broke’ it, most likely a syntax error (Don’t forget the commas). You can check for any errors by going to Tools > Error Console in the Firefox menu. Once you’re done, you should click on the button on the top right that says Save to File, and it will save the script and subscribe you to it.

Usage

Simply trigger Ubiquity with your shortcut (Option+Space on the Mac, by default), and then type the command you specified. It might not show an icon right away because it is being downloaded. After a few uses though, the icon should show up.

Using the search commands is easy. You can type in your command followed by a search query, that is the default behavior. If you type the command and execute it without a search query, it takes you directly to the site. If you have text highlighted/selected, and you execute the command, it will use the selected text as the search query. Finally, if you have text selected but you do not want to use the selected text as the search query, you can type the command followed by go to go directly to the site. By “directly to the site”, I mean that if your search command is for google for example, it will take you to http://www.google.com (The root of the site), just like Open Search Plugins do.

Removal

To ‘unsubscribe’ from the script, simply go to the Ubiquity Main Page and on the bottom right you will see a column under a header that says Subscribed Feeds. Find your script there and simply click Unsubscribe.

Recursive Pascal’s Triangle in Ruby

So while practicing Ruby, I decided to translate my previously posted Java code that prints out the numbers of the specified row from Pascal’s Triangle, into Ruby. This was easy, but the whole point was to then refactor it to make use of all the neat little Ruby tricks that the language has. After some examining and help from someone in the #ruby channel in freenode, I came up with this. It is a lot easier to read and shorter. I was told that in Ruby it could be done iteratively and would be better, but like I said, my goal was to implement all the neat Ruby tricks, not enhance the algorithm. Here it is:

How To Stream ABC Shows on Windows 7

I’m not a big fan of most networks’ streaming players. Usually they make you download random extensions/plugins and make you jump through hoops just to get the stuff streaming. I’m looking forward to the day when most shows are available on Hulu or YouTube. Anyways, recently I felt like starting to watch Lost and so the first thing I did was check if I could stream them online. To my dismay they were not available on Hulu but ABC did have their own streamer at the ABC Go site. I quickly loaded it up on my MacBook and it right away asked me to install a ‘plugin’ (Not an extension). I did this and without having to restart Firefox I was able to start watching Lost. I chose Standard Definition because I wanted to be sure not to run into any hiccups while streaming. The player shows 30 second commercials every once in a while (Not too many to become annoying) and I could live with that, no big deal for me. Anyways, after a few minutes I decide to hit the full screen button, bracing myself for the amounts of pixelation that would make the show unwatchable. Right after hitting the full screen button, however, it immediately seemed to switch to HD quality with no interruption at all, not one bit of lag. The HD quality was surprisingly nice, I’m not HD virtuoso but I’d say it had to be at least 480p, but on my 1280×800 MacBook screen it looked like 720p. So anyways, yeah, lately I’ve been watching Lost on my MacBook at a very nice quality with no lag whatsoever, I’m really surprised and glad.

Right now I am on my computer with Windows 7 RC 64-bit installed running Firefox 3 beta 4. I decided I should watch some Lost for a bit and I was shocked to realize that they had some sort of OS detection script running. I got a message saying something along the lines of “Only Windows XP/Vista and Mac are supported”.  Right away I figured that this should be fixable with a quick User Agent String ‘hack’. After all, most programs run fine on Windows 7, even if they are aimed at Vista they run perfectly fun on Windows 7.

Edit: David, from the comments, posted that you can easily avoid having to do this by simply installing the plugin by going to the plugin’s home page. ABC seems to do a check to make sure that the OS is ‘correct’ before allowing you to install the plugin, but once you have the plugin installed (Either by installing it directly or fooling ABC into thinking you have the ‘correct OS), it won’t care what platform you are on. Thanks David, for the URL!

Alright I’ll shut up with the commentary now and get right down to it. You will need to get the User Agent Switcher extension. Next you will have to find a User Agent String that is closest to your setup and has Vista as the Operating System. You can look at this list if you really want to spend some time and find one that suits you, or you could trust me and use the one I found; keep in mind that this one has the browser set as Firefox 3.5 beta 4, though that shouldn’t really matter as long as you’re running at least 3.0. Next what you will want to do is copy the actual User Agent String into your clipboard, it’s the text in the textbox at the top:

Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.1b4) Gecko/20090423 Firefox/3.5b4 (.NET CLR 3.5.30729)

Now you should go to Tools > User Agent Switcher > Options > Options… On the left sidebar click on User Agents and then click on Add… In the little dialog window that comes up, type in a description into the description box, something like “Firefox Vista”. Next, paste the User Agent String into the User Agent box, then click OK. Now close the options window and go back to Tools > User Agent Switcher and choose Firefox Vista, or whatever you put as the description for the User Agent. Now Refresh the ABC Go player page (I recommend CTRL+F5 to clear the cache for that page, though I doubt it’s necessary). Now click on the big button to open up the player (Which will appear in a pop-up window, so if you don’t see it it’s cause it’s being blocked) and it should no longer whine about using an advanced Operating System. It will ask you to install an extension (Unfortunately, but it’s not a big deal in my opinion) and then restart once it’s installed. Once restarted, your User Agent should automatically be switched back to the default, and you no longer need to go and switch it each time you want to load the player (At least from what I’ve noticed), it seems like it just does the check if you do not have the extension installed yet.

Anyways, there you have it. You should now be able to stream ABC shows on Windows 7 in Firefox. The reason you cannot use the pre-defined Internet Explorer 7 (Windows Vista) that comes with the User Agent Switcher extension is because the requirements for IE7 and Firefox are different. In Firefox, you install an extension, in IE7, you bash your head into the wall for running IE (No really, I guess you would download a setup file and install it directly to your system or some ugly stuff like that). Hope that helps, and by the way, this type of ‘fix’/'hack’ usually works with all other similar problems where the site detects that you are not running on an operating system or browser that they want (Though when it’s just the browser then it usually doesn’t work).