Retainability

Life's lessons expressed in UTF-8

Renaming Multiple Files With a Common Prefix

Last week, while putting together a quick slide show presentation, I found myself having to rename a set of images sharing a common prefix. The images had filenames that started with the prefix cidemot, which I needed to change to cidemo_current.
Since I work mostly on Mac Os X Snow Leopard, live in the terminal, and love me some regular expressions, I wrote a quick one line shell command to rename all of the files for me. Please note that while the following command solved my problem it can lead to the lost of data if not used correctly. So I advise that use it with caution and, if possible, test it on a sample set of files and/or environment.
Multi-File rename command
1
2
3
ls cidemot_* | xargs -n1 -I {} echo {} | sed 's/^cidemot\(.*\)/cp cidemot\1 cidemo_current\1/g' | sh

rm -rf cidemot_*
After renaming the files to the new expected format I deleted the original files with the rm (remove) command. I could have easily used the mv (move) command in the above script to rename and delete the original files in 1 swift move. But I always like to go with a 2 phase rename process so that I can verify the new files before deleting the originals (essentially making a backup).

Command Breakdown, How does it work?

First we start off by listing all of the files with the original prefix and piping the result to the xargs command one line at a time -n1. The -I {} is used for string substitution needed for echoing the filenames as they are to the sed command.
1
2

ls cidemot_* | xargs -n1 -I {} echo {}
The xargs command output is then piped, 1 at a time, to sed where we use regular expressions for doing a search and replace on the filename strings. In this particular snippet of code sed is being used to create a copy command string from the original filename, which can then be piped to the sh (shell command) for copying the original file to a new file with the expected filename (e.g. cp cidemot_patch_image.png cidemo_current_patch_img.png).
1
sed 's/^cidemot\(.*\)/cp cidemot\1 cidemo_current\1/g' | sh

Puppet Master in the Making

Growing up I was always pretty fond of the 1989 film Puppetmaster , which I happen to think, and some may disagree, is a pure classic. I won’t get into discussing whether or not the movie was good or bad. But I will say that the puppets in this movie rocked and the puppet maker was just as cool.

Fast forward 23 years, where I find myself learning how to become a puppet master of my own–puppet making with a twist (via Puppetlabs).

Sometime last year, maybe 2 years ago, I learned about this new configuration management tool for server management called Puppet, since then Puppet has turned into quite the household term.

Which is why, today, I am running through the learning guide on the Puppetlabs.com site to get my puppet making skills up to par. So that I too can make some cool puppets (Puppet scripts that is) to manage all of my servers from a single set of strings.

“Puppet currently in the making … PerBuntu. An Ubuntu Server running Precise Pangolin and Perforce 2012.1“ 



Deleting an EFI Partition in Windows 7

I had an external, WD Passport, 1TB disk drive formatted as an HFS+ drive which I was using on my Mac Os X 10.7 machine. After a while, I decided  to move the external drive to my Windows 7 machine. Seeing as the drive was already formatted on my Mac machine, Windows 7 was unable to fully initialize the drive because of the EFI Partition.

After running a quick search on Google, I found a quick how-to by David Vielmetter on Deleting An EFI Partition In Windows 7 via the Window’s “diskpart“ tool.

In an effort to preserve the contents of his post, in case the link ever changes, I have copied the list of steps from the original post – minus the images.

[step 1] With the external drive connected. Open the Windows command prompt with elevated privileges (Run as Administrator).

[step 2] When in the command prompt enter the command diskpart to enter the disk partition utility.

[step 3]  Type list disk to see a list of available disks. If you are unclear which disk is actually the external drive you can view the correct disk number in the Windows Disk Manager (Start -> Search Box ->  diskmgmt.msc). Once the correct disk has been identified type select disk # where # is the disk containing the EFI partition.

[step 4] Type select partition # where # is the partition you wish to delete.

[step 5] Type delete partition override
[step 6] After deleting the partition I noticed that I had to disconnect and reconnect the external drive for the changes to take effect. The disconnect/reconnect can be accomplished, within the disk partition utility, by typing the following commands offline disk; then online disk

Please note that while the steps listed above solved my problem they can lead to the lost of data if not used correctly. So I advise that use it with caution and, if possible, test it on a test environment.

PyCon2008 (Chi-Town)

This weekend I had the pleasure of attending the 2008 Python Conference (a.k.a PyCon2008). The conference took place in, the Windy City, Chicago with over 1000 attendees. The conference,with the exception of the wireless access, was amazing. My PyCon experience started on Thursday, March 13, 2008 where I attended two Python GUI programming (Intro to WxPython and Advance WxPython) tutorials. For the most part, the Intro to WxPython tutorial was very informative and eventful. The Advance WxPython course was somewhat disappointing,as the instructor was not prepared for the tutorial. No hard feelings I got a pretty good intro to WxPython and a full refund for the second tutorial.


On Friday, March 14, 2008 the conference started off with a bang there were some very interesting keynote speeches given by Chris Hagner (Microsoft), and Guido Von Rossum (Python Creator). It was quite the experience to sit there here how pythonistas are changing the world one day at a time. Immediately after the keynotes speeches I was off to the PyCon expo hall where I visited a few interesting booths like Enthought, Google, OLPC, Nokia, Wing IDE, and White Oak Technologies (WOTI). I was amazed but not surprised by some of the cool open source projects that Google was working on. These guys are really doing their thing and making great strides in the world of computing.

The demos by Enthought and OLPC were very interesting as well. Enthought is working on Multi-touch technology using Python, and infrared cameras to build intelligent touch screen technology. I was able to get one of their distributions CDs with the project docs and examples can’t wait to pop the CD into my machine at home. The OLPC project which is an acronym for One Laptop Per Child was very interesting. Their laptops were very small but they packed quite the punch. The laptops sport a really cool UI that is entirely Python based. The interface is intelligent, and very easy to use; I am sure my nieces and nephews would love to have one of these XO laptops. My main interest behind OLPC is the whole notion of giving back to others. I sat through some of the talks about developing for OLPC because this is one project I definitely wouldn’t mind being a part of.

Organizing Gmail Archives by Date

Over the weekend I found myself wanting to organize my Gmail archives into dated directories–similar to the way Thunderbird handles mail archiving.

At first I thought there is probably a gadget for this in Gmail labs, but no gadget. So I decided to roll out my own solution using filters and labels. I wasn’t really sure how to filter mail by dates so I did a quick search for filter by date in Gmail and came across a post on the My Digital Life blog, which had enough information to get me started. 


Creating The Filter

Start off by creating a new search filter in Gmail for finding all messages sent between 2 dates. For the remainder of this post I will use the dates 01/01/2009 and 01/01/2010 as examples.
Gmail, has support for 2 operators after: and before: which can be used to search for messages sent between a certain time period–dates must be in the format of yyyy/mm/dd. More information on Gmail search operators can be found here.
Enter the search string for the given date range

After entering the specified search string, if you want to test your search, click on the search button. Otherwise just click on the Create filter with this search link at the bottom of the search window to continue.  I recommend that you run a quick test to make sure the filter is working correctly.

After clicking the create filter link you need to configure the actions to take on the messages that fall under the given search. To archive and label all messages sent in 2009 check the Skip the inbox (Archive It) option, and check the Apply the label option which should be set to a label called 2009.

Set the actions the filter should take and click create filter

To apply the new filter to existing mail, check the Also apply filter to ## matching conversations box. The actual number of conversations may vary based on your search.

Once the filter has been created a new label called 2009 should show up in your list of Gmail labels. Clicking on the label will filter your inbox and show only those messages which were sent in 2009.