function test() : String
{
return 10;
}
Sunday, August 09, 2009
Syntax Highlighter on Blogger
At last, I got source Syntax Highlighter on my blog. Adding script in Gadget didn't work for me as I couldn't add <link> tag in HTML/Javascript gadget. Then I tried adding script in template itself and it works like a charm :)
Friday, July 31, 2009
Interoperability Problem with WCF Web Service Solved
I've spoken to many of my friends about how WCF services do not work with older system (and some time modern system like Flex). Well it is my bad that I didn't search for a solution. Sorry! I didn't search for the 'problem' itself.
Now, when I was generating WSDL file from my .svc, I good a strange thought. I didn't want to give 1 WSDS and 3 xsd imports (yeah 3 xsd:import.. see your WSDL), I wanted to flatten it a bit and give single WSDL. While searching for the solution, I found this article by Christain Weyer. It revealed to me that lack of 'single and complete' WSDL file is the problem for old consumers. I highly encourage you to visit his blog and see the solution by yourself.
Now, when I was generating WSDL file from my .svc, I good a strange thought. I didn't want to give 1 WSDS and 3 xsd imports (yeah 3 xsd:import.. see your WSDL), I wanted to flatten it a bit and give single WSDL. While searching for the solution, I found this article by Christain Weyer. It revealed to me that lack of 'single and complete' WSDL file is the problem for old consumers. I highly encourage you to visit his blog and see the solution by yourself.
Friday, July 24, 2009
Wix with util:User
Wix installer is my latest adventure. It's good but few thing may leave you scratching you head for hours. One of them is user right assignment.
I wanted to give ASPNET user some access right to my MSMQ. So defining user went like this (after that I gave permission):
Happy Weekends 2 u 2!
I wanted to give ASPNET user some access right to my MSMQ. So defining user went like this (after that I gave permission):
<util:User Id="aspnet" Name="ASPNET" / >Everything worked fine, until my product was uninstalled (for testing... in real life people will love it). Uninstaller 'owned' the ASPNET user and deleted while uninstalling the product. Leaving system corrupt. I had to rescue my system's dangled processes by re-registering ASP.NET. And found (hit and try) this is the right way:
<util:User Id="aspnet" Name="ASPNET" CreateUser="no" UpdateIfExists="no" />I don't know much about it but this worked and 'happy ending' is all I want at the starting of my weekends :)
Happy Weekends 2 u 2!
Thursday, July 16, 2009
Don't flush the Session after an exception occurs
I recently moved my all 'flush' at central location i.e. on session closed. And I close session in "finally" block of the code, to ensure that it really gets closed (not really).
So code would look like
try
{
//Use Session like never used before
}
finally
{
NhibernateSessionManager.CloseCurrentSession();
//closes session that was assigned to the thread
}
CloseCurrentSession in NhibernateSessionManager would look like this,
CloseCurrentSession()
{
ISession session = GetCurrentContextSession();
if(session != null && session.IsOpen)
{
session.Flush(); //evil is here
session.Close();
RemoveCurrentContextSession();
}
}
I was proud of this solution until I got into a database exception in my main code (which happens rarely after I write millions of lines of code).
If any such exception occurred and you try to flush, you will be delighted with another exception when you use session.Flush() It says "don't flush the Session after an exception occurs". For undisclosed reason, I couldn't use autoflush (reserved for next blog may be ;)
I believe there are alternate solutions but I as I told, I am lazy (like any other ORM), so I reverted back to my 'Flush manually' everytime when you make some entity dirty. Pretty shitty stuff huh???
Anyways, thanks for reading the blog even though the title "Don't flush the Session after an exception occurs" tells it all and inside matter is just ramblings.
So code would look like
try
{
//Use Session like never used before
}
finally
{
NhibernateSessionManager.CloseCurrentSession();
//closes session that was assigned to the thread
}
CloseCurrentSession in NhibernateSessionManager would look like this,
CloseCurrentSession()
{
ISession session = GetCurrentContextSession();
if(session != null && session.IsOpen)
{
session.Flush(); //evil is here
session.Close();
RemoveCurrentContextSession();
}
}
I was proud of this solution until I got into a database exception in my main code (which happens rarely after I write millions of lines of code).
If any such exception occurred and you try to flush, you will be delighted with another exception when you use session.Flush() It says "don't flush the Session after an exception occurs". For undisclosed reason, I couldn't use autoflush (reserved for next blog may be ;)
I believe there are alternate solutions but I as I told, I am lazy (like any other ORM), so I reverted back to my 'Flush manually' everytime when you make some entity dirty. Pretty shitty stuff huh???
Anyways, thanks for reading the blog even though the title "Don't flush the Session after an exception occurs" tells it all and inside matter is just ramblings.
Tuesday, June 16, 2009
Caching Problem with XMLHttpRequest
Using XMLHttpReuest is fun. But if you have just started the fun, you should know this.
IE has a known issue which caches the data if request is same. It's real mystery for me why Microsoft ended up with such default behavior for functionality which is responsible to load dynamic data. But as we have to live with it, here is a small hack which will turn off the caching for that page. You need to add this two lines in your HTML Head tag.
< meta equiv="Pragma" content="no-cache"/>
< meta http-equiv="Expires" content="-1" />
Solution Source: http://en.wikipedia.org/wiki/XMLHttpRequest#Workaround
IE has a known issue which caches the data if request is same. It's real mystery for me why Microsoft ended up with such default behavior for functionality which is responsible to load dynamic data. But as we have to live with it, here is a small hack which will turn off the caching for that page. You need to add this two lines in your HTML Head tag.
< meta equiv="Pragma" content="no-cache"/>
< meta http-equiv="Expires" content="-1" />
Solution Source: http://en.wikipedia.org/wiki/XMLHttpRequest#Workaround
Tuesday, May 12, 2009
About CProxyType*_NHibernate_ProxyINHibernateProxy_System_Runtime_SerializationISerializable2
Are you getting this exception while debugging on Visual Studio?
CProxyType*ENTITY_FULL_NAME*_NHibernate_ProxyINHibernateProxy_System_Runtime_SerializationISerializable2
Are you worried? Are you banging your head? Don't worry now, I have a solution for you! Follow as described below (step by step):
Step 1. Stop Debugging. Sometime NHibernate doesn't load lazy loaded entity during debug (specially in 'watch' or 'quick watch'). Test your code at runtime like Message Pop-up box or Console.Write etc
Step 2. Take a cup of tea.
CProxyType*ENTITY_FULL_NAME*_NHibernate_ProxyINHibernateProxy_System_Runtime_SerializationISerializable2
Are you worried? Are you banging your head? Don't worry now, I have a solution for you! Follow as described below (step by step):
Step 1. Stop Debugging. Sometime NHibernate doesn't load lazy loaded entity during debug (specially in 'watch' or 'quick watch'). Test your code at runtime like Message Pop-up box or Console.Write etc
Step 2. Take a cup of tea.
Sunday, March 01, 2009
Software Performance Consideration while Coding
Some tips when you write a code (an excerpt from Eric Lippert's Blog):
It tells how to walk on a blur trade-off between ‘correct’ and ‘preferment’ code. Success in the industry depends upon lot other factor and people just want workable code. Unnecessarily fast code doesn’t create any value of customer and time taken to think about or writing code is merely a waste in this hurry-burry software industry. Popularity of framework like .NET and Java are greatest example of it. Even the master, Donald Knuth, has said:
"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."
- Set meaningful, measurable, customer-focused goals.
- Write the code to be as clear and correct as possible.
- Carefully measure your performance against your goals.
- Did you meet your goal? Great! Don't waste any time on performance analysis. Spend your valuable time on features, documentation, bug fixing, robustness, security, whatever.
- If you did not meet your goal, use tools to discover what the worst-performing fixable thing is, and fix it.
It tells how to walk on a blur trade-off between ‘correct’ and ‘preferment’ code. Success in the industry depends upon lot other factor and people just want workable code. Unnecessarily fast code doesn’t create any value of customer and time taken to think about or writing code is merely a waste in this hurry-burry software industry. Popularity of framework like .NET and Java are greatest example of it. Even the master, Donald Knuth, has said:
"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."
Wednesday, December 17, 2008
Clear MSSQL Server Query Cache
NOTE: Strictly not for production servers and I mean it.
If you are first time optimizing query or choosing right index then you must know that SQL Server gives result from it's caches if query was already fired once. This is very useful feature but this behavior may tempt you to take wrong decision if this happens outside your knowledge.
You must see:
1. DBCC DROPCLEANBUFFERS -- Cleans temp buffers and dirty data. You may want to use CHECKPOINT before this command. http://msdn.microsoft.com/en-us/library/ms187762.aspx
2. DBCC FREEPROCCACHE -- Use this to clear execution plans http://msdn.microsoft.com/en-us/library/ms174283.aspx
I've not given FREEPROCCACHE with parameters which you may or may not be interested in but you should check out the link of microsoft site given there.
NOTE: Strictly not for production servers and I mean it.
Tuesday, December 16, 2008
"which" command for Windows using Powershell
"Code Assassin" has given a great way to use 'which' command (very popular in Unix and absent in Windows CMD prompt) in Windows using Powershell. If you are too lazy to go to his blog, here is the command,
($Env:Path).Split(";") | Get-ChildItem -filter sqlwb*
Here sqlwb is the command for which you want to know 'which' one will be used when executed, in short, location(s) of the command.
Surely there are better queries than this exists at the same place but above one simply works... rather works simply.
(at occations it gives more result than acutally it should give.. but you can easily figure out unwanted)
For other direct commands see: http://blog.stevex.net/powershell-cheatsheet/
It has nice collections for DOS commands and equivalent Powershell command.
Thursday, December 11, 2008
Database Indexes: tips
Database Indexes are sometime tricky. But it's easy to fall into traps by following simple advices. Here are some common tips (specific to t-sql and it may or may not apply to other RDBMS) listed here:
Sample Database Table:
1. Index is not used, when columns is in function
Sample Database Table:
| Customer_Id | Primary Key, Clustered Index, Numeric |
| Customer_Name | Part of multi-column index on "Customer_Name, Customer_Mobile, Customer_Location", Varchar |
| Customer_Mobile | Indexed, Varchar |
| Customer_Location | Part of multi-column index on "Customer_Name, Customer_Location" |
1. Index is not used, when columns is in function
Example of Bad:2. On DataType mismatch,
Select * from customer
where IsNull(Customer_Name,'!true') = IsNull(@CustomerName, '!true')
Good query:
Select * from customer
where Customer_Name= @CustomerName
OR (Customer_Name is null AND @CustomerName is null)
Example of Bad:3. Using Like on Wrong End:
Select * from customer
where Customer_Mobile = 9900114477
Select * from customer
where Customer_Id = '2'
Good query:
Select * from customer
where Customer_Mobile = '9900114477'
Select * from customer
where Customer_Id = 2
Example of Bad:4. : Multi-column Index is created with wrong sequence of columns
Select * from customer
where Customer_Name LIKE '%ram'
Good Option:
If you are gonna use put % always at first, use reverse Indexing
Example of Bad:
Select * from Customer
Where Customer_Name = 'CN' and Customer_Location = 'CL'
Good Option:
On Index is on columns:
1. Customer_Name
2. Customer_Mobile
3. Customer_Location
Which is only used when one of these is in your where clause:
1. Customer_Name
2. Customer_Name and Customer_Mobile
3. All three, Customer_Name, Customer_Mobile and Customer_Location
So only option is to modify Index Or Add new index on Customer_Location
Sunday, November 30, 2008
Powershell Advocacy for consuming .NET Programs
Powershell is more than a shell. Programs initially not written to be used using shell can also be involved into Powershell script, or cmdlets. Example is my “Get List of File Associated with multiple Changesets” which could also be written in a simple c# program, that too in more user kissing manner with GUI. But compromising on user interface brings more advantages which a developer loves to have for its program, especially for the ones used by developers. Here is why:
- Faster to write: A power shell script written in 4-5 line in above example may take around 20-100 lines or so to write in C# program. Once you are familiar with the syntax of cmdlet scripting, I think development is very much faster.
- Faster to modify: If you want to change output in any manner, it’s damn easy to understand the script and change it.
- Easy to Run: Once u have Powershell setup, it’s just like running ipconfig or ping!!
- Easy to extend the output: Output formatting provided inside Powershell is a great deal. Also, easy to write output in files and so easy to use your favorite text editor (mine is scintilla based SciTe).
- Easy to Reuse: Pipe and reuse the script which u already wrote for some purpose. Or just use script inside script.
Tuesday, October 07, 2008
Secure Your Wireless Internet
Note: Tips applicable for home networking only.
Here are some tips to secure your Internet sharing using Wi-Fi, securing not just for namesake but for real.
Tips for Securing router:
1. Make sure you change user name & password of your router. Remember, any obvious password or password that can be cracked by simple brute force techniques.
2. Restrict “Remote Access” of your router by which people can access your router without being part of your network.
3. You will get many option for Wi-Fi security out of which WEP (Wired Equivalent Privacy) being default. Don’t go on name, WEP is the security which only dumb cannot crack. Use any of WPA (Wi-Fi Protected Access). WPA can also be cracked if the password is weak.
4. Last but not least, don’t lure hackers. Switch off your modem and router when not in use.
Suggestion for strong password:
I know this need not to be a part of this discussion but if you use weak password, no security can help you. A good brute force with proper dictionary can crack these easily.
Do:
Don’t:
Here are some tips to secure your Internet sharing using Wi-Fi, securing not just for namesake but for real.
Tips for Securing router:
1. Make sure you change user name & password of your router. Remember, any obvious password or password that can be cracked by simple brute force techniques.
2. Restrict “Remote Access” of your router by which people can access your router without being part of your network.
3. You will get many option for Wi-Fi security out of which WEP (Wired Equivalent Privacy) being default. Don’t go on name, WEP is the security which only dumb cannot crack. Use any of WPA (Wi-Fi Protected Access). WPA can also be cracked if the password is weak.
4. Last but not least, don’t lure hackers. Switch off your modem and router when not in use.
Suggestion for strong password:
I know this need not to be a part of this discussion but if you use weak password, no security can help you. A good brute force with proper dictionary can crack these easily.
Do:
1. Mixture of Capital and Small letter, special character
2. Password length should be at least 8 character
3. For longer password, use 256 bit encryption technique
4. You are lucky if you are from non-English speaking country as you can have words which does not exist in common world list for bruit force attack. Use these words freely.
5. Try to have less used letter i.e. ‘x’ or ‘f’ or ‘q’ etc
Don’t:
1. Part of a password with complete English word. e.g. say no to ‘EightNineTen’
2. Password having any (key) sequence e.g. say no to ‘xxx1234’ or ‘xxx!@#$’ or ‘asdf’
3. Password having any obvious personal information e.g. say not to password with birth year
4. Password having repeating words i.e. say no to “IndiaIndia11”
Wednesday, September 17, 2008
Get List of File Associated with multiple Changesets
I wrote a cmdlet for powershell by which you can get list of file associated with list of changesets.
Steps:
1. Create a file Get-Changeset-Files.ps1 and copy above code in the file (preferably where get-tfs resides). Also add this directory into your $path
2. Open Powershell, go to Directory where above file recides
3. Run 'Set-ExecutionPolicy unrestricted' so that you can run above cmdlet
4. Everything is ready.. just run for example: Get-Changeset-Files('10, 20, 30')
See here for get-tfs.ps1
param(
[string] $changesets = $(throw 'Usage: Get-Changeset-Files 'changesets')
)
process
{
# get TFS object
$tfs = get-tfs ;
# build up list of file items
$fileItems = @();
$changesets.Split(',') | foreach {
$tfs.vcs.GetChangeset($_).Changes | foreach {
if($fileItems -notcontains $_.Item.ServerItem) {
$fileItems += $_.Item.ServerItem;
}
}
}
return $fileItems | Sort-Object;
}
Steps:
1. Create a file Get-Changeset-Files.ps1 and copy above code in the file (preferably where get-tfs resides). Also add this directory into your $path
2. Open Powershell, go to Directory where above file recides
3. Run 'Set-ExecutionPolicy unrestricted' so that you can run above cmdlet
4. Everything is ready.. just run for example: Get-Changeset-Files('10, 20, 30')
See here for get-tfs.ps1
not-my get-tfs
#This is very popular file you may get at many places. Change $serverName's default value
param(
[string] $serverName = 'http://tfs-server:port/'
)
begin
{
# load the required dll
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
$propertiesToAdd = (
('VCS', 'Microsoft.TeamFoundation.VersionControl.Client', 'Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer'),
('WIT', 'Microsoft.TeamFoundation.WorkItemTracking.Client', 'Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore'),
('CSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.ICommonStructureService'),
('GSS', 'Microsoft.TeamFoundation', 'Microsoft.TeamFoundation.Server.IGroupSecurityService')
)
}
process
{
# fetch the TFS instance, but add some useful properties to make life easier
# Make sure to "promote" it to a psobject now to make later modification easier
[psobject] $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)
foreach ($entry in $propertiesToAdd) {
$scriptBlock = '
[System.Reflection.Assembly]::LoadWithPartialName("{0}") > $null
$this.GetService([{1}])
' -f $entry[1],$entry[2]
$tfs | add-member scriptproperty $entry[0] $ExecutionContext.InvokeCommand.NewScriptBlock($scriptBlock)
}
return $tfs
}
Tuesday, September 16, 2008
Idiotic Software (TFS)
User Experience is where Microsoft TFS loses the ground. Here was a day when I struggled to merge around 30 changesets across branches. The user interface doesn't have any filter by which I can see only my changeset (out of 40 membered team's chagesets from the day we separated the branch). I cannot merge multiple changeset at once untill the are in sequence (no CTRL + select). It seems Team Foundation Server assumes the team is made of 1 person.
What NHibernate Lacks
There were situations when I had to make sure that I Get (or Load) fresh entity object from database. But with NHibernate, until I change configuration forever, there is no other way to do so except to use UnitOfWork.Refresh method.
This is expensive when I the object is not in cache at frist place. It makes 2 database hit.
What I need is something like this,
UnitOfWork.GetFresh(object pk)
OR
if(UnitOfWork.IsCached(object pk) && !UnitOfWork.IsDirty(object pk)
{
//Refresh
}
else
{
//Get
}
This is expensive when I the object is not in cache at frist place. It makes 2 database hit.
What I need is something like this,
UnitOfWork.GetFresh
OR
if(UnitOfWork.IsCached
{
//Refresh
}
else
{
//Get
}
Tuesday, September 02, 2008
Vertical Text Selection
You may need to do sometime vertical selection. For example, in example below, I want to select and remove all “SolidX”.

I need to do vertical selection for this. Selecting text vertically not commonly used but an excellent functionality provided by all serious text editors.
This is how to do it (Windows specific): Hold ALT and SHIFT key and select the text vertically and horizontally. It is not important whether you select first vertically or horizontally but you MUST press and hold ALT key before SHIFT key.
You can do this on all modern Code editors, good text editors like Scintilla based SciTE, TextPad etc. Once you know about vertical text selection selection, you will find its use at more places than what you can think about when unaware.
I need to do vertical selection for this. Selecting text vertically not commonly used but an excellent functionality provided by all serious text editors.
You can do this on all modern Code editors, good text editors like Scintilla based SciTE, TextPad etc. Once you know about vertical text selection selection, you will find its use at more places than what you can think about when unaware.
Friday, August 29, 2008
Blog Popularity
This blog is near to cross 500 unique visitor per month :) finger crossed
How to Get Calling Assembly
I work on a product which has more than 80 assemblies call around each other. We have build with pdb file specially distributed to developers for debugging purpose but all are not so fortunate :)
It is obvious that you cannot be sure about which assembly you will need to compile in order to get full call stack. But with : System.Reflection.Assembly.GetCallingAssembly()
This way you get the calling assembly so you can compile that assembly. There are a lot of goodies to explore in System.Reflection.Assembly class for debugging.
Happy Debugging!!
It is obvious that you cannot be sure about which assembly you will need to compile in order to get full call stack. But with : System.Reflection.Assembly.GetCallingAssembly()
This way you get the calling assembly so you can compile that assembly. There are a lot of goodies to explore in System.Reflection.Assembly class for debugging.
Happy Debugging!!
Thursday, August 14, 2008
Change-Set Rollback using TFS Power Tool (tfpt.exe)
Have you made a booboo by checking in something which you shouldn’t have? If you are using TFS and TFS Power Tools (tfpt in short) installed on your system, you are still good to roll the s#%t back.
Here are the steps that you will need to follow:
1. Install TFS Power Tool. This is recommended as it provides a lot of goodies without which you may see hell some day.
2. ‘Shelve’ all changes, as you will have to ‘undo’ all your changes.
3. Open cmd prompt. Make sure your $path environment variable is configured to find tfpt.exe
4. Change directory to the workspace
5. Give this command: rollback /changeset:{Change-Set Number}
(For example rollback /changeset:39356)
6. It will take latest of all your workspace. This is what I don’t like as it doesn’t work otherwise. It takes some but works…
7. After above step, tfpt has taken older version and all those file will be ready to be check-in with older viersion.. Check-in those and take a tea.
Tip [02/24/2009]: Step 6 may kill you if you are storing huge amount of data into TFS. I advice you to create a new workspace with only required files downloaded. For Example, if your all changes are in '$codebase/folder/subfolder/" then create workspace for $codebase/folder/subfolder/ mapped to local directory C:\for_rollback\ Due to this, step 6 will become very fast.
Powertool help and website: http://msdn.microsoft.com/en-us/tfs2008/bb980963.aspx
Here are the steps that you will need to follow:
1. Install TFS Power Tool. This is recommended as it provides a lot of goodies without which you may see hell some day.
2. ‘Shelve’ all changes, as you will have to ‘undo’ all your changes.
3. Open cmd prompt. Make sure your $path environment variable is configured to find tfpt.exe
4. Change directory to the workspace
5. Give this command: rollback /changeset:{Change-Set Number}
(For example rollback /changeset:39356)
6. It will take latest of all your workspace. This is what I don’t like as it doesn’t work otherwise. It takes some but works…
7. After above step, tfpt has taken older version and all those file will be ready to be check-in with older viersion.. Check-in those and take a tea.
Tip [02/24/2009]: Step 6 may kill you if you are storing huge amount of data into TFS. I advice you to create a new workspace with only required files downloaded. For Example, if your all changes are in '$codebase/folder/subfolder/" then create workspace for $codebase/folder/subfolder/ mapped to local directory C:\for_rollback\ Due to this, step 6 will become very fast.
Powertool help and website: http://msdn.microsoft.com/en-us/tfs2008/bb980963.aspx
Subscribe to:
Posts (Atom)