Friday, August 22, 2008

Bookmarklets

Bookmarklets is a little javascript code you can put directly into your firefox/IE "bookmarks(favorites)". So when you select the bookmark, it will execute the code and enhance your functionality of the browser. Bookmarklets have been around since IE4, and I find them quite handy. There are bookmarklets to autofill forms, to cut-and-paste, to select text and bring up a search engine and several other uses. I recently created a bookmarklet to rid myself of the annoyance when some sites use redirects, which causes either the form to appear as illustrated, or the firewall to block the site entirely.


The link appears as:
Notice that the actual link I want to read is a URL parameter and is percent encoded. Now I have to fill out this form every time I need to read an article on LSJ. Clicking on the Bookmarklet helps me grab the actual link which is:

For IE the easiest to create this bookmarklet is by adding a dummy bookmark (like this web page), then edit its properties:
Click on "Favorites", then RIGHT-CLICK on the link you added and select "properties" from the context menu.
In the "properties" window, click on "General" Tab. Now change the name of the bookmark to "UNESCAPE". Next, click on the "Web Document" tab and paste the following code for URL:
javascript:void(pos=location.href.search("=http%253A"));
if(pos=-1)void(pos=location.href.search("=http%"));
if(pos>-1)location.href=
unescape(unescape(location.href.slice(pos+1)))
Note the entire code is the url address, so it should be in a single line and without any spaces in between it. Now click on "Apply" and you will see a message:
"The protocol javascript does not have a registered program".
Click "Yes" to keep it anyway. Click OK, and then "Yes" again. Congratulations, you just made your first bookmarklet.

Tuesday, July 22, 2008

TransportationToastmasters new year celebration

Last month we had a great dinner celebration to induct and welcome the new board of my Toastmasters club, celebrate the past years achievements, and have a good social time. I've been a member of Transportation Toastmasters for many years, and am sort of the granddaddy -- to guide the newer members as well as help out with any kind of special events. I took on the project to organize this party. First order of business was to get a consensus of the venue, date and time. It just happens that I had read some articles on voting theory and voting models in different countries. Most voting is a simple ballot where you pick a single choice among many. It would great if our constitution was changed to explore these other options where we can pick multiple choices, rank them or use a weighting system - I believe that gives us much better ways to achieve a collective consensus. (I must admit though, that this is way low on a scale of what is wrong with our democracy)

Anyways, I thought I would try this out something cool. I first asked people to make suggestions for restaurants, and dates. After considering all factors, we narrowed it down to three day window, and choice of 10 restaurants. I thought of writing a quick asp.net application to get online surveys, but thought to first browse around the web to see if I could use something that is already there. SurveyMonkey happens to be an asp.net app and it had what I needed. I made it so that instead of people just picking on one restaurant, can put points of several ones that they like. There were given upto 100 points. The same applied to the date selection. At the end I added up the points to come with the consensus. You can also download the data to a spreadsheet and do more data manipulation (such as give a multiplier factor for people who are bringing guests), group totals, graphs, etc.

The survey was a great success, and the members loved the idea. It was also very convenient - a simple 5 question online form. Best of all this service is free.

We had a wonderful dinner celebration. We settled on Pizza House in East Lansing which has a room in the back. We invited our Division governor Peg McComb-Elowski and some former but long time members. It was good to see Vanessa Tran and catch up with her. We ran into Jane Aldrich, a long time WLNS news anchor, who was our special guest speaker just two weeks ago. We actually had a few more people than my what I had reserved for - but Pizza House was gracious to add more tables to seat everyone together.

Saturday, July 12, 2008

RegEx for extracting in HTML

Today I am at the Ann Arbor Give Camp - a weekend of coding frenzy where about 60 geeks are holed up in Washtinaw Community College developing web sites and web apps for charitible institutions and other good causes.



One of my tasks was to design a Master Page template from a mockup which was done in Publisher, and had tons of vml and office code. I needed to extract images and a rightClick-saveAs did not work (because of scripting, vml, etc.) All images were in the index_files folder, with a "image####.gif" filename. So I dumped the code in Expresso, and ran a match using the regex:
index_files\/image\d{1,4}\.gif,
Viola! I got a list of match which I copied and pasted in an HTML and downloaded the images.

