Thursday, December 02, 2004

Here is another command line tool. Strangely, a couple of quick web searches could not come up with a command line tool for resizing images – so I wrote my own. If you have photographs from a digital camera that you want to mail out and the images are too large for email then most of the time it involves taking each image to some sort of image editing software and resizing them and such.

 

Image Manipulation Utility v0.1

(c) Roshan James, Dec 1 2004

 Img v0.1 is built on the .Net 2.0 GDI+ API and supports only creation

 of JPG image files. Exif/Iptc metadata are lost during convertions.

 

Syntax:

     imgmanip [/S] < filepattern> [additional patterns] < image size>

         /S               - recurse subdirs

         < filepattern>    - any wildcard combination

         < image size>     - format < Width>x< Height>, Ex: 800x600

 

(Don’t tell me it looks cheesy – I know it does – but it solves the problem)

A part of this source I found on the web, so appropriate mention is given to the original article.

 

Here are a few usage examples

 

> img *.jpg 800x600

File1.800x600.jpg

File2.800x600.jpg

This basically converts all jpf files to images of 800 * 600 resolution.

 

To recursively change

> img /S *.jpg 800x600

File1.800x600.jpg

File2.800x600.jpg

Simple?

 

If the original images have any metadata information then they are not retained in the new ones. What is this? Well most cameras insert information about the camera into the image file. You can also add your custom information like a title or description or comments to the image. To see this information (on a WinXP) simple right click the image file and take a look at the properties -> summary tab. Also if you tinker around with the column settings of explorer in detail view you can display some of this info directly in explorer.

 

I can think of a bunch of simple useful things to add – format conversions, cropping, borders, grayscale etc. Lets see…

 

The code is simple usage of .Net GDI+ API. The download exe is compiled to .Net 2.0 – but you can recompile from source to the version you want. For compilation run the following from a .Net SDK 2.0 command line –

>csc img.cs

 

Download

 

Speaking of image metadata, if you are a Ruby programmer, take a look at the exif library available. EXIF is a metadata tagging standard for image files.

http://raa.ruby-lang.org/list.rhtml?name=rexif

Thursday, December 02, 2004 1:14:33 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
 Wednesday, December 01, 2004

Digressing from the past couple of posts - I just wrote this little utility for myself that will do file encryption/decryption from the command line. I figured that some of you might also find this useful so I am sharing it out here.

 

File Encryption/Decryption utility v0.1

(c) Roshan James, Dec 1st 2004 
 Enc v0.1 uses 256 bit Rijndael encryption to give a relatively strong

 encryption for data. The utility is built over the .Net 2.0 Crypto API.

 

Syntax:

     enc +< password> < filename>

         to encrypt a file

     enc -< password> < filename>

         to decrypt a file

     enc ?< password> < filename>

         to view fileinfo

 

This is no rocket science – simple usage of the API - but gives you reasonably good locking and a handy tool. The 256 bit Rijndael encryption implies that you can provide a password that is upto 16 chars in length. The encryption algorithm is a symmetric one – which means that you use the same password to decrypt the file.

 

This is also very rudimentary – no error checks and blah done: just enough code to get the job done.

 

Usage:

 

This is how you encrypt a file

> enc +password foobar.txt

Creating:2004-12-01--1206711.enc (foobar.txt)

 

It creates a new file called ‘2004-12-01--1206711.enc’ using the current date-time. This file is always a few bytes larger than the original. To extract the foobar.txt again you would say –

 

>enc -password 2004-12-01--1206711.enc

 

If you did not wish to extract the contents of an enc file, but you just what to see what file it contains, you say –

 

>enc ?password 2004-12-01--1206711.enc

2004-12-01--1206711.enc ==> foobar.txt

 

The exe here is a .Net 2.0 executable. The source is also there, so you can compile under your pet version of the runtime.  To compile

> csc enc.cs

 

And of course, it can encrypt any kind of file.

 

Download

 

Let me know if you want some simple switches/features added.

Wednesday, December 01, 2004 7:31:45 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
 Monday, November 22, 2004

