Sunday, January 11, 2009

Updated to Windows Live Writer 2009

Updated to live writer 14 which is part new live update pack.

Notable changes

1) Preview

2) Segeo font

Friday, January 02, 2009

Friday, December 26, 2008

Get hosting environment

My friend asked:
What is easiest way to get to know about type of web server?

Why not with our age old friend 'telnet'?

==============================
[harsha@JD11AF08 ~]$ telnet sriharsha.net 80
Trying 75.126.232.124...
Connected to sriharsha.net.
Escape character is '^]'.
GET / HTTP/1.1
Host: sriharsha.net

HTTP/1.1 200 OK
Date: Fri, 26 Dec 2008 16:36:23 GMT
Content-Length: 573
Content-Type: text/html
Content-Location: http://sriharsha.net/Default.htm
Last-Modified: Sat, 03 May 2008 10:52:12 GMT
Accept-Ranges: bytes
ETag: "72b52dbebadc81:20844d"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET

....................

==============================

Same thing can also be obtained with HEAD
HEAD / HTTP/1.1
Host: sriharsha.net

Tuesday, December 23, 2008

CLR version on client

Click once deployment requires CLR to be present on target machine to verify manifest. Following snippets help in detecting the same.

Snippets work with IE5+ and Firefox 3+ only. They fail with Chrome.

Server Side:

protected void Page_Load(object sender, EventArgs e)
{
bool clrOK = Request.Browser.ClrVersion > new Version(3, 0);
if (clrOK)
Response.Write("CLR Version : " + Request.Browser.ClrVersion);
else
Response.Write("This machine does not have Microsoft .NET Framework version 3.5 SP1. Install and try again.");
}



Client Side:



<script type="text/javascript">

function
DetectCLR(targetVersion) {
//Gets CLR version on IE5+ and Firefox 3+
var uagent = navigator.userAgent;

//Form regular expression
var clrRegExp = new RegExp(".NET CLR \\d.\\d.\\d{5}", "g");

//Get Matches
var clrversions = uagent.match(clrRegExp);

//Is CLR present
if (clrversions == null)
document.write("Please install Microsoft .Net Framework 3.5 SP1 and try again");

//Possible .NET CLR versions for v2 and above
//.NET CLR 2.0.50727
//.NET CLR 3.0.04506
//.NET CLR 3.5.21022
//.NET CLR 3.5.30729
var arraylength = clrversions.length;
var clrversiondetected;
for (var i = 0; i < arraylength; i++) {
//document.write(clrversions[i] + "</br>");
clrversiondetected = (clrversions[i] == targetVersion);
}


if (!clrversiondetected)
document.write("Please install Microsoft .Net Framework 3.5 SP1 and try again");
else
document.write("CLR Version : <b>" + targetVersion + "</b>");

return clrversiondetected;
}
</script>

Saturday, December 20, 2008

BOSS Linux - Bharat Operating System Solutions

I just came across BOSS.

BOSS (Bharat Operating System Solutions) GNU/Linux distribution developed by  C-DAC (Centre for Development of Advanced Computing) derived from Debian for enhancing the use of Free/ Open Source Software throughout India. BOSSGNU/Linux - a key deliverable of NRCFOSS has crossed another milestone by releasing version 3.0. BOSS GNU/Linux Version 3.0 is coupled with GNOME and KDE Desktop Environment with wide Indian language support & packages, relevant for use in the Government domain. Currently BOSS GNU/Linux Desktop is available in almost all the Indian Languages such as Assamese, Bengali, Gujarati, Hindi, Kannada, Malayalam, Marathi, Oriya, Punjabi, Sanskrit, Tamil, Telugu, Bodo, Urdu, Kashmiri, Maithili, Konkani, Manipuri , which will enable the mainly non-English literate users in the country to be exposed to ICT and to use the computer more effectively.

Friday, April 11, 2008

How to access explicit interface methods from another method