Friday, July 11, 2008

.Net Certification map

Forgive me Lord for I have sinned. It's been over two weeks since my last post, and I have not posted updates to my regular expression talk. It's been ridiculously busy two weeks, so much so that I have slept very little. Wednesday night, I started cooking dinner at 11:30 pm. "Chicken Do-Pyaza" - a curried chicken recipe with generous portion of onions (Do-Pyaza translates to twice the onions). In a sleep deprived state I somehow ended up adding too much yogurt, onions, and water! So my recipe ended up becoming "Cream of Chicken 3-1/2 Pyaza e Rassam" - (Rassam is a South-Indian diluted soup.) Didn't taste bad though.

Anyway, here at MDIT we are looking to start a internal study group for .Net and other technology and I am helping launch the initiative. I was looking for certification information, and it is not well documented on the MSDN site, so I compiled it nicely in graphical format, that gives you the certification path at a glance. It shows you all the exams needed and prerequisites to get MCTS, MCPD and MCITP for .net 2.0, 3.5 and SQL Server 2008.







Tuesday, June 24, 2008

Part 1. Power of a Regular Expressions

Rather than just posting the slides, I decided to do a series of blog posts on the subject - consider it as a intro or tutorial to Regular Expressions.

What are Regular Expressions?

Regular Expressions (or RegEx for short) is a technique to shorten coding by using bunch of letters and symbols (metacharacters). Most modern languages support regular expressions. You can use it in code. But where they are really useful is data cleanup, extraction, converting legacy data, grabbing data from the internet, etc. Regular Expressions can be considered as the SQL for freeform text.

RegExs are avoided by most people (even experienced programmers shy away from it), because they either don't understand it, haven't taken the time to learn it -- or they think that it is sediment left over from the Unix era.

At the end of this tutorial you will see that, regular expressions can actually be easier and quicker to code. Once you understand how it works, and some of the tools and techniques, you will see how dramatically it can shorten code, and save you a time with coding and debugging. Also, maintenance can actually be easier!

Here is a terrific example. Today, I was browsing through the prep book for MCTS Exam 70-528, and came across this example for asp.net custom validator control to validate passwords. The password rules are:

  • 6-14 characters,
  • at least one lowercase letter,
  • at least one uppercase letter
  • at least one number

Here is the conventional method. (Code directly copied from the book, pg 469 with misspelled "argument" and all)

<script language="javascript" type="text/javascript">
function ValidatePassword(source, arguements)
{
var data = arguements.Value.split('');
//start by setting false
arguements.IsValid=false;
//check length
if(data.length < 6 || data.length > 14) return;
//check for uppercase
var uc = false;
for(var c in data)
{
if(data[c] >= 'A' && data[c] <= 'Z')
{
uc=true; break;
}
}
if(!uc) return;
//check for lowercase
var lc = false;
for(var c in data)
{
if(data[c] >= 'a' && data[c] <= 'z')
{
lc=true; break;
}
}
if(!lc) return;
//check for numeric
var num = false;
for(var c in data)
{
if(data[c] >= '0' && data[c] <= '9')
{
num=true; break;
}
}
if(!num) return;
//must be valid
arguements.IsValid=true;
}
</script>

Now, with the use of regular expressions, we can shorten this into just ONE line of code:
<script language="javascript" type="text/javascript">
function ValidatePassword(src, args)
{
args.IsValid =
args.Value.length>=6 && args.Value.length<=14
&& /[a-z]/.test(args.Value) //find a lowercase
&& /[A-Z]/.test(args.Value) //find a uppercase
&& /\d/.test(args.Value) //find a digit
}
</script>

You've got to love the elegance and compactness of this code. I believe it is actually easier to understand and debug - no messy loops and "if" constructs. And it reads exactly like the password rules specification above. Such is the amazing power of regular expressions. Note: "\d" is the character class for identifying a single digit. We could have just as well said "[0-9]".

In my next post we will look at a few more easy examples and examine the metacharacters.

Sunday, June 22, 2008

Regular Expression talk at Lansing's DODN