Over the months I had slowly lost touch with Scheme, with so much happening in life. Today I saw some scheme code again and somehow just looking at it made me happy. Some kind of inherent simplicity in seeing those brackets and that indentation style – something vague familiarity of old friendship. It was weird.

 

No no, I am not cracking up and I am still a good old pure imperative languages programmer at heart and yes (Small talk guys please stand to the corner), I believe that C++ is a OO language and I still like .Net and C#. But all said and done, I think I like scheme – need to get back to some old scheming as soon as time allows.

 

Digressing - been musing about dynamic languages a bit more. The real reason I have not been writing too much about it is because of the feeling that I am going to sound stupid because I don’t know enough. I think I am going to let go of that and take the risk of looking foolish for a bit and start writing down things as I go ahead.

 

Here is a bunch of things that could/would fall under the general umbrella of the lose term – dynamic languages –

1)       closures

2)       iterators

3)       coroutines

4)       continuations

5)       mutable types

6)       typeless variables

7)       dynamic method dispatch

8)       eval

 

I don’t want to get into method dispatch and sub-classing mechanisms here, but I think the above is a general list. Any biggies I have missed? Lets see if there are any appropriate mappings we can find in the CLR and such.

 

The iterators and closures are solved problems – or atleast are largely solved problems in C# 2.0 (yes I know we can’t do ref variables – I think that’s ok for now – I will be happy if you have an answer)

 

There are solutions to most of the others lying around in one way or the other in Jim’s IronPython and the lesser loved Jscript.Net compiler that ships in source form with Rotor.

 

Does anyone know where I can find a readable description of how a scheme compiler (not interpreter) would work?

Monday, November 22, 2004 8:51:44 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

Dynamic Languages on the CLR – Part 1

 

Today I came across a paper written in 1996 at MIT that spoke of Dynamic Languages implementation on the JVM. The paper is an interesting read and pleasant because it isn’t dotted with arcane notational jing-bang and actually talks about real implementation issues.

 

The paper is written by Olin Shivers of MIT, interesting person – ha ha, actually this is the real link.

 

The first section address the issues of optimization of small scalar data types like integers which cannot actually afford to have dynamic lookup. The solution he proposes entails an assumption to be imposed on pointer types – so that small values can be held immediately rather than via indirection. For this purpose he recommends the addition of a type called an ImmediateDescriptor. I could not help smiling because this seems so much like a solved problem in the CLR of today – value types.

 

The second big issue that the paper brings is one of custom operations that a particular language may require that the runtime may not support. I don’t really have an answer for this. The paper goes onto compare this as being the inherent contradiction between RISC and CISC systems and adds the angle of safety of the end programming construct. This is by far a brilliant piece of thinking and these are the two suggestions primarily

1)       Build it up in API

2)       Enable the VM to have an extendable instruction set – similar to micrcodes in a processor

a.       Enable compilability of such new instructions by compiling to a lower level more RISC instruction set than the high level instruction set of the runtime…

 

I am hoping to offset this second part by not affording extensibility in the runtime and instead believing in some magical set of primitives. I don’t know about work that is actually being planned by the CLR team in this regard, I wonder what they are planning.

Monday, November 22, 2004 3:45:54 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 

It has been on my mind for a long time, to write about this – supporting dynamic languages on the most advanced runtime on the planet. I have been having this pet project on the back of my mind, and figured that I should probably write about it now. I was wondering how hard it would be to extend the CLR in a fundamental way to support dynamic languages – the idea here is not to add a whole bloat of features to the CLR, but to try and identify a set of primitive or simple rules/abstractions which when added to the CLR would enable implementation of dynamic languages efficiently on the CLR.

 

Why the CLR? Because the CLR is one of the fastest runtimes/VMs out there; it was inherently designed to run multiple languages; runs on a whole bunch of hardware and software platforms and has a very wide acceptance in the industry; it is an open standard that is not owned by any company; and there are atleast two publicly available implementations in source form – which means that it enables a language that previously had to lug along its own VM/interpreter to boldly go where no previous version has gone before.

 

