Category Archives: Uncategorized

Renaming files by pattern

Occasionally (and especially when receiving assets) I have the need to rename multiple files at once — often by some sort of pattern. For instance, I may need to rename all files with the string "_msg" in it where the file ends with ".png". Previously, I might have manually found and renamed all of them or written some hack of a bash “for loop” to iterate over a find result. Neither options are quick or easy.

Recently, I found a great and simple util called rename to quickly and easily rename files with simple search-and-replace functionality.

In this example, I’m renaming any *.png file under a drawable* folder, replacing _msg with _message.

rename s/_msg/_message/ drawable*/*.png

The rename util (not the same as mv) comes standard with most linux installations, but I’m on Mac OS X and that means I have to get it separately. In order to easily get rename, I use homebrew.

  1. Install homebrew.
    ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
  2. Install rename
    brew install rename
  3. Done.

Looking at Android Framework source quickly

Even though I have recent checkouts of the Android source on my local machine, I usually prefer a more convenient and quick way to look at the platform code. Looking through source files on my local machine can often be slow to find the appropriate files and unreasonable to keep open in an IDE all of the time. Instead, I’ve been using the copy of the Android source that is hosted on github.

Generally, if I’m looking for something like ‘How is ListView implemented in Froyo?’, I’ll open up the source in github at https://github.com/android/platform_frameworks_base, hit ‘w’ as the shortcut for switching branches and tags, type in ‘froyo’ and choose the right branch, hit ‘t’ as the shortcut for finding a file in the repository, type ‘ListView’ and hit enter to open the file. Now I have the ListView implementation open in Github and ready to peruse!

What’s nice is that at myYearbook, we have a github:enterprise instance where we host our own internal code. So in the same way I can figure out how ListViews are implemented in Android, I can also figure out what our current Android versionCode is. Open the internal github to the myYearbook repository, hit ‘t’, type in AndroidManifest.xml, and then use my browser’s find functionality to look for ‘versionCode’. Done.

Awesome!

parcelabler: for implementing Android’s Parcelable interface

I have created a tool for making the methods needed for implementation of Android’s Parcelable interface within a pre-existing class.

  1. Open the parcelabler tool.
  2. Copy the full code of the class into the “Code” text field.
    Example code:

    public class Photo {
        /**
         * Caption for the photo
         */
        public String caption;
        public int commentCount;
        public long photoId;
        public boolean isDefault;
        public Bundle metadata;
        public CommentHandler commentHandler;
    }
    
  3. Click “Build” to create the methods
  4. Copy the methods into your class
  5. Add “implements Parcelable” to your class definition
Now you should hopefully have a working implementation of Parcelable in your class.