Skip to main content

Posts

Generating UUID in Jython

I have been poking around STAX/STAF recently and I found a need to generate UUID or GUID in Windows. I tried uuid module in CPython but I can't call it inside my STAX job. I tried to create STAX process but I noticed that if the program is under heavy usage I cannot guarantee that the STAX process that runs the CPython gets the resulting UUID string. Since STAX is using Jython, I reasoned out that this should be possible in Java. A quick search in Google shows java.util.UUID. This class is just what I need. So, basically, in Jython I can generate a UUID using the following command: import java print java . util . UUID . randomUUID () ~ts~

Generate universally unique ID in Python

In my previous post, I discussed how to generate GUID (Windows world) or the standard equivalent UUID to generate a guaranteed unique identifier from Python. I didn't know that their is a CPython library that can do this in a more platform neutral way. Just today, I came across the module uuid. uuid is now part of the standard Python library but as to when, I am not sure. One thing I am certain, it is there in Python 2.5.1. Below is a sample code to generate a UUID version 4 . import uuid print uuid . uuid4 () If you want to know more about UUID and the standards using it, please pay a visit to Wikipedia - UUID . ~ts~

Getting PUTTY to draw line correctly

This is a shameful direct copy of the information from this link . To make it all work right, you need to twiddle the following configuration settings: Terminal → Keyboard: Change the sequences sent by: The Functions keys and Keypad: Select Linux. Window → Appearance: Font settings: Pick a font that contains the Unicode line drawing characters, such as Andale Mono or Lucida Console. (Unfortunately Vista’s gorgeous new Consolas font does not have those.) Window → Translation: Character set translation on received data: Select UTF-8. Adjust how PuTTY handles line drawing characters: Select Use Unicode line drawing code points. Connection → Data: Terminal details: Terminal-type string: Enter “linux”. Now line drawing characters should show up as they are supposed to. ~ts~

Generate GUID in Python running in Windows

GUID can be useful as a primary key for a databases and also for the records or rows of data that needs to be unique. There are a lot of tools that can generate a GUID but in this quickie blog, I am documenting how to generate a GUID using Python in Windows. To generate a GUID, import the code below: import pythoncom _guid = pythoncom . CreateGuid () _guid_str = str ( _guid ) print "%s GUID is %d long" %( _guid_str , len ( _guid_str )) ~ts~

Grab screen capture programatically

Pre-requisite: Python 2.5 for Windows Python Imaging Library ( PIL ). Install Python 2.5 for Microsoft Windows. Make sure that you have administrative rights to be able to install the application properly. After having verified that Python is installed and working, install Python Imaging Library. See below for a sample of screen capture python script. #--<-start code here->-- import ImageGrab ; img = ImageGrab . grab () img . save ( "D:\\test.jpg" ) #--<-end code here->-- ~ts~

Detecting the process using/locking a file

In Windows, if a file is being used, normally user cannot delete it. But there are cases, especially during development and/or troubleshooting, where a file needs to be deleted or renamed. The issue here is that deleting a locked/used file is not allowed in Windows. Windows Explorer does not give even a slight hint as to who has the lock on the file. Fortunately, Mark Russinovich of Microsoft , developed a tool to list the process that is having a lock on the file. The name of the tool is "handle" and can be downloaded from the site . If you have a file readme.txt and you want to delete it and for some reason their is a rouge application getting hold of it. To get the process name of the application that's using it, just issue the command: handle readme.txt ~ts~