Explicit interface methods are prefered to instance members for following reasons

a) They are accessible only through interface

b) They support multiple levels of inheritance chain

Some insight. Take this example.

a) Take simple console application

b) Add an interface

c) Implement interface

d) Create Object of the class and try to access interface method

e) Cast it with interface and access

f) Call another explicit method method

g) Call another explicit methos by casting this object with interface

using System;
using System.Collections.Generic;
using System.Text;

namespace ClassMonitorLibrary
{

public class Program
{
//Entry point
public static void Main(String [] args)
{
#region Not accessible directly
//Object is accessible
//IFile im = (IFile)(new InterfaceMethods());
#endregion
InterfaceMethods im = new InterfaceMethods();
im.GetFile("Data.txt", 10);
}
}

//Simple interface
interface IFile
{
bool GetFile(string fileName, int length);
bool IsFileExists(string fileName);
}

//Interface implementation
class InterfaceMethods : IFile
{
bool IFile.GetFile(string fileName, int length)
{
#region how to access method
//if (((IFile)this).IsFileExists(fileName))
#endregion
if
(IsFileExists(fileName))
Console.WriteLine("FileExists");

return true;
}

bool IFile.IsFileExists(string fileName)
{
return true;
}
}
}

Tuesday, March 18, 2008

Saturday, March 15, 2008

Vim settings

Back up and swap files that vim creates are sometimes frustrating; that too when you are working on source tree in version controlled directory.

Setting them off is desirable for such environments. Today I updated my Vim profile to do this and also found consolas font more appealing font for Vim editing on windows. Just thought of sharing profile file if anyone else interested in it.

 C:\Program Files\Vim\_Vimrc file 

set nobackup "Set off backup files"
set noswapfile "Set off swap files"

"Fonts"
set guifont=Consolas:h12:cANSI

"Tabs"
set stal=2

"GUI Options"
set guioptions-=T "No Toolbar"
set guioptions-=r "No right scroll "
set guioptions-=m "No menu "

"Color scheme"
colorscheme wombat "tried zellner, now wombat suits me best"

Friday, March 07, 2008

MsMUG Survey

AutomationFederation.org is conducting and online survey on Issues in the Manufacturing Environment.

Survey results will be published in Microsoft's forum.

During April 2-4, 2008, Microsoft will be hosting a forum specifically addressing issues in the Manufacturing environment. The Microsoft Manufacturers User's Group (MsMUG) has been working side-by-side with Microsoft in preparation for this event.

Monday, January 21, 2008

Visual Studio Task List feature - I regret for not knowing this earlier

Do you use Visual studio's Task List? Atleast I was't using it so far and I regret for not knowing this earlier.

How it works

It works like this, you might want to do something at code at later point in time, just add a comment in this syntax

//TODO: Add exception handling here

or you are doing code review and felt a message should have been logged here just add a comment like this

//LOG: recursive function, log depth of stack

or you might have felt a method has grown too big, it must be refactored, just add a comment where ever you felt like

//REFACTOR: break this part as a function

How to access

And visual studio has a window to search for all these comments and present them in a list.

To show task list select from View -> Task List

By default it shows user task, select for comments from combobox.

How to customize

You can set more tokens from Tools -> Options Check in image here. TODO, HACK, UNDONE and UnresolvedMergeConflict are default tokens in visual studio. I added LOG and REFACTOR.

Check how a

TODO: Clean up and Log Something in code is shown with. And it is a clickable target

Also you can sort all log messages or TODO's to attend once.

Also you can define user defined tasks too.

For that select User tasks option in Task List and add your taks.

I felt the option very handy and felt like sharing it.

Unit Testing for Native Code

As I am spending most of time in CLR sandbox these days, I couldn't realise that NUnit can't work for native code. But that is a bit disappointing, having spent those many years developing C++ code, I couldn't accept flag go down. YES there is a Unit testing framework available for native C++ too. It is called WinUnit and MSDN Febraury 2008 article Simplified Unit Testing for Native C++ Applications describes the details.

