Tuesday
May242011

triggerGreppy

For the longest time, I have been meaning to brush up on Python. Unfortunately, * I haven't had much need for scripts lately. * When I have needed a script, I've needed it pronto! No time to learn a new language.

The problem is I'm lazy and I don't really want to read a book or website on it. I just want to solve some little problem I might have that needed scripting. You know, just take a sample script and play with it to do something useful to me.

So... after lamenting about this, my friend Mike sent me a sample python script to play with. The sample code he sent me was basically a simple grep clone.

Aha!

I have always wanted a grep-like tool that gave me more context. I know that you can tell grep itself to provide more context, but as far as I know, you can only specify the number of lines before and after your match you want included. This is realistically all one might need for most cases, but I wanted more.

So that is what me new script does. (You can find a copy of my script here) You provide three search terms:

  • trigger: the main term you are looking for.
  • begin: something pattern that describes the beginning of the block you want to print out.
  • end: The end pattern for the block.

For example: I exported an xml file from my iTunes library that describes all of my media. I can now search for the name of an author for example and get The full dictionary entry for the song. (output listed below.)

I hope this is useful to some one else or at least serves as a starting point for your own exploration of python.

% triggerGreppy Tacuba "<dict>" "</dict>" Library.xml

    <dict>
        <key>Track ID</key><integer>7587</integer>
        <key>Name</key><string>Bar Tacuba</string>
        <key>Artist</key><string>Café Tacuba</string>
        <key>Album Artist</key><string>Café Tacuba</string>
        <key>Album</key><string>Café Tacuba</string>
        <key>Genre</key><string>Alternativo &#38; Rock Latino</string>
        <key>Kind</key><string>MPEG audio file</string>
        <key>Size</key><integer>4703278</integer>
        <key>Total Time</key><integer>233221</integer>
        <key>Track Number</key><integer>13</integer>
        <key>Year</key><integer>1992</integer>
        <key>Date Modified</key><date>2010-09-27T20:44:49Z</date>
        <key>Date Added</key><date>2010-08-03T04:30:10Z</date>
        <key>Bit Rate</key><integer>160</integer>
        <key>Sample Rate</key><integer>44100</integer>
        <key>Normalization</key><integer>2381</integer>
        <key>Artwork Count</key><integer>1</integer>
        <key>Persistent ID</key><string>E467DC7506CA7184</string>
        <key>Track Type</key><string>File</string>
        <key>Location</key><string>file://localhost/Volumes/Attic/Music/iTunes/iTunes%20Music/Cafe%CC%81%20Tacuba/Cafe%CC%81%20Tacuba/13%20Bar%20Tacuba.mp3</string>
        <key>File Folder Count</key><integer>4</integer>
        <key>Library Folder Count</key><integer>1</integer>
    </dict>

---------------------
    <dict>
        <key>Track ID</key><integer>7753</integer>
        <key>Name</key><string>Las Flores- Cafe Tacuba</string>
        <key>Artist</key><string>Various Artists</string>
        <key>Album</key><string>Hace Calor  Pop &#38; Rock</string>
        <key>Genre</key><string>General Rock</string>
        <key>Kind</key><string>MPEG audio file</string>
        <key>Size</key><integer>2752097</integer>
        <key>Total Time</key><integer>136881</integer>
        <key>Track Number</key><integer>3</integer>
        <key>Date Modified</key><date>2010-08-19T05:00:31Z</date>
        <key>Date Added</key><date>2010-08-19T04:58:27Z</date>
        <key>Bit Rate</key><integer>160</integer>
        <key>Sample Rate</key><integer>44100</integer>
        <key>Play Count</key><integer>1</integer>
        <key>Play Date</key><integer>3370023481</integer>
        <key>Play Date UTC</key><date>2010-10-16T01:38:01Z</date>
        <key>Normalization</key><integer>2518</integer>
        <key>Persistent ID</key><string>52FAE1944A13F3EE</string>
        <key>Track Type</key><string>File</string>
        <key>Location</key><string>file://localhost/Volumes/Attic/Music/iTunes/iTunes%20Music/Various%20Artists/Hace%20Calor%20%20Pop%20&#38;%20Rock/03%20Las%20Flores-%20Cafe%20Tacuba.mp3</string>
        <key>File Folder Count</key><integer>4</integer>
        <key>Library Folder Count</key><integer>1</integer>
    </dict>

