False sense of security

Photo by public15


http://www.e-signature.com/ provides logo and signature embedded fonts. Per se, there is nothing wrong with the service, and is useful for people who need it.

However, a look at the website throws up the claims below. Each one has a quote from me below it on the truth behind the statement.

Imagine being able to distribute a signed word processing document to your staff or clients without fear of the logo or signature being copied…

DW: Even if the font is embedded, the logo/signature can still be copied and used on other documents. While this is not possible as a font letter, it can be done as a bitmap.

No embedding is the option most often selected for signatures as it ensures the highest security – the signature will only appear on computers that have the font installed. If you use signature fonts for signing checks, no embedding is also recommended.

DW: Please don’t use this for cheques. Its easier for someone to access your computer and steal the font than you think. The font will be installed on your PC and will remain there, its not something that you can carry on a pen drive and keep in lock and key.

The recipient does not have access to the font to reproduce it in another document nor can they cut-and-paste the on-screen signature or logo.

DW: Again wrong. It cannot be cut-and-pasted as a font letter, but can be done as a bitmap.

Keep your font proprietary. No one can copy your font because it will reside in an inaccessible cache on the browser. You can display your text the way you want without fear of anyone copying it.

DW: What’s an inaccessible cache? No cache is inaccessible – a smart user can always take your font away. Remember: if the browser can download it (and use it to show your content), a user can download it too.

It appears to me that these folks are very much aware that they are making statements that are not 100% truth. A false sense of security is worse than no security.


Oracle deadlocks: the what and the how

Everyone knows what a deadlock is: a situation in which two or more competing processes are waiting for the other to finish, and thus neither ever does. The purpose of this post is to help people understanding the deadlock a little better with a view to enable them to fix the problem when they find one.

Assume that there are two processes running, A & B and that they require a (shared) file and a printer to do their work. Process A locks up the printer, and Process B locks up the file for its own use. Now, none of the processes can complete because they do not have all the resources needed for their completion, and neither will they release the resource they have: they will keep on waiting for the second resource.

Let us create a deadlock now, using Oracle database and SQL Plus client.

We opened two sessions, and executed “set autocommit off” as the first statement.

Now in the first session we executed:

UPDATE ps_voucher SET grp_ap_id='A' WHERE voucher_id='00692096' AND invoice_dt='2-JAN-2002';

second session:

UPDATE ps_voucher SET grp_ap_id='A' WHERE voucher_id='00692096' AND invoice_dt='13-MAR-2007';

back to the first:

UPDATE ps_voucher SET address_seq_num=2 WHERE voucher_id='00692096';

and then the second:

UPDATE ps_voucher SET address_seq_num=2 WHERE voucher_id='00692096'

BAM! Deadlock. See screenshots:

Deadlock - Session I
Deadlock - Session I
Deadlock - Session II
Deadlock - Session II

What went wrong? There existed two vouchers in the system, with the same VOUCHER_ID but with different INVOICE_DTs (invoice dates). Each process first locked up one of those vouchers, and then – as the second UPDATE – tried to update both. (On the database side, a process gets a lock on a specific row when it UPDATEs that row, and the lock is released when the process COMMITs or ROLLBACKs.)

Yes, the programmer could have been smarter and written better code: if he had put the INVOICE_DT clause in the second statement also we would have been fine. However, in practice, with huge systems having tons of code – programmer will sometimes make mistakes. Even if they do not, deadlocks will occur: not all deadlocks are caused by SQL issues.

From a system design perspective, what can be done to prevent deadlocks? One way is for the execution of each process to have a unique ID – let’s call it process instance (PI). So if a process ABC is run once, it will have a PI of 1222 and when it’s run next it will have a PI of 1224. If, after this process PQR is run, it will have a PI of 1223. Before changing any transactions, the process can update it own PI on the transactions that qualify:

UPDATE ps_voucher
SET pi=1223
WHERE <process specific selection criteria>
AND pi=0;


The commit here is important – only then will other processes be able to see the ‘locking’.

Thereafter the normal processing SQLs can be changed as below:

UPDATE ps_voucher
SET grp_ap_id='1'
WHERE <process specific criteria>
AND pi=1223;

At the end, set the transactions back to ‘open for processing’ by setting PI to zero:

UPDATE ps_voucher
SET pi=0
WHERE pi=1223;

If there are other ways to achieve this, please let me know by posting comments.

The DBA is usually able to specify the SQL queries involved in a deadlock. Many times one process is UPDATing the rows that the other is DELETing.


Making letter portraits

Manmohan Singh letter portrait
Having been impressed by letter portraits (see right), I wanted to figure out how to do them myself. In addition, I have shown you a lot of my own photos on this blog, without making the readers any wiser on how to do stuff. Better late than never, they say – so lets get started.

Choose a photo that you want to convert. Not every photo is a good candidate: the photo should be simple, not having a lot of detail. A bigger size say 640 x 480 should be available, and should have some contrast. For the purpose of this tutorial we will use this tree:


The result may not look very good because the photo does not have a unique recognisable shape, but will work fine for this tutorial. You may want to try yourself with this better photo of Indian PM Manmohan Singh:

Manmohan Singh

Step 1 is to open a word editor and type (or copy!) some text into it. It looks best if the text is related to the person whose photo portrait you are making. Times new roman font is preferable, Size 14, Bold. Set the zoom to 70% for good results. Take a screen print using Alt-Print Screen key on your keyboard, and bring into Photoshop. The result looks something like this:


Now crop to retain the text, and copy-paste multiple times to achieve the size you need.

Moving over to the main photo (the tree), go to Window->Show Channels. Click on each channel one by one, and see which one has the highest contrast. Retain that one, and delete the others:


Now click on Image->Mode->Grayscale and then on Image->Mode->RGB.

Finally, when your two photos are exactly the same size, drag the text over the main photo – or copy paste as a new layer. The photo with the text should be on top and the other below.

Now go back to Window->Layers, and from the blending mode (upper left corner where it says Normal), select Screen. Things should look like this:


Flatten the image by going to Layer->Flatten Image.

What you want to do after this is up to you. You may want to do Image->Adjust->Threshold for complete B&W look. For, as for example with the PM photo above, you may need to do some cleanup using the Eraser tool for a ‘clean’ look.

If all this is too much work, being a lazy person like me – try this website: http://lunatic.no/img2aschtml.php.
Upload a photo, and it creates a colored text portrait. Its beautiful and you can choose the characters. Take a screenshot (using Alt-Print Screen) of the result and crop in Photoshop, to save as an image.

If something is hard to follow, please post in comments and I will simplify. The Manmohan Singh photo is by ‘ahinsajain’.


Ozymandias – the king of kings

King of Kings
King of Kings (photo by Charlie Phillips)

The frequency of postings having gone down a bit, the readers may be wondering what I am up to. I am preparing for the first anniversary of this blog.

Today I want to share with you a second poem that has persisted in my memory since school days – the first one having been Twenty Froggies. The name is Ozymandias and was written by Percy Bysshe Shelley in a competition with Horace Smith. The poem is below:

I met a traveller from an antique land,
Who said — “two vast and trunkless legs of stone
Stand in the desert … near them, on the sand,
Half sunk a shattered visage lies, whose frown,
And wrinkled lips, and sneer of cold command,
Tell that its sculptor well those passions read
Which yet survive, stamped on these lifeless things,
The hand that mocked them, and the heart that fed;
And on the pedestal these words appear:
My name is Ozymandias, King of Kings,
Look on my Works ye Mighty, and despair!
Nothing beside remains. Round the decay
Of that colossal Wreck, boundless and bare
The lone and level sands stretch far away.”

The competing entry was (and this one is also nice, but presents a slightly different field of view):

In Egypt’s sandy silence, all alone,
Stands a gigantic Leg, which far off throws
The only shadow that the Desart knows: —
“I am great OZYMANDIAS,” saith the stone,
“The King of Kings; this mighty City shows
“The wonders of my hand.” — The City’s gone, —
Nought but the Leg remaining to disclose
The site of this forgotten Babylon.

We wonder, — and some Hunter may express
Wonder like ours, when thro’ the wilderness
Where London stood, holding the Wolf in chace,
He meets some fragments huge, and stops to guess
What powerful but unrecorded race
Once dwelt in that annihilated place.

The message the both convey is simple: Time is bigger than any and all of us. For the believers, it also means that God mocks your pride.