Random Quotes using ASP.NET and XML

Saturday, October 27, 2007

I recently created a random quotes generator to be put up on my website. The code could be used to produce any random text on your website, where the text is defined in a XML file.

The following is the XML file for use with the code:

<?xml version="1.0" encoding="utf-8" ?>
<quotes>
<quote id="1">
<text>sample quote</text>
<author>sample author</author>
</quote>
<quote id="2">
<text>another quote</text>
<author>another author</author>
</quote>
.
.
<quote id="15">
<text>yet another quote</text>
<author>quote author</author>
</quote>
</quotes>
Save this file as quotes.xml in your ASP.NET project. Now open the page where you would like to place these random quotes. Create 2 labels in the page design with ids 'labelquote' and 'labelquoteauthor':

<asp:Label ID="labelquote" runat="server"&rt;</asp:Label&rt;
<asp:Label ID="labelquoteauthor" runat="server"&rt;</asp:Label&rt;


Now, add the following code to the 'Page_Load' method of this page:
string strquote;
string strquoteauthor;
Random r = new Random();
int random = r.Next(1, 15);

XmlTextReader reader = new XmlTextReader(Server.MapPath("quotes.xml"));
while (reader.Read())
{
if (reader.Name == "quote" &&
reader.GetAttribute("id") == random.ToString())
{
while (reader.Name != "text")
reader.Read();
strquote = reader.ReadElementContentAsString();
while (reader.Name != "author")
reader.Read();
strquoteauthor = reader.ReadElementContentAsString();
}
}
labelquote.Text = strquote;
labelquoteauthor.Text = strquoteauthor;
In the above code, the while loop reads all the lines of the Xml file and the quote having the specific random id is displayed.

You can also, make a user control from this code which you can add to each page or the master page of your website.

Web-o-cabulary 2.0

Monday, October 22, 2007

With the augmentation of Web 2.0 technologies, a whole new technical jargon has evolved. Internet users are glutted with new terms and wonder about their meanings. So, here's a list of the 'Most Essential Vocabulary for Web 2.0' or 'Web-o-cabulary 2.0'.

AJAX: Asynchronous JavaScript and XML is a scripting technique to develop interactive and fast web applications with enhanced functionality. The most commendable feature of AJAX is its ability of partial exchange of data with the server, enabling the changes to appear on the browser without reloading the complete page.

API: Application Programming Interface is a code interface over which programmers can built their own applications. APIs make it possible for the programmers to use some great features on the web without any complex coding. Some commonly used APIs include Windows Live APIs for Maps, Rich Media, Photos, Search

Atom: Atom is a commonly used syndication format for web feeds. It is based on XML and is supported by most standard feed readers.

Blog: Blog or a Weblog is an online journal, which provides an easy to use interface for users to publish content. Blogs enable people to have an online presence without having any technical knowledge.

CSS: Cascading Style Sheets is a W3C standard for defining styles of the elements on a web page. It enables the separation of content from the layout, thus providing more flexibility and control of the elements on a web page. Also, it enables layering of the content on the page.

Feeds: Feeds allow you to get updates from the websites. It allows you to check the recent articles and content from web pages on the internet. A person may subscribe to a news feed to get the latest news right on his desktop.

Folksonomy: Folksonomy is the practice of collaboratively categorizing content by tagging the content under various connotations. This method is popularly applied in social bookmarking and tagging webpages and photos.

Mashup: Mashups are a interactive genre of web applications which accumulates data from various sources and conflates it in a single integrated application. Mashup generally collects data from Feeds and Web Services.

Microformats: Microformats are a set of simple open data formats, which allows the normal data in HTML and XHTML to be categorized by providing annotations in the existing markup. It aims at easier access of information such as contact addresses, locations etc making it easily placeable by the searching softwares.

Perpetual Beta: Perpetual Beta is the software stage where the software is launched and is always under constant updates, which could be monthly, weekly or even daily. It follows the principle of "release early and release often", thus a software is released at a premature state and new features are added frequently.

Podcast: Podcast is a form of a feed carrying digital media files which could be downloaded or streamed on media players. Online radio is a well comprehensible example of a podcast.

RSS: Really Simple Syndication is a collection of feed formats. It is used to syndicate updated content from a website.

