Wednesday, December 28, 2011

a piece of py: renaming files

I hate spaces in the names of files. It's a quirk of my personality. I prefer CamelCase as an alternative. I used to like a mix of lower case letters, hyphens and underscores, but that was before my world of Unix and Python was dominated by Java.

However, I am a member of the minority and so I often end up with folders and files whose names aspire to be sentences (or at least parts of speech like nouns, prepositions, pronouns and the occasional verb [To be DELETED: ugh!). Today was one of those days. I had a folder full of PDFs, each with a name of the form Last, First.pdf. I would have preferred a name like FirstLast.pdf. The easiest way to do this was with some shell-fu or Python-fu (with due apologies to the GIMP). I tossed a coin and chose Python. I fired up PythonWin and started working on fragments that would eventually unite into a single one-liner to rename them all (sorry JRR). I wasn't smart enough to reduce it all to one line (I needed the imports and I was not a lambda knight).

import fnmatch, os
# basedir is a string representing the full path to the folder
# containing the poor PDFs
for pdf in fnmatch.filter(os.listdir(basedir), '*.pdf'):
  new_name = ".".join(["".join(reversed(pdf.split('.')[0].split(', '))), 
                      pdf.split('.')[1]])
  os.rename(os.path.join(basedir, pdf), os.path.join(basedir, new_name))

Of cours,e I could have skipped using new_name completely:

import fnmatch, os
# basedir is a string representing the full path to the folder
# containing the poor PDFs
for pdf in fnmatch.filter(os.listdir(basedir), '*.pdf'):
  os.rename(os.path.join(basedir, pdf), 
         os.path.join(basedir, 
                 ".".join(["".join(reversed(pdf.split('.')[0].split(', '))), 
                 pdf.split('.')[1]])))

I think this might be the first time I used reversed(), but since it was a relatively recent addition (2.4 to be precise), I didn't feel too bad. Had I written this code before 2.4 had been released, I would have been forced to use reverse(): this also reversed the list, but did it in place and did not return the list; I would be forced to reverse the list first and then send it onto the join conveyor belt.

I also like how just adding brackets as bookends to items separated by commas, I get a list:

["".join(reversed(pdf.split('.')[0].split(', '))), pdf.split('.')[1]]

Mission accomplished. With some learning to boot. Not bad for a few minutes of work.

Monday, December 26, 2011

pentahexed: the tale of a misleading manifest

If you have worked with Oracle's JDBC drivers before, you are no doubt familiar with ojdbc5.jar and ojdbc6.jar.

Oracle tells you that ojdbc5.jar contains Classes for use with JDK 1.5. It contains the JDBC driver classes, except classes for NLS support in Oracle Object and Collection types and that ojdbc6.jar contains Classes for use with JDK 1.6. It contains the JDBC driver classes except classes for NLS support in Oracle Object and Collection types.

Take a class oracle/core/lmx/CoreException.class from each JAR, send it to file and you are not surprised with what you see:

(for oracle/core/lmx/CoreException.class from ojdbc5.jar): compiled Java class data, version 49.0 (Java 1.5)
(for oracle/core/lmx/CoreException.class from ojdbc6.jar): compiled Java class data, version 50.0 (Java 1.6)

Open the manifest of each JAR, however, and you see something interesting. The value of Created-By is the same in both JARs: 1.5.0_30-b03 (Sun Microsystems Inc.). How can a JDK 1.5 compiler know about JDK 1.6? Surely, this has to be something lurking in the scripts that needs to be fixed. It also wouldn't hurt to use a newer version of Ant (the value of Ant-Version) is Apache Ant 1.6.5 (the latest version is 1.8.2).

Saturday, November 26, 2011

dhanush unleashes linguish

The viral attack of why this kolaveri has found a very unlikely (and rather unfortunate) victim: The Language Log. Why? Surely not because the Tabloid of India had something to say about it. Was it because the WSJ had a piece on it? Sigh.

Friday, November 25, 2011

revisiting wallace

After I had tried to catch up with the works of Sidney Sheldon and Robin Cook, it was inevitable for my attention to turn to Irving Wallace, another name familiar to fans of Sheldon, Cook, Ludlum, Cussler and Clancy. Wallace, if you didn't know it already, was responsible for encouraging Sidney Sheldon to publish his first novel The Naked Face. This might explain why s*x features a lot in the works of both writers. Research was more important to Irving Wallace than to Sheldon and he made sure his books were full of its fruits (consider books like The Seven Minutes and The Word); the experience for me as a reader was hardly as unpleasant as it was when I was unfortunate enough to read the works of Dan Brown, another purveyor of research.

But I digress. I just finished reading an old hardbound copy of The R Document that I had picked up at a book sale organised by the public library. I was surprised at how fast I had finished it, but I was also relieved that it was not as painful as The Pigeon Project. The latter also tried to be a travelogue of Venice while we follow Tim Jordan in his attempt to save the formula for yet another elixir for youth. The biggest problem with the novel is that it isn't hard to predict the end and once you have done that all the suspenseful goings-on are just not suspenseful anymore.

The R Document, on the other hand, is a conventional thriller with the appropriate twist and surprise tossed in ever so often to season the proceedings. The novel follows Christopher Collins, the Attorney General of the United States, as he races against time to find out more about a mysterious "R Document" that seems to be a rather nasty side of the 35th amendment (which is a new amendment to the Constitution that allows the powers-that-be to suspend the Bill of Rights during times of national emergency). Once again, you can predict how this is all going to end. But this time, Wallace does not try to do more than deliver a standard thriller while showing off his research on politics and the constitution of the United States. There is no travelogue. There is no sequitur into unrelated sub-plots. This is the stuff of efficient black and white low-budget thrillers (and in the hands of a competent journeyman that black and white thriller would have been a far better piece of art than this piece of pulp). Since this is fiction for the masses, it would be unfair to expect complex characters or a genuine sense of intrigue and dread. This novel was written 45 years ago, but could easily have been written today about the Patriot Act of 2001. That topical stroke of luck makes The R Document more memorable (is that too strong a word?) than The Pigeon Project.

commerce versus process

I asked Google about "my passport" and the first link in the results is Application Status, which is a page hosted by the Bureau of Consular Affairs telling visitors how they could check the status of their application for an American passport. Results about Western Digital's products appear only later.

Saturday, November 05, 2011

dirty ditties

Bappi Lahiri famously insisted that A. R. Rahman had lifted the ho in Slumdog Millionaire's Oscar-winning jay ho from his hit rambhaa ho from Armaan. In Anuvab Pal's book Disco Dancer (dedicated to the cult classic starring Mithun Chakraborty), he is even quoted as proudly claiming to have brought the ho to Bollywood. Would he then concede that Vishal-Shekhar's ooh la la from The Dirty Picture owed a debt to a certain song composed by A. R. Rahman for Rajeev Menon's Minsara Kanavu?

Regardless of such trivial quibbles, Bappi seems like the perfect person to warble this lusty duet with Shreya Ghoshal (who would have thought she'd pick a song like this instead of a strain of romantic yearning?). The song starts off feeling like an uncensored alter ego of R. D. Burman's chunarii sambhaal gorii before shifting into a nostalgic paean to the disco-laced 80s dominated by Bappi-da. Bappi gets to pay tribute to himself in (as far as I can remember) his second song for Vishal-Shekhar. He couldn't have asked for more.

it was a pleasure to be amma

I was pleasantly surprised and very impressed when I visited the Anna Centenary Library. I love the public library system in the US and always wished that something similar had existed in India (the British Library in Pune was the closest, but it offered only paid subscriptions and a catalogue mostly limited to the United Kingdom). For the first time, I saw hope as I explored the floors of the library.

And then Amma's crusade against all the edifices erected by her predecessor headed to Kotturpuram. The library was Amma's next salvo against Anna. Once again she wanted a hospital in its place. So far, such a hospital has not been set up in India. By establishing a super speciality hospital dedicated to interests of children, it is certain that Tamil Nadu would [sic] emerge as the top ranking State in protecting the interests of children, she was quoted as saying.

And what happens to the contents of the library? Amma plans to move them to the proposed Integrated Knowledge Park on the DPI (Directorate of Public Instruction) campus in Nungambakkam citing some reasons for this being a very ideal place. Nobody said anything about whether her government plans to be fair with space. I find it hard to believe that they're going to match square foot for square foot and floor for floor. Books in a bookshelf are likely to end up packed in boxes.

But I exaggerate. I shouldn't be cavilling about this. After all, a hospital is a noble thing to have (I trust that the hospital will be generous to all children in need of medical assistance). But so is a library. Surely there are condemned structures around town that can be torn down and replaced with her hospital. Surely there are other locations in the metropolis that deserve a facelift for the better.

But Amma must have this building.

Not because its location works better for a hospital than for a library.

Not because its interior design and layout are more conducive for hospital beds, labs and offices than for bookshelves, reading desks and couches.

But because Anna made it.

How people can elect such bickering people into office is beyond me.

Mercifully, the Madras High Court has restrained the State government from moving the library. Perhaps good sense will prevail and I'll still expect to see books on shelves and see people sitting at the desks reading and studying instead of dealing with the smell of disinfectant.

(the title of this post paraphrases the opening line of Ray Bradbury's most famous book, which seems quite appropriate for the occasion)

Wednesday, October 26, 2011

eternal riders of pune

After a fresh experience of the roads in Pune lasting several days, I am ready to conclude that the average Puneite on the road (on foot, gripping the handle of a motorised two-wheeler or a bicycle, helming an autorickshaw, car, van, bus or truck) has three significant qualities: he or she is discourteous, he or she is selfish and he or she is suicidal. Despite this lethal combination of qualities, he or she seems eternal. untouchable by death. amar. imagine that. The font of eternal life must exist in the murky miasma of the traffic jams in Pune: how else does one explain the lack of significant fatalities on the roads when everyone (regardless of their size or the size of their mode of conveyance) is trying to squeeze into every available space of every size at any imaginable speed? That woman sliding between a bus and a jeep passed through without a scratch; that scooterist swung cleanly a breath away from the noggin of a large van; those two cars crissed and crossed by a motorcyclist without affecting his path or angle at all. Unbelievable.

Friday, October 21, 2011

you pay for the space: the annoying things are free

Cellphone screens in the dark. Think of fireflies with Asha Parekh-ian (or Nanda-esque) derrieres. They are annoying. Distracting. Especially when you are trying to watch the movie.

Cellphone ringtones. They are annoying. Distracting. Especially when you are trying to listen to the dialogue uttered by the characters in the movie that you have been trying to watch.

Inconsiderate. The people who paid for the seats they are sitting in and insist on continuing to use their cellphones to send text messages, receive and check text messages, make calls and receive calls without being courteous enough to switch their phones to silent mode. The cinema hall is just another place to hang out and presumably what transpires on the screen is akin to the unfortunate band that plays music while you dine in some faux star restaurant.

Except that the film and the band are not the same thing.

Could you please take your call outside?, I lean over and say to the girl sitting next to us, who, after a conversation louder than the booming sound of the film playing in the hall, has decided to talk on the phone,

It's an important call, she replies, failing to see why I should have a problem with this. I continue to be polite and inform her that the volume of her conversation is louder than the volume of the film (which is why I have a problem -- because I paid to listen to the film and not to her). Her reply is priceless: You could have said it in a more polite way (or words to that effect).

Is it time to take a leaf from Falling Down and go watch movies with a baseball bat in tow? Is that the only way to get such inconsiderate, discourteous (and seemingly clueless) people to behave? Why doesn't the management of the theatre/multiplex request people to be courteous? Why aren't there any ads like the Don't spoil the movie by adding your own soundtrack ad that plays at the AMC theatres? Why doesn't someone take a hint from the Alamo Drafthouse? (the uncensored PSA is here)

Monday, October 17, 2011

entomical cojones

Look carefully at the glass wall for the customs office (or some office dedicated to a similar function) at the airport in Pune as you walk from the check-in counters to the place where the security check is conducted and you will be informed (among other things) not to take khus khus and (I kid you not) beetle nuts into Dubai (or the Gulf, unless I am mistaken). Surely they meant betel, unless those parts of the world regard the family jewels of the members of the Coleopteran order as either a culinary delicacy or something as precious as a rhino's horn.

Thursday, October 06, 2011

jobs all over

Last night, when I read that Steve Jobs had passed away, I switched to the Hacker News tab and refreshed it to read what the world had to say. I saw something I had never seen before: every single one of the 30 items on the first page was about Steve Jobs. It was worth a "screencap": steve jobs on hacker news

My favourite tribute so far (aside from the austere bold link on google's main page) was the image here.

Tuesday, October 04, 2011

super seven: the fox is on fire

All hail Nicholas Nethercote!

When Mozilla launched Memshrink to finally do something about all the memory that Firefox never seemed to let go until it had to shrug, I discovered Nicholas Nethercote's blog. Since then I have been reading every new post on his blog, enjoying his writing style and also learning a lot about performance tuning and about the innards of Firefox (I didn't know just how much sqlite was used in all those add-ons). I also waited eagerly for Firefox 7 so that I could see the results of all these fixes and last week I didn't hesitate a moment when I saw the pop-up in the system tray telling me that Firefox 7 was available. Mercifully, the only hacks I needed to get two add-ons working were familiar ones that I had effected when Firefox 5.0 was rolled out.

A few minutes later, after Firefox was back up and running, I could see the difference. I spent some time playing with about:memory?verbose, because the output now contained information about the various compartments that were using memory. Firefox was not lurching to chomp away memory. Instead, it seemed more well-behaved and offered strong testimony to everybody who had worked hard to plug all those leaks and free all that heap.

The only cloud in this silver sky was a news article screaming that Chrome was poised to take over from Firefox as the second most popular browser. Perhaps all these fixes have come too late. Perhaps the article didn't analyse the data correctly and fairly. I don't care much right now as long as Firefox 8 promises to shed even more lard.

Saturday, September 24, 2011

non-vegetarian vegetable

The local Indian store has a modest section offering vegetables each labelled in English with often liberal spelling. Redish was just something to warm you up and prepare you for Bison Bites aka Snack Gaur. Rest assured, O shocked vegetarians. This was not the bison served up to complement a sip of cold carbonated cola; this was just a typo too much for trichosanthes cucumerina, also known as your friendly neighbourhood snake gourd. You may now breathe again.

Sunday, September 11, 2011

old-time poetry

I found some amateur verse from the old electronic archives today. I seem to have written it in October 2002, when I used MARTA more often than I do now; here goes nothing:
walking steadily to keep time
with a bus approaching
it's a race to survive
the fumes and fury
of rush hour

why do they desert me
when I'm in a hurry
i see too many of them
when I'm not

PS:: The title is a play on the name of a rather interesting store that I discovered some months ago (the only branch in Georgia, as it turns out)

operation yellow boots

Anurag Kashyap does it again and this time around he's not the producer, but the director and one of the writers of the film. Having already been witness to one of the most unlikely places to hear a quote from Jim Morrison, we are not as surprised when, after she asks Chittiappa Gowda the gangster when she should come (to pay off the gangster in happy endings), the gangster, already oozing comic menace, goes if you come today, it's too early; if you come tomorrow, it's too late; you pick the time; tick tick tick tick tick tick; tick tick tick tick tick tick. This not only fits his character because he is a Kannadiga ganster, after all but ensures that those who have never been lucky to have heard (and seen) the cult favourite from Operation Diamond Racket get a chance to right the wrong. Priceless!

PS: Earlier in the scene, when we first see Chittiappa, he's watching the video of a film song (that sounded like a Kannada version of Ilayaraja's raajaa raajaathi from Agni Natchathiram) on the tube. Does anyone know which movie that was?

Thursday, September 01, 2011

deeply ambiguous

The poster for Deep Blue Sea features two living creatures -- a shark and a lady in distress. Does the tagline "Bigger. Smarter. Faster. Meaner" refer to the shark, the shark's gaping maw or the threatened rack?

Friday, August 26, 2011

bearable exposition

I get the feeling that all writers churning out candidates for the mainstream bestseller lists have to deal with exposition a lot more often than writers of works that are less mainstream. Some of these writers turn this devil around and decide to take the opportunity to show off all the research they have done (Crichton did this well; Dan Brown does not).

Intermission: Can you imagine Anthony Burgess writing A Clockwork Orange in the style of Dan Brown? The book would have been thicker and loaded with interleaved explanations of nadsat and descriptions of the prison, its architecture, its history and who knows what else. A title like Fruits and Mechanics would have topped this cake of futility.

I'm on a Michael Connelly buffet right now and the 8 books I have read have introduced me to exposition of various flavours and of varying levels of subtlety (or the complete lack of it, in some cases), but his exposition never strays beyond the realm of the police procedural and the court room. This, I think, is a good thing. It would have been unbearable to wade through a mini-treatise on the architecture of the courthouse just as we were about to begin an interesting trail.

Some of the books are written in the first person. This allows the writer to be more liberal in the exposition, because, after all, this is supposed to be a man or woman telling you a story. The more details you get, the better. A lot of exposition that might otherwise stick out like a sore elephant in a regular third-person narrative goes down easier when Jack McAvoy or Mickey Haller is writing to you, dear reader.

I tend to prefer little to no exposition (which is why I admire the bold stroke of the glossary in Vikram Chandra's Sacred Games: you read the tale with its natural rhythms and later use the glossary to understand the vernacular), but I can understand the need for it in mainstream fiction. Besides, fitting it into the narrative without losing the reader is not trivial. Given this, I liked the few examples from the 8 books I had read so far, where the exposition was adroitly placed just like a shot/reverse shot scene where the cutting didn't bother you. Here's an example from The Brass Verdict (I have taken the liberty of marking the relevant sections):

"Two arrests. ADW in 'ninety-seven and conspiracy to commit fraud in 'ninety-nine. No convictions but that is all I know for right now. When the court opens I can get more if you want."
I wanted to know more, especially about how arrests for fraud and assault with a deadly weapon could result in no convictions, but if Cisco pulled records on the case, then he'd have to show ID and that would leave a trail.

Tuesday, August 23, 2011

may which force be with you?

Both Rediff and Hindustan Times have something to say about Force, the remake of Kaakha Kaakha. Unfortunately, both disagree on what seems to make this production special enough to merit a news item.

Rediff says: What will make this film stand apart from his other films is that Amin claims he has not used cables in Force at all, a vital element in action sequences.

HT says: Film's action director Allan Amin told the tabloid: "John is a physical guy so the action was all high octane. We did use cables for certain sequences[...]

It gets even better when both disagree on the weight of this motorcycle that John Abraham chose to lift himself without wires instead of eliciting the services of a stunt double. Rediff insists that the weight of the bike was 200 kilograms, while HT is confident that it was only 150 kilograms (it's still heavy enough to merit a "wow," but "really heavy bike" does not sound attractive enough in a news article). Perhaps a special feature on the DVD of the film will include a section dedicated to trivia to console us all.

Spoonerism alert: The Rediff article begins with a reference to a film called Rang De Sabanti (you know they are actually talking about this).

Saturday, August 20, 2011

did NDTV use a machine to transcribe an interview?

A couple of months ago, NDTV published an exclusive (they said it) interview with A. R. Rahman conducted by Prannoy Roy. The interview is mostly a piece of fluff with each subsequent question often having nothing to do with the previous one. There are a couple of nuggets of trivia, but they hardly make this piece worthwhile. The most irksome thing, however, is evidence that the transcriber was clueless, the editor was asleep or that the transcriber was a machine and that there was no editor. How else does one explain Y R Muttu instead of Vairamuthu and Jammu Sukand instead of Jhamu Sughand? Who can tell? Who knows? Who cares?

Monday, August 15, 2011

send the BSIFA back in time

Although Edward X Delaney was perhaps his most famous creation, Lawrence Sanders also created another interesting detective called Timothy Cone, an ex-Marine working as an investigator for Haldering and Company, a Wall Street firm specialising in corporate intelligence (in plain English: he investigates deals and mergers that reek of foul play). He is, needless to say, brilliant; he is also rather eccentric (otherwise he probably wouldn't be an interesting character). The tales of Cone are short, all written in the simple present tense (for creative reasons unknown) and collected in two volumes, The Timothy Files and Timothy's Game. Their lasting value, however, lies not in the plots and the twists (a lot of which are just surprises -- only Cone really can really put the pieces together), but in the scenes of intimacy between him and his boss Samantha Whatley (yes, they are having an affair unbeknownst -- they hope -- to the other people in the office). I was not surprised that Sanders valued such scenes, since he had devoted entire novels to desire, lust and coupling (you can't go wrong with titles like The Seduction of Peter S and The Passion of Molly T). What I was not prepared for was that his descriptions of the moments between Cone and Whatley seem to almost parody themselves with poetic flourishes, pithy phrases and often laughably inane choices of words. Allow me to present a sample from the works collected in The Timothy Files:

but they cannot deny their bodies' appetites, and when their hormones take over, they go berserk.

they're two stick figures, all bony knobs and hard muscle. their mating is a furious battle, not against each other so much as the emptiness and lunacy of their lives. when they strain, it is not to punish but to break out into another world. oh, look at the meadows and the daffodils! the lawn they seek is bliss.

it's such a sweaty wrestle, not quite hysterical but frantic enough. and
when they're done, staring at each other with dulled eyes, reality comes
seeping back, the real world takes over again. but something remains ...

they're like two rough hawsers, braided, rasping against each other and welcoming the scratch. in no way are they gentle or tender, because they are both hard, hurt people, wanting to get out. and this is the only way they know.

so there are no proclamations of love or undying passion. instead there is is a gritty intenseness, both of them serious and hoping. their coupling is a partnership of two bankrupts, as if all their liabilities combined might show up in black ink and make them wealthy.

they really do get out with each other, as attuned as a duo of violinists, howing and scraping in unison and losing themselves in mutual harmonies. carried away and lost with closed eyes and seraphic smiles, loving life and its surprises.

finally, ignited again, they come together in a different mood: all murmurings and soft twistings. they couple in a drugged tempo, slow and lazy, as if this night might last forever.
later, drowsy and satiated, they lie entwined, peering at each other with dazed eyes. they say nothing of what has happened, not wanting the moment to slip away -- as it inevitably does.

BSIFA was a reference to this

 
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.