Last night's party at Jeff's was a lot of fun. We had the Xbox's "Rock Band" connected with all the controllers. I have always wondered what the hell is the deal was with games like these (why waste time on pseudo guitars when you can spend that time learning real guitars). But watching my buddies belt out lyrics to Radiohead and Blue Oyster Cult, I can see now see what the draw is -- they were really having fun. What a fantastic product this is, from a marketing and innovation standpoint. (the credit really goes to original innovator - Wii and Guitar Hero)





I thought yesterday's Day of Dot Net was a terrific success. We organized it at a grand scale pulled it through, with record participation, great publicity from local press and the finale with Lansing Mayor Bernero's address. Thank you Joe, Jeff, Vivek and others for doing such a bang-up job. For our first event we outdid both Ann Arbor and Grand Rapids in the scale and detailed level of planning. We had managed to get very famous speakers, had incredible amount of swag and other giveaways, and had great of food and beverages. The LCC West campus was a fantastic facility. I felt excited to be part of this group.

I really enjoyed speaking at the event. It was very interactive with lot's of questions. Since a few attendees requested the code samples, which I will post shortly. Here is the presentation.

Tuesday, May 13, 2008

It's a Tuesday, but feels like a Friday!

This evening I went running with the Mid Michigan Track Club. We met at Hawk Island park. What a great evening, and the park is especially beautiful. I really enjoyed running with these folks, and it was a good change of pace for me. I have been way too geeked out recently with .Net exams, and work-work and technology. After that, Minal and I met up with the Raad's, owners of Woody's Oasis. We went to dinner at Sindu's. The food, as usual was outstanding. They are such wonderful people. All in all, a real fun evening.

West Michigan Day of .Net was a great success

This past week was incredibly busy for me. My project at work is in a critical stage and takes a lot of my time. Then, I went to my Optometrist who gave me the good news / bad news. Bad news - my vision has slipped a little. Good news is that it is not too bad. Good enough to drive, but just bad enough to cause some annoyance since I cannot see crisply, or recognize people's faces until they get up close. So if you guys don't see me waving back at you, I'm not being rude - I just cannot see you. (That's my story and I am sticking to it!). Anyway, the annoying part is after all these years, just when HDTV is upon us and I bought a beautiful Samsung LCD panel, now my vision slips. Grr!

I attended the West Michigan day of .Net this past Saturday at Davenport by the Grand Rapids airport. I was very impressed with the speakers. It was a great opportunity to catch up with technologies. I spent ALL of Sunday (I mean 10am to past midnight!) reading up on all the things the speakers talked about, and gave references, and other things I was not familiar with. It looks like this year there is a lot of emphasis on TDD, testing tools, continuous integration. Also WCF and WPF are big. There were talks on new languages F#, Boo/DSL, and also a mention of Ruby. I'm gonna read up on them sometime in the future, especially F#.

I am named the director of education for GLUGnet

The president of the Greater Lansing .Net User Group, Joe Kunk asked me to be the "Certification Director", and launch and lead the .Net study group. I suggested that Education director would be a better sounding title. He got OK from the board, so here I am, on the GLUGnet board as the Education Director. One of my first steps is to launch the study group for the next exam 70-528(MCTS .Net Web development). I have sent the message out to the community. We will be meeting Wednesdays 6pm-8pm at the Gone Wired Cafe in Lansing starting May 21st.

I am an MCP now! Passed the .Net Framework test!

I am glad to announce that I cleared this exam last week. The study group really helped me - I don't think I could have done without it. The subject matter for the 70-536 is vast, and having the study group automatically puts you on a schedule of completing one chapter a week. Also getting together and discussing the chapter helps clarify the content. Most of all, it keeps you inspired to keep on going. Call it the "weight watchers of .Net".

The book unfortunately was choke full of errors and had missing information. That made preparing for the test all the more difficult. I studied my butt off, because I wasn't sure on the format of the exam and how hard the questions would be. Looks like all my studying paid off as I scored on 931, well above the 700 passing grade. I'm still trying to figure out how to reward myself - I deserve it this time!

Thursday, January 10, 2008

First entry

Hi, my name is Vijay Jagdale - welcome to my blog.