SEO: Search Engine Optimization is a process of improving your rankings on the search engines by using a set of techniques, which include ameliorating the quality of content and code of the website, placing links at strategic locations on the web and adhering to some web standards.

Silverlight: Silverlight is a Microsoft technology to develop Rich Internet Applications, which run on browsers by downloading a small plugin. It provides enhanced user-experience and media functionalities and is a strong competitor of the Adobe Flash. Silverlight is a subset of Windows Presentation Foundation of the .NET 3.0 framework and is coded using XAML.

Social Bookmarking: Social Bookmarking is a folksonomy practice through which users bookmark pages on the web and create custom tags to annotate these pages.

Social Networking: Social networking is a method to promote online collaboration of people by creating communities of (net)citizens with similar interests. It is a popular method to connect with friends online.

Tagging: Tagging is a practice of annotating the web content by creating tags or keywords to identify them. Also see: Folksonomy

Weblog: See: Blog

Web Service: Web Services are the modules enable a programmer to use these modules in their programs without actually coding them. It allows machine to machine data transfer between applications in XML format that follow the SOAP standard.

Wiki: Wiki is a web application which allows you to easily create and edit content on the web. It is used to create collaborative websites and is a great tool for social content creation and organization.

XAML: eXtensible Application Markup Language is a declarative XML-based language by Microsoft. It is a markup language enabling greater collaboration between designers and developers by providing a common platform for both.

XHTML: eXtensible HyperText Markup Language is a standard W3C markup language, which is a reformation of HTML adhering to the XML standard.

XML: eXtensible Markup Language is a markup language which allows users to generate their own tags. It enables creation of structured data that could be easily exchanged over the web.


Note: As most other stuff of Web 2.0, this list is also in the 'perpetual beta' state. This list is bound to future enhancements and modifications.

TechVista New Delhi 2007

Saturday, October 13, 2007

TechVista, Microsoft Research(MSR) India's annual research symposium, was a splendid event held today at New Delhi with focus on "Computing and Technology- Shaping the Future". Six magnificent scientists from diverse technology domains came under one banner to present some of the most marvelous research and developments in computing.

The first session of the event started with a talk by Dr. Rick Rashid, Sr. VP, Microsoft Research. Dr. Rashid's presentation was titled "10 Years into the Future". He started by showing some of the science fiction gadgets which are now real, like the data crystal is now a memory stick. He also displayed the concept of Wallet PC as it was in 1999, which we are using now as Windows Mobile. Rick showcased some of the cutting-edge research projects which would have an impact on the world by 2017. He apprised the advances in ubiquitous I/O and predicted that the standard white boards may soon be replaced by LCD boards. He demonstrated the SkyServer, which is a fabulous astronomy tool enabling you to view space as you view earth from Google Earth or Live Virtual Earth. It also enables you to create video tours of the the space. Other projects demonstrated in the presentation were SenseCam, a virtual black box for humans; Digital Photomontage, a superb tool for photo morping; and a traffic monitoring system in Seattle using data mining for streaming intelligence on mobile devices.

The next speaker at session one was Prof. Eric Grimson of MIT who presented his study on "Computational Applications in Medicine". He showed how image guided surgery could be performed using some advanced computational methods. He explained the construction of structural models using AI. He demonstrated the improvements in MRI technology and Enhanced Reality Visualization.

The last speaker of session one was Prof. Krithi Ramamritham from IIT Bombay. His presentation was "LAB<- ->FIELD : A Challenging Journey". He presented a project named 'AQUA' which is an acronym for 'All QUestions Answered'. It is a project where farmers can get all their questions answered by experts through an online system supported by Government agencies. AQUA features cross lingual info retrieval, suggestive search, offline and mobile versions. Prof. Ramamritham demonstrated how the research at lab went to the field and how the requirements from the field came back to the research labs, which again went to the field and a vicious circle followed.

Session one was followed by a Special Session by Mr. Kapil Sibal, Mr. Craig Mundie, Dr. Rick Rashid and Mr. Srini Koppolu. In this session, Dr. Rahid demonstrated another fabulous software - PhotoSynth, which allows you to create a 3D view from multiple ordinary pictures. Mr. Craig Mundie, Chief Research and Strategy Officer, Microsoft Corporation presented some advancements in computing and showed how the computing pendulum is moving towards multicore processors and software+services technologies. Mr Kapil Sibal, Union Minister of Science & Technology and Earth Sciences, appreciated the technologies and suggested how these could be used in public projects in India. Mr. Srini Koppolu, Managing Director, Microsoft IDC gave a small talk about Microsoft in India. This session was followed by PhD poster presentations, where some great research work was presented by Ph.D. fellows.