Some smart languages like Groovy are doing this with the JVM. I was hoping for a while that Ruby would – but it turns out, after several mails on the Ruby mailing list that Matz the creator of Ruby, has other plans. Matz is writing his own VM for Ruby.

 

It looks like it’s a season for writing multi-language runtimes – head of the pack being Parrot, the new VM for Perl 6. There is of date, little or no information available about the actual architecture of Rite – ruby’s VM that Matz is working on.

 

What makes a runtime that supports dynamic languages different from runtimes that are built to support statically typed OO languages – I don’t have enough of a formal education or personal experience to answer that straight out. That is one of the things that I hope to teach myself in coming time. I can throw terms like dynamic method dispatch at you… but essentially I don’t know if I can nail it down to a set of fundamental primitives that make all the difference.

 

This is a blog entry about some of my early ramblings on the topic. I am hoping to teach myself some of the difference by looking at the opcode design for Parrot. I am expecting that there would be opcodes for runtime type lookup, runtime method invocation etc etc – does that solve the problem, I don’t know. It provides features that can be used to mitigate the problem, yes. In conjunction with studying the architecture of Parrot, I am hoping to compare and contrast that with what the CLR supports and see what is missing in the CLR. Again I am not expecting much to be missing – what I am expecting to be seeing be seeing is that a lot of what Parrot provides as opcodes, the CLR would not natively provide, but would instead be available as framework API.

 

There is another source – Jim Hugunin’s IronPython. Sometime early this year Jim Hugunin shocked the Python community and a large part of the dynamic languages world by implementing a python version that ran on the CLR – it was faster that the classical C Python. Jim previously was known for his Jython – a Python that ran on the JVM – but was a rather slow implementation. What Jim has essentially done is that he has written a bunch of libraries to augment what the framework provides and has used these liberally along with regular IL. Jim now works for the CLR team at Microsoft.

 

Once I think I have an understanding of how the Parrot opcodes makes it a better runtime for dynamic languages, looking at Jims work (which is openly available) should give me a good idea of what primitives can be derived and can be pushed into the CLR. That should be a good fun project to work on.

 

A lot of what I have typed would be plain common sense for someone who was actually following the field. A whole bunch of things are getting in the way of getting started, else I would have already.

Monday, November 22, 2004 3:44:47 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
 Saturday, November 06, 2004

To Neha, a good friend and an amazing singer,

I just loved the way you sang Bobby McGee the other day. It’s playing in my mind right now right now.

From the coalmines of kentucky to the california sun,

Bobby shared the secrets of my soul,

Standin’ right beside me through everythin’ I done,

And every night she kept me from the cold.

The somewhere near salinas, lord, I let her slip away,

She was lookin’ for the love I hope she’ll find,

Well I’d trade all my tomorrows for a single yesterday,

Holdin’ bobby’s body close to mine.

 

Freedom’s just another word for nothin’ left to lose,

And nothin’ left was all she left to me,

Feelin’ good was easy, lord, when bobby sang the blues,

And buddy, that was good enough for me.

Good enough for me and bobby mcgee.

 

 

 

The weather in Hyderabad is great these days. Maybe, the only time of the year when it is as pleasant.

 

I am upto reading 3 books in parallel these days and I wish I wasn’t because they are nice books.

 

One of them is called ‘The Naked Bachelor’ by Darrel Bristow-Bovey a hilarious collection of articles on how to get around. I highly recommend taking a look at this if you ever come across it. This book can always be read in parts and even has a certain Douglas Adams Hitchhikers quality to its humour in parts.

 

The other one is ‘A Homage to Catalonia’ by George Orwell. I am midway through this and the narrative is beginning to change flavor and I am reading it with much trepidation – the last time it was 1984 and it left me feeling that my ancient empty streets to dead for dreaming for a long log time. I still shudder.

 