Salient features are

a) Its built as a regular C++ dll

b) You can run it from Command Line by passing dll name as argument to WinUnit.exe

c) You can integrate with Visual Studio Build process, so whenever you build the project Unit Tests are performed

Compared to NUnit:

a) It lacks UI

b) Lacks report generation features

Friday, January 04, 2008

xcerion XML internet OS/3


Today I got my beta account for xcerion. First impression is "it is awsome", but doesn't work in firefox.

It works only with IE 6 or 7 on windows. Its an xml based web operating system. Applications are developed using Model View Controller framework.

Though it is not from big giants like Microsoft and Google, it paved a way towards it. It may not be adapted in low bandwidth environments, though there is an offline feature.

Tuesday, January 01, 2008

HAPPY NEW YEAR - 2008

Wish you and your family a very Happy, Prosperous and Cheerful Newyear 2008.

Wednesday, November 28, 2007

Midlets using MotoDev Studio

MotoDev Studio is a new IDE platform to develop J2ME applications for Motorola phones.

I just did a basic test using this.

Prerequiresites:

  1. Install latest JDK SE
  2. Install MotoDevStudio

Build Steps:

  1. Launch MOTODEV Studio for Java(TM) ME v1.0
  2. Create a new project
  3. Select Phone type
  4. Create a package under src folder. (not necessary, but a good practice. else default package will be selected)
  5. Create class
  6. Add code (simple hello world using LCDUI)

    package MyPackage;

    import javax.microedition.lcdui.*;

    import javax.microedition.midlet.*;

    public class HelloWorld extends MIDlet
    {
        private Form mainScreen;

        private Display myDisplay;
       

       public HelloWorld()
        {
            myDisplay = Display.getDisplay(this);

            mainScreen = new Form("Hello World");

            StringItem strItem = new StringItem("Hello","This is a J2ME MIDlet.");

            mainScreen.append(strItem);
        }
        /**
         * Start the MIDlet
         */
        public void startApp() throws MIDletStateChangeException
        {
            myDisplay.setCurrent(mainScreen);
        }

        /**
         * Pause the MIDlet
         */
        public void pauseApp()
        {

        }

        /**
         * Called by the framework before the application is unloaded
         */
        public void destroyApp(boolean unconditional)
        {

        }
    }

  7. Edit Jad file MyMidlet.Jad; Goto Midlets tab (below); Add Midlets e:g MidletName,icon,Package.Class
  8. Build project, default setting is autobuild
  9. Create Package;Rightclick on MyMidlet Project (root element), From pulldown menu click J2ME and click on select CretePackage
  10. If everything goes well you should have MyMidlet.jar and MyMidlet.Jad files in ~:\Documents and Settings\user\workspace\MyMidlet\deployed
  11. Use MidletManager or your favourite tool to install this midlet
  12. Restart phone and test midlet

Note: This is without signing

Monday, November 26, 2007

VIM ftp editing

VIM supports easy editing of remote files.
Just Open ftp://domain.tld/path/to/file
It prompts for username and password!!!

Friday, October 26, 2007

Dave Winer on SOAP, REST and XML-RPC.

A good link http://www.kbcafe.com/rss/?guid=20060704042846

Note: Reproduced from site

SOAP Request

GET /stock HTTP/1.1
Host: www.kbcafe.com


<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
xmlns:m="http://www.kbcafe.com/stock">
<soap:Header>
<m:DeveloperKey>1234</t>
</soap:Header>
<soap:Body>

<m:GetStockPrice>
<m:StockName>HUMC</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>

The SOAP request tends to be overly verbose, but generally (not always) easy to understand. The SOAP envelope wraps an optional Header and the Body. The Body contains the actual XML request object. The Header contains information not required to service the request, but that help in some other way. A common use of the SOAP Header is the attachment of user credentials to the request. The beauty of SOAP is that it's not bound to the HTTP transport, although HTTP is by far the most commonly used transport for SOAP messages.



