Friday, September 11, 2009

Updating XML fields using LINQ to SQL

There is an hard to avoid issue with LINQ to SQL. That is you cannot update data on XML data fields using LINQ to SQL. This is a work around so you can update data in XML data fields using LINQ to SQL.

  • Open your DML file on Microsoft Visual Studio.

  • Drag and drop the table(s) that have the XML data field(s). (This is a new instance let the original table to be there. For example if original table name is "Employee" this might be "Employee1".)

  • Click on the data field name that has XML type data.

  • On properties box change the Type under Code Generation to String.

  • Now when ever you need to update the XML data, use the new table instance.

Please note when compiling you may get a warning saying two references for same table might to lead to a conflict. You can safely ignore it and do wise coding. :-)

Recommended Books

Tuesday, September 1, 2009

Fix your USB Flash Drives

Most of time due to viruses and disk errors USB flash drives or USB pen drives become unusable. If you try to open them, format them or scan them for viruses on Windows; system won't let you do so.
There is a very easier fix on the other side of the river. i.e. using Linux.

WARNING: This procedure will format your flash drive. I'm not responsible for any damages or loss that may cause you. Use this guide at your own risk.

All you need is Linux installed machine or bootable Live Linux CD.
Goto console mode. (Go to the terminal mode)
Type following command to find out your flash drive node,

sudo dmesg | tail -20

Then you will get a list like

usb-storage: device scan complete
sd 3:0:0:0: [sdb] 12345678 512-byte hardware sectors: (320 GB/298 GiB)
sd 3:0:0:0: [sdb] Write Protect is off
sd 3:0:0:0: [sdb] Mode Sense: 03 00 00 00
sd 3:0:0:0: [sdb] Assuming drive cache: write through
sd 3:0:0:0: [sdb] Assuming drive cache: write through

Then sdb is your flash drive.

Use following commands to fix your flash drive.

sudo fdisk /dev/sdc

You must change /dev/sdc appropriately.

Then you will get following message and prompt.

The number of cylinders for this disk is set to 14593.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs

Command (m for help):

You may type p to list current partition table.

Then enter d and delete available partitions.
If you have only a single partition entering d will delete it.
Other wise you may have to enter the partition id.

After deleting all the partitions, enter n to create new partition.

Command (m for help): n
Command action
e extended
p primary partition (1-4)

Now enter p then 1.
Then enter twice.

Partition number (1-4): 1
First cylinder (1-7644, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-7644, default 7644):
Using default value 7644

Command (m for help):

Now enter w to write table to disk and exit.
Now you will be able to format the USB flash drive and reuse it again.

Friday, July 3, 2009

Bluetooth Mobile Phone Hack

This is hack that you can do on your friend's Bluetooth enabled mobile phones. By successfully implementing this hack,
  • You can dial any number from your friend's mobile phone.
  • You can change the silent mode.
  • Turn on ringing tone with out a call.
  • Turn on alarm sound.
  • Access Phone Book.
  • Access SMS.
  • Access Call Summery.
  • And many more depending on the compatibility of the friend's phones. Most of Nokia, Sony Ericsson and Motorola phones are supported.
Are you impressed?
Then this is what you need.
  • Two Bluetooth enabled phones. Obviously your phone and your friend's (victim's) phone. ;-)
  • Your phone must have Java support.
  • You need Super Bluetooth Java application installed.
  • Physical access to your friend's phone for one time or If your phone is already paired and your friend has already added you to trusted connections no problems.
This the way to do it.
  • If you haven't already paired two phones. Pair them and add your phone to trusted connections on the other mobile phone's paired devices list. If you don't do this, every time you try to connect your friends phone, he will get an alert asking to permission to connect.
  • Go to your applications.
  • Open Super Bluetooth application.
  • Select "Connect".
  • Select your friend's phone and connect.
  • And everything else is straight forward. ;-)
Have fun! :-D

BTW I found this video on YouTube demonstrating this hack. There are lot more videos like this have a look.

Tuesday, March 31, 2009

.NET/IIS URL Rewriting using URL Rewriter

You can easily rewrite URLs on .NET/IIS using free open source program called URL Rewriter.
If you don't know what is URL rewriting is, it is simply the mechanism which give out search engine friendly URL like instead of
Whats actually happening is, there is only products.aspx file exists and it takes query sting product.
But by using URL rewriting, it passes the psp as the query string to the products.aspx file.
So what user see is but (s)he is actually looking at the

