Search and rename files in a directory using Python

I found this cool script for renaming files using a Python script. Never thought it would be so easy.

#!/usr/local/bin/python

# Python Rename File 1.0
# Author: Douglas Palovick
# License: GPL http://www.gnu.org/licenses/gpl.txt

import re, os
rxin = raw_input('enter a regex to search for:\n')
foo = re.compile(rxin)
newname = raw_input('enter a new base name:\n')
a = 0
for fname in os.listdir(os.getcwd()):
    allowed_name = re.compile(rxin).match
    if allowed_name(fname):
        # newfname = string.lower(re.sub(foo,
                                   # '', fname))
        # b = (newname + str(a))
        a += 1
        c = os.path.splitext(fname)
        b = (newname + str(a) + c[1])
        os.rename(fname, b)

Simple Latex article template

Here is a simple template for writing an article. If you happened to write in German add “\usepackage[ngerman]{babel}” and change \usepackage[utf8]{inputenc} to \usepackage[latin1]{inputenc}.

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\date{24.04.2009}
\author{Max Mustermann}
\title{Replace with the title}
\begin{document}
\maketitle
\begin{abstract}
Abstract starts here.
\end{abstract}
\tableofcontents
\section{Start}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce nec justo. Fusce congue sem eget lacus. In nisi tortor, auctor in, ultricies eget, sollicitudin in, metus. Aliquam erat volutpat. Morbi enim odio, semper vitae, scelerisque a, varius eu, erat. Duis interdum, turpis non tristique sodales, dolor nunc congue est, ac luctus libero purus quis nisi. Curabitur non neque. Ut massa. Sed porta egestas nisi. Aenean aliquet placerat lectus. Donec urna. Fusce porttitor congue velit. Fusce et purus nec velit posuere pharetra. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ante massa, luctus in, gravida nec, venenatis ut, dolor. Cras rutrum. Suspendisse scelerisque feugiat libero.

Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nulla et purus id purus commodo hendrerit. Praesent nec libero. Sed mollis placerat elit. Quisque odio nibh, blandit sit amet, volutpat ultricies, sagittis eu, enim. Ut aliquam pulvinar metus. In hac habitasse platea dictumst. Nunc molestie, ipsum non pharetra commodo, neque nunc rhoncus tellus, vitae interdum quam tellus a sapien. Nam tincidunt, est in bibendum imperdiet, enim nibh vulputate lacus, quis elementum lacus enim non elit. In vel risus quis elit rhoncus mollis. Pellentesque mi nisi, lobortis eu, scelerisque et, pellentesque at, arcu. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.

Quisque libero turpis, scelerisque nec, tincidunt eget, mollis in, massa. Duis sollicitudin sapien a odio. Phasellus sodales arcu et magna. Nam ut quam. Donec ante. Curabitur eget orci. Duis mattis sagittis nibh. Nulla facilisi. Nullam mauris. Aenean ante risus, facilisis sit amet, commodo at, tempor ut, felis. Maecenas at urna. Aliquam erat volutpat. Maecenas molestie. In nulla urna, tempus at, volutpat sit amet, hendrerit ac, leo.

Proin commodo gravida metus. Proin ligula. Quisque sed nunc quis tellus accumsan bibendum. Morbi dui nunc, lobortis et, tempus molestie, dictum eu, leo. Morbi sagittis mollis metus. Proin a dui. Integer interdum. Integer mattis dui nec justo. Proin vitae sem in leo pharetra bibendum. Donec sapien augue, molestie in, sagittis sodales, imperdiet sit amet, ipsum. Nulla nisl lectus, sollicitudin nec, interdum ac, tempus rhoncus, diam. Cras neque lectus, bibendum non, posuere et, interdum id, dolor. In eu neque sed neque dignissim dignissim.

Cras ornare magna at felis. Mauris augue dolor, blandit et, convallis sit amet, semper in, lectus. Nam dignissim. Donec lorem. Donec vitae magna. Aenean eu neque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris venenatis dapibus quam. Phasellus ultricies, magna quis venenatis condimentum, tortor elit sollicitudin arcu, id sagittis nisi leo id urna. Phasellus mollis lobortis tortor. Proin molestie mattis felis. Sed vel purus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec nisl lorem, placerat et, ultrices sed, ornare sagittis, mi. Vivamus ornare, tortor nec faucibus fermentum, tortor odio gravida erat, non luctus nulla dolor sit amet dui. Nullam sagittis odio id est. Aenean malesuada libero nec lectus. Aliquam nec justo.

\section{Next Chapter}

