Sunil Jagadish

Archive for the ‘.NET’ Category

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

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

Let’s Build A Compiler For The CLR

leave a comment »

Wow, only now I realized that Raj has mentioned my name in the context of his book which is titled – “Let’s Build A Compiler For The CLR“. Thanks Raj! His book is a wonderful piece of writing. Raj has struck a very nice balance between the geek-ness and simplicity. Do read it if stuff like Compilers fascinates you.

Written by Sunil

2007.03.09 at 08:34 PM

Posted in .NET, Programming

Windows Mobile 5.0 Emulator and Webservice woes

with 15 comments

Many people (including me) have faced the issue of connecting to a webservice from a Windows Mobile 5.0 emulator. The error generally encountered is- “Unable to connect to network”.

I was able to overcome this problem after learning from this post that I need to cradle1 the emulator and then deploy the application. Before you cradle the emulator, make sure you have a compatible version of ActiveSync running on your machine. Configure your ActiveSync to connect using DMA (because the intention is to connect to the emulator).

I used my desktop’s IP address (and not “localhost”, nor the machine name) to add the webreference (of the webserivce) in the mobile device project.

Rest of the steps in cradling the emulator is neatly laid out in this post.

Note:
1. To cradle your emulator, first connect to it using the Device Emulator Manager, only after which the “Cradle” option in the Actions menu will be enabled.

Written by Sunil

2006.11.24 at 12:59 PM

Posted in .NET

LINQ – Language INtegrated Query

leave a comment »

Language INtegrated Query (LINQ) is an extension to the capabilities of .NET languages (currently C# 3.0 and VB 9.0) to perform SQL-like operations on any source of data. The conventional data sources that we’ve been using today are databases, flat files, XML documents etc. LINQ defines certain standard query operators that enable set operations, traversal, projection, selection, join (the relational algebra stuff) to be performed on non-conventional sources of data, which is IEnumerable<T>-based. This means that you can use LINQ to query data from sources such as the enumeration of the list of processes running on your machine. I found this neat example here.

To get started with LINQ, you need to download the LINQ SDK (May 2006). I delivered a session on LINQ at the BDotNETStudent UG meet.

One of my demos included querying a String collection.

Code:

string[] names = {"Burke", "Connor", "Frank", "Everett", "Albert", "George", "Harris", "David"};
var q = names
           .Where(s => s.Length > 4)
           .OrderBy(s => s.Length)
           .Select(s => s);
foreach(var i in q)
           Console.WriteLine(i);

A simple query which selects those names from the collection which have a length greater than 4 and the same is then ordered based on the length of each string (in ascending order).

The output:

Frank
David
Burke
George
Harris
Connor
Albert
Everett

Here you’d observe that though “Burke” appears before “Frank” in the original collection, after the execution of the query, the order isn’t preserved. This is because; the OrderBy operator implements an unstable sort algorithm to order the elements.The subtle difference between OrderBy in LINQ and SQL is that, in case of SQL, a query like-

select * from tab_names order by len(sname)

would result in:

Burke
Frank
David
Albert
George
Harris
Connor
Everett

Links:

LINQ Project on MSDN
Download LINQ SDK
LINQ Samples
Anders Hejlsberg on LINQ [Channel9 video]
LINQ Intro

Written by Sunil

2006.06.04 at 11:50 AM

Posted in .NET, Programming

Visual Studio Power Toys and Code Snippet Editor

with one comment

I just completed a bluetooth demo for a Windows Mobile presentation that I'd doing at MSDN @ Campus, Coimbatore.

Code snippets is a very good feature which is helpful especially while doing demos. It is good to see the snippets wrapped within a neat XML schema. But, I thought it is slightly cumbersome to create a code snippet. The Powertoys blog has a pointer to a very cool tool – Snippy, which makes snippet creation quite simple.

Creating code snippets [MSDN]
Creating and Using Code Snippets in Visual Studio 2005 [4Guys From Rolla]
Code snippet XML schema reference [MSDN]

You can find some ready-to-use code snippets in GotCodeSnippets. It doesnt contain many snippets, but a cool initiative.

Written by Sunil

2006.01.19 at 05:46 AM

Posted in .NET, Programming

Web Services – Cool demo

leave a comment »

The other demo I showed during the launch of Microsoft Academic Projects was to demonstrate the web services. Though this demo may not have real business application, one will be able to guess the power of Web Services and its extensibility.

I setup my webcam at home and used TinCam, to dump images shot from the webcam into a folder at a given interval. I referred this article and used Binary Serialization to transmit the images from my PC to the Web Service consumer application which is a simple WinForms application.

A very simple application, but cool to watch. Download the source here.

Written by Sunil

2005.11.30 at 05:24 AM

Posted in .NET, Programming