---------------------

[I removed furthere matches for brevity]
Sunday
May012011

Sharing Git Branches Remotely

I usually have two branches when working on a project with a team. The master branch tracks origin/master, and I do most of my work on my local development branch.

Every now and then, I work an experimental feature. When I start on it, I'm not sure if it will work out and wether or not it should make it into the master branch someday. In those cases, I will make a new local branch to play with the idea. Lets say I called it superCoolFeature. At some point of the development of this feature, I might need to share this branch with one of my team members. How do do I do that?

Well... I just figured that out recently and I thought I'd post it here in order to remember it the next time I need it.

It turns out to be a two step process. First you need to push your local branch onto your remote (usually your remote is origin, but you can type git remote to see a list of remotes.) After that, you will need to make your local branch track your remote branch. Here are the commands that do just that:

Note: You need to be on a different branch before you execute the second command, so you might want to do a git checkout master first.

git push origin <branch>
git branch -f <branch> origin/<branch>

or to be more specific to my example:

git push origin superCoolFeature
git branch -f superCoolFeature origin/superCoolFeature

Once you've done that, you should have a new branch on your remote and your local branch should track it. Now you need to tell your teammate to create his own local branch that tracks the remote branch. They can do that with the following:

git branch -t <branch> origin/<branch>

or again, more specifically:

git branch -t superCoolFeature origin/superCoolFeature