The third is the eternal Fountainhead by Ayn Rand. (Yes Pooj, I finally picked it up, how could I not). I have just started by I have taken a liking to it already. Maybe I am heaping too large a compliment on myself, after 20 pages, what seems to be Howard Roark’s inherent functional perfection of buildings is seems close at heart to what I feel is the same way good software is built – not so much about UI as much as a comparison with architecture would imply – but about the beauty in which the functional pieces of the software come together inside; like Pirsig’s motorcycle.

 

Reading Fountainhead reminded me so much of A Separate Peace, a book that keeps coming back you to in thoughts in the most unexpected circumstances.

This picture is taken from the Philips Exeter academy’s page about The Separate Peace.

If there is a legal issue about the use of this picture please do drop me mail.

 

Saturday, November 06, 2004 9:25:08 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
 Friday, November 05, 2004

This is the sort of thing I have avoided writing about and thought I would not be, for a long time to come – I was afraid to too, mostly because I felt I would be able to or would get too involved in warding of the slack I would get for saying this. But reading this article that Sriram had linked to in his blog brought a mountain of stuff tumbling down. (I don’t know why I am so much into this software-ethical-stereotype thing these days, I have work to do you know). Before you go ahead and read the article linked above, here is what I have to say. This is not a long story, but one of those minor incidents that have stuck on to gnaw at my phsyche.

 

Rewind several years back to when I was in my second year of undergraduate studies. I had just got my first computer (yes) and Pooja had got hers. We didn’t really have internet connections those times, though we did have the modem and required hardware. We eventually figured that if we needed to talk to each other, we could use one of those direct modem-to-modem dialup software. After a lot of tinkering with dialup software and modem settings, we had something going that mostly worked for us. I had a copy of some old dos based software – I cant seem to recall its name – that we used to dialup each others computers and basically ‘chat’.

 

The software was the most reasonable one I could find for our purpose, but was however seriously limiting and got rather frustrating after a few weeks of use. God-geek-in-the-making that I believed myself to be those days, I figured that the only way I would get things to happen my way is by writing a modem communication software of my own. (I know what most of you might be thinking, but those days it wasn’t too surprising to see how often this particular approach was the panacea to all my ills).

 

Those days I also got a chance to talk to one of the few men who seemed to know everything, or atleast had a damn good idea about how to get to know the few things that he might have missed. I got a chance to talk to Jayakrishnan K about the modem’s idea that I had on my mind. JK would know about these things – he should because he had written Kerala’s first BBS (bulletin board service) by hand (as a couple of COM files on a DOS machine doing all the multitasking and all). A short discussion later, I had my head full of X-Modem, Y-modem, Z-modem etc and I was reasonably charged up. The error control would be hard, he had warned me, but that was ok.

 

So I got home and start off, eventually I figured that I probably wasn’t as smart as I thought I was. I was using intervue (Ralf Brown’s fabled Interrupt List (Ralf Brown is now Professor at CMU)) for reference. Somehow some things didn’t seem to make too much sense and I needed more information on how to initialize the modem correctly.

 

This is where GPL stepped in. I turned that in the pile of commonly shared source and software in the college students circles I had a piece of software that did modems communication. I wasn’t really sure what the full intent of the software was, but It has what I wanted – it had assembly code to initialize a modem and set all the settings and such. And being assembly code that manages a hardware device there weren’t too many ways about – you had to load some registers, write to some ports, call some interrupts etc in a certain fixed sequence of ways. Well if you are creative, you can think of several ways of accomplishing the equivalent of

Mov AX, 10

But that by itself didn’t mean that the code to initialize the modem would be written very differently by me, once I had seen how it is to be done. It also turned out that the software (as you would be expecting by now) was GPLed.

 

After the excitement of reading the ASM snippet I had a look at ‘COPYING’, the GPL text file. It seemed to me that if I were to use this piece of code from here to write my modems software to talk to Pooja the entirety of the code that I write would have to fall under the GPL license. It would not be my code anymore. Which is to say, that I would not be free to decide what I do with it – weather I sell it or hide it or share it – that choice would not be mine anymore. That was really disturbing for a while, because here I was wanting to write that piece of modems communications software to talk to a friend and I had a solution in hand, but there was nothing I could do about it – without subjecting myself to legal risk, had I written the software and shared it around without giving away my code. That was my first introduction to the viral nature of the GPL, though at that time the only word I could think of was ‘unfair’.

 