\subsection{Sub Chapter}
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce nec justo. Fusce congue sem eget lacus. In nisi tortor, auctor in, ultricies eget, sollicitudin in, metus. Aliquam erat volutpat. Morbi enim odio, semper vitae, scelerisque a, varius eu, erat. Duis interdum, turpis non tristique sodales, dolor nunc congue est, ac luctus libero purus quis nisi. Curabitur non neque. Ut massa. Sed porta egestas nisi. Aenean aliquet placerat lectus. Donec urna. Fusce porttitor congue velit. Fusce et purus nec velit posuere pharetra. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ante massa, luctus in, gravida nec, venenatis ut, dolor. Cras rutrum. Suspendisse scelerisque feugiat libero.
\section{End}

Cras ornare magna at felis. Mauris augue dolor, blandit et, convallis sit amet, semper in, lectus. Nam dignissim. Donec lorem. Donec vitae magna. Aenean eu neque. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris venenatis dapibus quam. Phasellus ultricies, magna quis venenatis condimentum, tortor elit sollicitudin arcu, id sagittis nisi leo id urna. Phasellus mollis lobortis tortor. Proin molestie mattis felis. Sed vel purus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec nisl lorem, placerat et, ultrices sed, ornare sagittis, mi. Vivamus ornare, tortor nec faucibus fermentum, tortor odio gravida erat, non luctus nulla dolor sit amet dui. Nullam sagittis odio id est. Aenean malesuada libero nec lectus. Aliquam nec justo.
\end{document}

Just started using svn

subversion logo

Today I started using subversion to update this website. After couple of initial hick ups things are working pretty fine now. If you are planning to use svn make sure to backup the blog before checking out.

Here is how I set up the blog to update using svn.

  1. In Terminal cd to the document root. (eg. cd /srv/www/htdocs/)
  2. mv <blog dir>/ <backup>/ -> If anything goes wrong, you could reinstate the blog by reversing the above.
  3. svn co http://svn.automattic.com/wordpress/trunk/ <blog dir>/ -> This will download a working copy of the latest WP bild.
  4. cp <path to wp-config.php from the backedup copy> <path to new blog root>/ (eg. cp backup/blog/wp-config.php blog/)
  5. cp <path to backed up copy of the uploads> <new wp-content dir> (eg. cp backup/blog/wp-content/uploads blog/wp-content/)
  6. cd <blog dir> and issue svn update command to upgrade the WP version.
  7. When you switch to the login mode, WP will automatically attempt to update the database. If there are any plugins or themes missing, you could install them now. (some plugins can be updated directly in the Admin mode)

Obama vs. Hillary

If you ever seen a “Get a Mac” advertisement, you may find this funny. The cartoon is from Bill Mitchell.

12a.gif

Funny Blue Screen of Death

While looking for a background image for my iMac, I found this. Click on the image to see more.

bsod.gif

Flawless (2007)

Just watched a British movie called Flawless. I must admit that it had created such a big excitement from the beginning to the end. There were hardly anything to complain about. The Music is great(I am a Jazz fan)! and Demi Moore plays her role pretty well too.

Storyline

“From director Michael Radford (THE MERCHANT OF VENICE, IL POSTINO) comes FLAWLESS, a clever diamond-heist thriller set in swinging 1960s London. Demi Moore plays Laura Quinn, a bright, driven and beautiful executive at the London Diamond Corporation who finds herself frustrated by a glass ceiling after years of faithful employment, as man after man is promoted ahead of her despite her greater experience. Michael Caine is Hobbs, the nighttime janitor at London Diamond who is virtually invisible to the executives that work there, but over the years has amassed a startling amount of knowledge about how the company runs. Hobbs has his own bone to pick with London Diamond. Observing Laura’s frustration, he convinces her to help him execute an ingenious plan to steal a hefty sum in diamonds. But unbeknownst to Laura, Hobbs plans go even farther than he’s let on, and together they set in motion a thrilling heist of dizzying proportions, the likes of which London has never seen.”

flawless

Any freelancers here?

Just happened to stumble upon this very useful site dedicated to freelancers.

freelance

Life after death

life after death

Tutorial: Photoshop Button Maker

Here is an excellent tutorial about making buttons using Photoshop. It is being explained in a very simple way and there are couple of samples available for you to try it yourself.

Link to the tutorial.

finiteloops.com finally complete

After months of testing various CMSs, I have decided to install WordPress on finiteloops.com. This wasn’t an easy task as it was difficult to find a easily configurable CMS with good themes and plugins. So far I have tried Textpattern, Movable Type, e107, Drupal, and couple of more. Every single one of them have their strengths and weaknesses but overall WP gave me the best impression.