As always, you should proceed with caution. Have backups of your repo before performing a new command for the first time (In general backups are a good idea, regardless of what you're up to.)

Also for future reference, here is the list of blog post on the subject I found while investigating this:

Wednesday
Nov032010

Kinesis Advantage Keyboard - First Impressions

Motivation

About ten months ago, I had a sharp pain in my wrist. In that occasion, it happened after an accident while I was playing racquetball. I visited the doctor and he said I should wear a wrist brace. I did so on and off for about six to eight weeks. While I was in pain, I noticed that the slew of keyboard shortcuts I use on a regular basis were killing me (in particular those involving the control modifier, so I swapped control and caps lock.) I did get better and life came back to normal and stopped using the brace.

A few weeks ago, my left wrist started bugging me again. This time I remembered I had gone through this five years ago (I know, my memory is legendarily crappy.) That time the pains went away when I started using a Microsoft ergonomic keyboard. I used it until I switched to using mac laptops. So now that the pain was starting up again, I decided to get a new ergonomic keyboard.

Choosing a model

I could have gotten another Microsoft keyboard, but I was never crazy over the build quality of my last one (which BTW was not a USB model so I couldn't use my old one.) and besides, the Microsoft keyboard is obviously very biased towards Windows (can't blame them for that.)

So after investigating a bit, I found the Kinesis Advantage Contoured Keyboard. There are several less radical options out there, even Kinesis has some split in two halves keyboards, that are otherwise rather "normal." I decided that if I was going to get used to an ergonomic keyboard, I might as well get one that goes out all the way and redesigns the whole thing from scratch. (What can I say? I believe engineers do their best work when they can rid themselves of legacy constraints.) The only legacy that I decided to keep was the Qwerty layout.

Foot Switch

So I just got and I'm typing on it right now. It feels freaking weird. But first things first. I got the regular Advantage model in black. I could have gone for the Pro, but I wanted to get the three-way foot switch. I found the websites a bit confusing. Clearly, the Pro model is differentiated by its silver color and expanded macro memory, but what I missed for a while was the fact that it also includes a single-way foot switch. I was set on trying the three-way foot switch and I could not find a way online to upgrade to that with the pro without paying for a superflous one-way switch.

If you decide to get the keyboard and the foot switch, make sure you don't buy the more expensive USB foot switch. The USB models are standalone, and could work in theory with any other keyboard. If you get the pedalboard that only works with Kinesis keyboards, you will save some money, but I also believe you will enjoy tighter integration. The model that I got connects to the keyboard with a telephone style cable (RJ-45?) With this model, you supposedly can reprogram the foot switch, just like you can any other key.

First Impressions

OK, so right off the box, I have to say I'm happy with my perceived build quality. It feels solid. We shall see if it remains like this over time.

Hooking it all up was pretty straight forward. It has a little USB hub in the back with two ports. I hooked up my old mouse's wireless dongle. The ports are kind of in a cave underneath the keyboard. This is perfect for things that don't get moved around (like my mouse wireless link) It probably would not be very useful for memory sticks and such.

Right now, typing anything requires my full concentration. I'm sure that this will improve over time (in fact, just as I write this post I can start to feel the difference in my head.)

A lot of keys (mostly modifiers) get moved over to the thumbs. I expect this to be big win on the long run, but right now I feel like I'm all thumbs (pun fully intended.) In particular, my right thumb is in charge of space and my left thumb does backspace (or delete in true mac parlance) Unfortunately, I'm used to hitting space with my left thumb so now instead of getting spaces between words, I keep nuking the last letter of the previous word.

This keyboard is carefully crafted with the motion of every finger in mind. It certainly feels that way. My fingers feel less stressed than they usually do when typing something this long (sorry about the length of this post, but I need the practice.) But there is another side effect that I did not anticipate: this keyboard hilights all my bad typing habits. Apparently, I tend to hit some characters that are in the pinky column with my ring finger. The problem is that, since the column is calibrated for the pinky, using the wrong finger results in much hilarity.

I can see this will take a while to get used to. It probably would go easier if I were a better typist. I tend to depend too much on occasionally seeing the keys, that will get me into trouble with this keyboard. I do think think that sticking it out with this keyboard will make me a better typist.

So far I am liking using the foot switch for shifting, but I'm not sure if I will eventually get to use all three switches. Right now I'm working hard just to remember one. Only time will tell how well modifiers work for me on my thumbs. Right now, I can already feel my thumbs growing tired.

Finally, I can also feel my back starting to get tired. I believe that my chair doesn't provide me enough height (besides it's kind of broken.) I also think that I need to raise my table about an inch or two. This keyboard demands good posture. Again, that feels weird right now, but I believe it will bear fruits in the long run.

Sorry, for the super long post. I do plan on writing a follow up after I've had a few days with it.

Thursday
Jul152010

News and Noteworthy

I thought I was pretty happy with the launch of RetroSketch. Then, a week later, Apple featured it in the News and Noteworthy section of the App Store. Turns out I was able to get even happier than I initially thought possible.

Today, marks the last day RetroSketch will be featured in the App Store. It has been a very nice ride. Once again, I find myself grateful.

rsomg.png

Thursday
Jul082010

Thank You.

My new favorite tweets.

I released RetroSketch to the App Store last week. I am very proud of it's minimal interface. But I have found a major problem with its lack of chrome– I have no place to thank all the people who have helped me along the way.

First and foremost I need to thank God for the opportunities I have received and the talents I was given. I also need to thank my wife and kids. They have supported me all along and have endured many challenges along the way. None of this would be possible without them.

Next on the list are all my friends and colleagues that have helped me out. In particular I want to thank Rob Rhyne, Mike Ash, Mark Boszko, Sandy Wang, Guy English and everyone at NSCoder Night DC. If it wasn't for all these fine folks, RetroSketch would be a slow, pokey, ugly, barely usable pile of code plastered on a hard to read website. (Trust me on this one.)

Finally, I want to thank all of my good friends scattered over the internet. I can not begin to explain how deeply moving it has been to see the outpouring of support. The picture next to this article is something I never expected to see. What can I say?

THANK YOU.