Session two started with the presentation of Prof. Manuela Veloso, CMU on "Multi-Robot Intelligence". She demonstrated how multi-robots are programmed STP (Skills, Tactics and Plays) Behavioral Architecture. She discussed details about her research project, CMRoboBits. She also gave video demos of the robots which were programmed using some complex algorithms. This was, no doubts, the most exciting presentation of the day.

The next presentation was by Dr. Tony Hey, Corporate Vice President of External Research, Microsoft Research on "The Role of Computing in the Sciences". He demonstrated how advanced computational technologies can solve the problem of data deluge faced by most scientists. He explained that the key steps for information management are data collection; data processing, analysis and visualization; and archiving. He exhibited the use of mashups and eResearch benefiting the scientific community.

The last speaker of the day was Dr. Michael Kass, Senior scientist, Disney/Pixar and technical Academy award winner. His gave presentation on "Pixar's Production Process" and "Clothing Animation at Pixar". He discussed the details of the animation movie production process at Pixar. He then presented Clothing Animation technologies for which he had also won an Oscar.

In the end, MSR presented rewards for the PhD poster presentation. Overall, TechVista was fabulous event showcasing some of the most cutting-edge research and developments.

Add a Google Map to your Website

Monday, October 08, 2007

I recently used Google Maps API on my college website. It was somewhat tedious to read the API documentation and figure out how to code a simple map. So, here I'm writing a basic tutorial for adding a location map on your website.

Start by signing up for an API key. Go through this "Hello World" example of the Google Maps API. For a start, copy this code and run it. The first thing you would need to modify is the following:

map.setCenter(new GLatLng(37.4419, -122.1419), 13);
You would need the latitude and longitude of the desired location. To find out the coordinates of your desired location use the Google Map Search, go to your desired location and right click on the directions option to find the coordinates. The second argument (13) specifies the zoom level of the map.

The above code would produce the map of the desired location on your browser screen. Now lets see how to add-on some features on your map.


Adding an Info Window
:

An info window is a call-out text from a particular location. To add an info window, just add the following line of code in the initialize() method:
map.openInfoWindowHtml(map.getCenter(), "any html formatted text here");
You can also add tabbed info windows, which I'm not discussing here to keep this tutorial simple.
Class Reference: GInfoWindow, GInfoWindowTab


Adding Controls:

Controls are a set of buttons which allow you to perform specific functions. To allow users to switch between different Map Types, viz. Map, Satellite and Hybrid; use the following statement in the initialize() method:
map.addControl(new GMapTypeControl());
You can add various other controls to the Map. To view the complete list of available controls, view the class reference.
Class Reference: GControl


Adding a Marker:

A marker is used to mark a position on the map. For adding a marker on a specific point add the following lines of code in the initialize() method:
var point = new GLatLng(28.631749, 77.116578);
map.addOverlay(new GMarker(point));
The above code places a marker on the desired point. You can also define a custom image as a marker using the GIcon class.
Class Reference: GMarker


These are just a few of the features of the Google Map API. These would be sufficient if you are planning to implement a simple location map on your website. For more advanced features of the Google Maps API, refer to the API Documentation.

Generate ASCII Art from Images

Monday, October 01, 2007

Here's an interesting code in C# which allows you to generate ASCII Art from your usual text images.

First a sample:
The above image is produced using normal ASCII characters. It is generated by a C# code written by Matt. The code renders an image by displaying a set of ASCII characters on the screen.

This ASCII art is reminiscent of the antediluvian DOS-like programs which created on-screen images using normal text. This code could be handy for people who like to create images for SMS-text messages.

You can download this code from here. Unzip the files, copy them to a New Website in Visual Studio and compile it to run.


Here's another sample generated from this code:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@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@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

The image above is displayed by repeatedly using the '@' character of varying colors (you can verify it by copying the above image and pasting it on Notepad).

Tip: Try playing with the font-size and line-height properties in the CSS file to adjust the image size and sharpness.