SOAP Response

HTTP/1.1 200 OK

<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
xmlns:m="http://www.kbcafe.com/stock">
<soap:Body>
<m:GetStockPriceResponse>
<m:Price>27.66</m:Price>

</m:GetStockPriceResponse>
</soap:Body>
</soap:Envelope>

The SOAP response, also slightly overly verbose, but easy to understand. Now, imagine getting this response and you want the m:Price element text. How would you formulate the XPath to acquire this bit of information? Very simple ("//m:Price/text()").


REST Request

GET /stock?StockName=HUMC HTTP/1.1
Host: www.kbcafe.com

The beauty of REST is that GET requests do not require a request package. In this case, the parameter data is simply passed as an HTTP request parameter. Of course, this simplicity comes with a price. You are now bound to the HTTP protocol. Although the argument has been made that the principles of REST are not bound to HTTP, nobody has ever documented that approach.


It's important I explain here that REST is primarily used to service GET requests. By GET, I mean REST requests using the HTTP GET verb. REST uses three other HTTP verbs POST, PUT and DELETE. GET is used to retrieve data, POST to create, PUT to edit and DELETE to ... umh... delete. The HTTP verb is another element that binds the REST protocol to HTTP.


REST Response

HTTP/1.1 200 OK


<?xml version="1.0"?>
<m:Price xmlns:m="http://www.kbcafe.com/stock">27.66</m:Price>

The REST response is often very similar to the contents of the SOAP request body. And it's very easy to express an XPath and retrieve the data ("//m:Price/text()"). Note the REST response is actually simpler than the SOAP Body. This is by convention. SOAP transactions typically contain an element named with the method name and the strings Request and Response appended. This is actually unnecessary, but does have one advantage. REST request typically embed the method name within the request URL, which again binds the protocol to HTTP, whereas embedding the method name within the package allows SOAP to exist over any protocol.


XML-RPC Request

POST /stock HTTP/1.1
Host: www.kbcafe.com

<?xml version="1.0"?>
<methodCall>
<methodName>stock.GetStockPrice</methodName>

<params>
<param>
<value><string>HUMC</string></value>
</param>
</params>

</methodCall>

The XML-RPC request is the most verbose of all the protocols. This verbosity is what makes XML-RPC both difficult to use and lacking in inter-op. For example, the <string> element is optional, so the <value> element could have been expressed as <value>HUMC</value>. Several MetaWeblogAPI (the most common implementation of XML-RPC) providers assume the <string> element is present, while others assume it's not present. Whichever way you code it, at least one MetaWeblogAPI provider will fail. This leads to a lot of frustration for developers trying to write XML-RPC applications. You often have to code the request differently to compensate for different server implementations.



XML-RPC Response

HTTP/1.1 200 OK

<?xml version="1.0"?>
<methodCall>
<methodName>stock.GetStockPrice</methodName>
<params>
<param>

<value><double>27.66</double></value>
</param>
</params>
</methodCall>

Again, the XML-RPC response is the most verbose and again it contains a gross limitation. What's the XPath for retrieving the data? If you said ("//double/text()"), then we might have a problem down the road. Imagine the provider augments his response with new elements that includes the stocks 365-day high and 365-day low. The XPath would fail. Neither SOAP or REST have this problem, because the elements are named semantically.

Thursday, September 27, 2007

Happy Birthday to Google

Today is 9th birthday for Google.

WISH YOU MANY MANY HAPPY RETURNS OF THE DAY GOOGLE.

Saturday, August 11, 2007

Regular Expressions - Part3

In previous post Regular Expressions - Part2, we discussed about regular expression engines and concept of backtracking. In this post we will discuss about the basis constructs of regular expressions , how to use them t o match simple words and lines.

Meta Characters

