Sunil Jagadish

Archive for the ‘Programming’ Category

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 Dev Live Beta launched

with one comment

When everything is going the Live way (Mail Live, Windows Live, Live Messenger etc.), why not something for Developers?

http://dev.live.com

Written by Sunil

2006.06.10 at 05:56 PM

Posted in Microsoft, Programming

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

Interesting numbers in the Windows Mobile 5.0 Device Emulator

leave a comment »

Check out Barry Bond's post about a few numbers in the WM 5.0 Device Emulator that can be used to test busy numbers, never answer numbers etc.

Written by Sunil

2006.02.06 at 05:57 AM

Posted in Programming

Windows Mobile 5.0 Message Interception

with 4 comments

I delivered a session on Windows Mobile programming with a focus on WM 5.0 in Coimbatore during the MSDN @ Campus event. I demonstrated a Bluetooth application using the 32feet API and Message Interception API in WM 5.0. I am reminded to point out that Peter Foot of the OpenNETCF fame, has separated a few APIs including the Bluetooth library into 32feet, which is worth noting for Bluetooth enthusiasts.

I have uploaded my demos here-

Bluetooth demo (scenario was communication between a PPC and a Desktop machine at a Pizza Company)
[Demo will be upload the shortly]

Download the SMS interception demo

The SMS Interception demo has inline documentation to help you understand its working.

/*
*
* ———————————
* Running the application
* ———————————
*
* 1. Make sure you have VS 2005 and Windows Mobile 5.0 PocketPC SDK installed
* 2. Run the application and use the Windows Mobile 5.0 PocketPC Phone Emulator
* 3. Click on the “Start” button to start the SMS Interceptor
* 4. This application will peek at all SMS’s received henceforth and process them
* if the SMS body is prefixed with the word “ASTRO”
* 5. Valid format for getting prediction: ASTRO dd-mm
* 6. Open the “Messages” in the PocketPC and create a new SMS, say, ASTRO 20-8
* (for 20th Aug) and send it to +14250010001, which is a fake number.
* Any Phone calls or SMS’s to this number is a reference to the emulator itself.
* 7. Once the SMS is sent, it appears in the list box. If it were to be an SMS
* without prefix “ASTRO”, the application will leave it to be read by the user.
* 8. This can be observed when the prediction is sent. This SMS lands in the Inbox.
* 9. To stop the Message Interception, click the Stop button
*
* More reading info on SMS interception API in WM 5.0:
* http://blogs.msdn.com/windowsmobile/archive/2005/07/09/437189.aspx
* http://www.pcquest.com/content/search/showarticle1.asp?arid=75833&mode=disp
*
* Windows Mobile 5.0 PPT – TechEd
* http://download.microsoft.com/download/9/f/a/9fadc29f-8df1-486f-b200-94f79ee7a7de/MED%20303%20New%20Managed%20APIs%20Controls,%20Messaging%20and%20Telephony.ppt
*
*/

I got mails from many people reporting a problem in downloading the code. So, I’ve uploaded it here – http://suniljagadish.googlepages.com/SMSInterception.zip

Written by Sunil

2006.01.30 at 05:53 AM

Posted in 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