Sunil Jagadish

Archive for July 2007

CAPTCHA Generator for .NET

with 5 comments

I needed a CAPTCHA generator for some stuff I’ve been doing. I looked around and did find some assemblies for .NET. I thought of coding my own CAPTCHA generator and decided to do this using C#. The result – You can download/contribute here. You can even download a sample usage of this in a Windows Forms application form the “Releases” section. This can even be used in ASP.NET applications. This assembly will need permission to write to disk (to store the CAPTCHA image generated).


Usage

using CAPTCHA;
CaptchaGenerator cgen;

Single custom coloured CAPTCHA
cgen.CaptchaColor = Color.FromArgb(130, 120, 130);
CaptchaText = cgen.GenerateCaptcha(@”G:\test1.gif”);
pictureBox1.ImageLocation = @”G:\test1.gif”;

Captcha2

Default Random Coloured CAPTCHA
cgen.ResetCaptchaColor();
CaptchaText = cgen.GenerateCaptcha(@”G:\test1.gif”);
pictureBox1.ImageLocation =
@”G:\test1.gif”;
Captcha1



Advertisements

Written by Sunil

2007.07.25 at 07:26 PM

Posted in .NET

Anagrams

with 3 comments

What is an anagram?

Problem: Given a file containing words, re-arrange it such a way that all anagrams appear consecutively.

Example:
Given,
dcba
pqrs
zyx
cbad
xyz
sqrp
abcd

The result should be:
abcd
cbad
dcba
pqrs
sqrp
xyz
zyx

Here is a simple Perl + unix command line which does the job:

#!/usr/local/bin/perl -w

use strict;

open(INP,$ARGV[0]);

while(<INP>) {
   chomp;
   my $sig = join ”, sort split(”,$_);
   print “$sig\t$_\n”;
}

Command line: ./anagram.pl ip.txt | sort | awk -F’\t’ ‘{print $2;}’

Technique: Every word is associated with a signature. Here, a signature is nothing but the word with all the characters in it appearing in sorted order.

Here is how it looks:

abcd    abcd
abcd    cbad
abcd    dcba
pqrs    pqrs
pqrs    sqrp
xyz     xyz
xyz     zyx

Then, awk -F’\t’ ‘{print $2;}’ simply prints the original words (column 2).

Written by Sunil

2007.07.18 at 12:47 PM

Posted in Algorithms

Click-O-Matic

leave a comment »

I’ve been downloading software from my MSDN Subscription account. MSDN provides a custom download application which (un)fortunately does not have the feature to schedule downloads to begin at a particular time. Also, I’m not allowed to use DAP or any other download accelrator to download from MSDN. Sharath had pointed me to this sometime back. PTFB is a trial version software, so, here is a free version of a similar (but much more simpler, lesser features & less jing-bang) application which does the same job. I’ve called it Click-O-Matic (for the lack of a better name :-))

A “just-works” version is ready. In case you are intrested to use this, leave a comment here with your e-mail ID and I can mail the setup file to you.

For the geekier ones here, I wrote this in C# using simple PInvoke to simulate the mouse clicks.

Written by Sunil

2007.07.18 at 11:54 AM

Posted in .NET