Meta characters are a sub-set of ASCII character set which take part in building a regular expression. e.g. +,$,^ etc.. Thus these characters instruct regex engines to perform specific operations. If we want to instruct regex engine to deal with thm as normal characters instead of meta characters we need to escape them with backward slash '\'.e.g regex "firstname\.lastname" instructs the engine to ignore special meaning of '.' and to consider as a '.' character.

Following list gives overview of mostly used meta characters.

. Dot - any character in a line

In normal search we use ? to specify a single wildcard character and * to specify sequence characters till next character. e.g. to search a file we use IAdb*.dll But in regex * is used for repetition. Also note that in a line phrase. This mean that the behavior of ‘.’ can be altered using mode settings like SingleLine or MultiLine mode to notify regex engine whether to match a newline (\n or \r\n) with a ‘.’ or to stop at new line. e.g:

Search String:
using System;
using System.IO;
using System.Text;
RegEx: “System.*”
Explanation: In MultiLine mode this matches all references with System and its decedents till end of line.
Matches in non-Single Line mode:
a)System;
b)System.IO;
c)System.Text;
Matches in Single Line mode:
a)System;System.IO;System.Text;

Note that semicolon is also matched in each line

\ - back slash
It is already mentioned that these are used to instruct regex engine to consider them as
normal characters. And when used with a number like \1 or \2, this specifies a back reference number. Back references will be covered seperately.

[ ] - opening and closing square bracket

Any group of characters to be matched are specified within these brackets. Examples are mentioned below.

( ) - round brackets
These are used to ho sub-expressions or back references. Back references will be covered later. Sub-expressions are similar to programming language sub expressions.

{ } curly brackets
These are used with iterators. We have seen this in Part 2 for five digit length. Its format is like {x,y}. where specifier is anything that need to repeated. Here x is
mandatory and can contain values from 0 to value of y. And y is optional to specify. and has to be any integer.

* Iterator to iterate for zero or more times. (0 or more times)

? Iterator to iterate for zero or one time only. (0 or 1 times)

+ Iterator to iterate for at least once or more times. (1 ore more times)

\w alphanumeric character including underscore

\W non-alphanumeric

\d numeric character

\D non-numeric

\s any white space; include , , and


\S non white space

| - pipe character
This is used to match alternatives. We used this in Part to test regex engine. Its syntax goes like [matcha | matchb]

\b - word boundary
We used this in part2 .

\B - any non- word boundary
example:
Search String:
ITSHUFFormAbc.htm
ITSCorporateFormBcd.htm
ITSSelfEmployedFormCde.htm

regex: ^[A-Z]{3}\B[a-zA-Z0-9]+\B

Match:
ITSHUFFormAb
ITSCorporateFormBc
ITSSelfEmployedFormCd


^ - beginning of a line

It matches from start of the line. In MultiLine mode it matches at the beginning of each new line. e.g.

Search String:
thisofLine1 of thisstring100
thisofLine2 of thisstring200
thisofLine3 of thisstring300
RegEx: ^this[a-zA-Z0-9]+
This matches this from the start of each line.
Matches in MultiLine Mode:
a) thisofLine1
b) thisofLine2
c) thisofLine3
Matches in SingleLine Mode:
thisofLine1

f you take out initial caret(^) in above regex, it will match both instances of this in each line

^ got a meaning of inversion when used within square brackets []. We will cover this in character classes.

$ - end of line
It matches at the end line. In MultiLine mode it matches at the end of each new line. e.g.
Search String: Let us the same string as above
thisofline1 of thisstring100
thisofline2 of thisstring200
thisofline3 of thisstring300
RegEx: this[a-za-z0-9]+.$
note '.' before $.
Matches in MultiLineMode:
thisstring100
thisstring200
thisstring300
Matches in SingleLineMode:
thisstring300

\A - start of text
Start of text matches only at the start of string irrespective mode setting

\Z - End of text
End of text matches only at the end of string irrespective mode setting