So Interested? ;-)
If so this is how it will be done,

<section name="rewriter" requirepermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />

<add type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" name="UrlRewriter" />

<rewrite url="/products/(.+)" to="/products.aspx?tag=$1" />

  • Now if you test this on Visual Studio, you will see that URL rewriting is working.
  • But, If you deploy this on ISS it will not work.
  • The trick is,
  • Right Click on the web site on ISS manager.
  • Goto the "Home Directory" tab.
  • Select configurations.
  • Select .asax extension.
  • Click "Edit" button.
  • Copy the executable path and click the "Cancel" button.
  • Now click on the "Insert" button.
  • Paste the previously copied executable path on the text box.
  • Make sure that "Verify that file exists" is unchecked.
  • Click Ok
  • Close the web site properties dialog.
  • And thats it. ;-)
You can use reguler expressions, IF clause, UNLESS clause etc. URL handling. You can find out lot about it from URL Rewriter Refence.

Sunday, February 1, 2009

Do the bulk updates using Microsoft SQL Server Correctly.

This is the scenario:
You have a table called tblItem with fields,
itemID, itemTitle, itemDescription, itemImage and itemPrice.
itemID is set as the primary key or it is the field that can be used to uniquely identify a given row.
And this table is populated with 1000 records.
Imaging that you have to change the price of about 700 items.
And your data entry team supplied you a Microsoft Excel spreadsheet with itemID and new itemPrice.
So you have to update the tblItem table, without effecting other 300 items.

Before you start updating:
Make sure that itemID is unique in tblItems and the spreadsheet, otherwise you will get an error.

How to do the update:
  • Import data from the spreadsheet and create a new table called tblTemp
  • The fields will be tempID and tempPrice
  • Run this query:
UPDATE tblItem
SET itemPrice = (SELECT tempPrice FROM tblTemp WHERE tempID = itemID)
WHERE itemID IN (SELECT tempID FROM tblTemp);

With this query you can make sure that other records which aren't present in the spreadsheet will not get updated and only the records present in the spread sheet get update.

Words of caution:
  • Don't forget to delete the temporary table.
  • It is always a good idea to make backup.

Friday, January 30, 2009

Easy way to read color on web site

When you have to find out color of certain image or text in a website, you may have wasted time by making screen shot of the web site and opening it in a Image Editor using its Eyedropper, Color Picker to find out the color. But with ColorZilla, color on website is just a one click away. ColorZilla is a Firefox Add-on.

  • Find out color of any place on the web browser. (Including Favicon area, menu, toolbars etc.)
  • Get color code in both RGB format and Hex format (with hash notation ex. #FFFFFF).
  • Shows the name of active CSS style.
  • Web page zooming.
  • Advance color palette.
  • Configurable color representation format.
  • Configurable Keyboard Shortcut (Default ColorZilla keyboard shortcut is set to Shift + Esc).
  • Integration with other popular Firefox add-ons and more...
How to Install ColorZilla?
  • Open Firefox.
  • Go to Tools menu & select Add-ons.
  • Click on Get Add-on icon.
  • Type ColorZilla on the text box and press enter.
  • Select ColorZilla on the search results and click Add to Firefox button.
  • Firefox will download and install the add-on.
  • Restart Firefox.
  • ColorZilla icon will be available at the left hand corner of the status bar.
How to Use ColorZilla?

How to find color with ColorZilla?
  • Click on ColorZilla icon in the left hand corner of the status bar or press the ColorZilla keyboard shortcut (Default ColorZilla keyboard shortcut is Shift+Esc).
  • Now where ever you move your mouse point on the browser window status bar will be showing the color code in both RGB format and with hash notation plus the name of the active CSS style.
  • Click on the screen or click on the ColorZilla icon or press the ColorZilla keyboard shortcut.
  • Right click on the ColorZilla icon, and select any copy color code format to copy the selected color.
How to zoom web pages will ColorZilla?
  • Right click on ColorZilla icon.
  • Go to Zoom.
  • Select any zoom level from 20% to 1000%.
How to change ColorZilla color picker size?
  • Right click on ColorZilla icon.
  • Go to Options.
  • Select Color picker.
  • Select the color picker that you want.
How to Change the ColorZilla keyboard shortcut?
  • Right click on ColorZilla icon.
  • Go to Options.
  • Select Change Eyedropper Shortcut.
How to find more information about ColorZilla?