Then I figured that I probably needn’t tell anyone and I could write my software anyway. But then I wondered what would happen (with the notion of fame) that I had this famous piece of software and then one day someone realizes that I actually did have this piece of software on my hard-disk and then they would say that I stole this code illegally. This bothered me a lot because I like to think of myself as an ethical person and tend to get reasonably bothered by the converse. Immature as it may seem, I also wondered if no one could ever write modem’s communication software again.

 

And in time the feeling came to pass, and my code never got written and we used the same old piece of software until we bought ourselves internet connections and things blew over. I still wanted to know if there was a way out.

 

Years later when I had my first chance to meet Richard Stallman, founder of the Free Software Foundation and the GNU project and author of the GNU GPL, I wanted to know if there was a way for me. But in the passing time many other things were beginning to affect my thinking and I was beginning to be more bothered about the small programming communities and their spirit of unbounded sharing and coexistence with the commercial world that the rising tide of GPL acceptance seemed to be wiping out. I feared for those communities and I felt I was part of them.

 

When Stallman finally did come, he was visiting model Engineering College to talk about the danger of software patents – on his first ever visit to India. And then there were people there at the talk, who were asking Stallman how they could detect if someone has used GPLed code in their own software, maybe after modifying it. How they could track down these people and bring them to court. And there I was, wanting to ask the exact opposite – about how I could be protected for using GPLed code because there was no other obvious way to do something esp once you have seen one approach that solves the problem. The question about who protects the programmers.

 

My question never got asked.

 

People around me told me that my concern was unfounded. Things like that don’t happen. Nobody is bothered if you take from GPL code they said. Its just there to be a moral standard they said.

 

Last year, for some uncalled for reason, the topic came back again. This time over train ride home to Cochin from Bangalore when I was traveling with Sidharth. He didn’t see the problem and I was going on raving from the Karnataka border to Ernakulam railway station that its getting dangerous that there is so much GPLed code out there just lying around on the web, crawled by search engines and popped up at you without your ever intending. And if you took from these – copy paste from your browser that smart little three line snippet – you are strictly speaking, subjecting yourself to illegal usage of GPL code.

 

Over the years also I have developed this habit in programming when I am stuck I usually search the web for a solution. Maybe a smart little hack or a piece of advice on how to do something and I am chugging along smoothly again. After joining Microsoft two months back a few colleagues here advised me against doing this – you never know the legal implications of what you are doing they said. It seemed a little odd then, but then maybe I had been forgetting where I was coming from. I do use the web a lot – but now with this additional fear factor and layer of caution – and I wished I lived in a world where ‘freedom’ was a different, more real sort of freedom of choice.

 

Then I found this article : http://www.icsharpcode.net/pub/relations/amatterofinspiration.aspx

I do not know who is right and who is wrong in this debate, but I can empathize with the factors that caused it to originate. This is from the group that creates the rather well know .Net IDE called #develop – an alternative to VS and commercial IDEs and is often recommended to students…

 

I had been procrastinating making this post for some days now. Esp Chris Pratley’s words ring so close to my fears I've been a little gun-shy of blogging about Word for fear of being inundated by what are as far as I can tell a gang of "net thugs" who roam the net making...”. Hopefully this will be the last thing I need to have to say about this entire topic for a while. My blog is getting increasingly dedicated to writing stuff that I get dragged into rather than stuff I like getting into.

 

DO NOT hold this in perspective of my employer or any previous employer or any other context - these are purely my OWN OPINIONS done on my own steam and is not nor was ever was part of any job description of mine.

Friday, November 05, 2004 2:02:13 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]  | 
 Wednesday, November 03, 2004
  Redmond 

 

Pooja is in Redmond these days...

 

Wednesday, November 03, 2004 1:49:00 AM (Eastern Standard Time, UTC-05:00)  #    Comments [7]  |