Showing posts with label Tips and Tricks. Show all posts
Showing posts with label Tips and Tricks. Show all posts

Wednesday, October 28, 2020

Finding the .NET version on windows

 In Java, you can execute a simple command "java -version", but unfortunately it is not so straightforward in .NET.

The below stackoverflow thread shows some commands that can be leveraged to find out the .NET version - https://stackoverflow.com/questions/1565434/how-do-i-find-the-net-version

The commands which worked for me on Win10 are as follows:

Command Prompt (cmd):

dir /b /ad /o-n %systemroot%\Microsoft.NET\Framework\v?.*

The above command will list down all versions of .NET except v4.5 and above. 

reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\full" /v version

The above command will work for .NET versions v4.5 and above. 

PowerShell:

gci 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP' -recurse | gp -name Version,Release -EA 0 | where { $_.PSChildName -match '^(?!S)\p{L}'} | select PSChildName, Version, Release

The above powershell command is the most versatile and will list down all versions. 

Saturday, June 08, 2019

On @Cacheable annotation of Spring

The @Cacheable annotation of Spring works like magic, allowing us to create caches easily with just one line of code.
But it is important to not that the caching will NOT work if you are calling method is in the same class !
This happens because Spring injects a proxy at runtime to implement caching and if you are making calls to cacheable methods from the same class, the proxy is not used.

More information on this thread - https://stackoverflow.com/questions/16899604/spring-cache-cacheable-not-working-while-calling-from-another-method-of-the-s

Monday, October 24, 2016

Printing an object's properties for debug purposes

Quite often, we override the 'toString()' method of an object to print its properties. But there are a number of reusable utilities that can be used for the same.

In Java, the popular Apache Commons Lang3 package contains a class called ReflectionToStringBuilder  that has static overloaded methods 'ToString()' to print all fields using reflection. You can also specify a few formatting options and the fields to exclude.

Another option is Java, is to use the JSON libraries to print the object as a json string. The Google librarly Gson can be used to print (or pretty print) an object as a json string.

In .NET, you can either use the ObjectDumper library or you can use the object json formatter - newtonsoft JSON library

Tuesday, December 01, 2015

Weird laptop battery problems and ridiculous solutions

Laptops suffer from so many idiosyncratic battery problems and have their own ritual of try-n-test solutions that appear so weird !

Recently, I was facing a unique problem on my HP pro book 440. The charger was connected, but the battery was not charging. The status showed - "Plugged in, not charging". I tried multiple options to rectify this - by removing and plugging in the battery, by restarting the machine, but nothing worked.

The following steps posted on HP forum finally did the trick.

- While the computer in running, disconnect AC from the outlet
- Restart computer
- After loading, reconnect AC

Hope this helps someone in dire need :)

Monday, July 27, 2015

builtwith.com - A nifty tool

We used to use browser tools such as Firebug to find out more 'backend' information about a particular site - for e.g. what servers does it run on? What server-side web technology is being used? What web content management tool is being used? etc.

Found a nifty website that gives all this info in the form of a neat table - http://builtwith.com/
A useful tool to have in the arsenal for any web-master. 

Thursday, February 05, 2015

Comparing two columns in excel to find duplicates

Quite often, you have to compare two columns in excel to find duplicates or 'missing' rows. Though there are many ways to do this, the following MS article gives a simple solution.

https://support.microsoft.com/kb/213367?wa=wsignin1.0

Monday, January 26, 2015

Router blocking HTTPS traffic?

Recently I had got a new cloud router for my broadband connection. Though the speed was very good, I was facing intermittent problems in accessing HTTPS sites. For e.g. webmail would hang sometimes, payment gateway pages would not load, Amazon app would not load screens, etc.

At first, I was not sure if the router was to blame, or was it the internet connection itself. A quick google search revealed that this is a common problem faced by many routers and had to do with the MTU (Maximum Transmission Unit) size limit. I was surprised that the MTU size would affect HTTPS which is a application level protocol.

The following links show an easy method to find out the correct MTU size for your network using the ping command. For e.g. ping www.google.com -f -l 1472

http://www.tp-link.com/lb/article/?faqid=190

http://www.tp-link.com/sa/article/?faqid=69

Tuesday, May 20, 2014

Appending the current date to the file-name in a DOS batch program

I was writing a utility batch for my backup folders and wanted to have the current date appended to the filename. Using just %DATE% was throwing errors as the default output of the date command contains a space on Windows. For e.g. echo %DATE% would return "Tue 05/20/2014".

The following format of the %DATE% command did the job for me. A good trick to have in your sleeve :)
echo %date:~-10,2%-%date:~-7,2%-%date:~-4,4%

This formatting essentially trims chars from the end and then truncates. Just copy-paste fragments of the above string to understand how this works. For e.g. echo %date:~-10%

I had used this to create a date-stamped jar file as follows.
jar -cvf backup_%date:~-10,2%-%date:~-7,2%-%date:~-4,4%.jar data/*

Thursday, January 16, 2014

Advanced search options in Windows Search

I had always been a fan of Google Desktop and it's ability to surface any information hidden under folders. Recently my friend mentioned that the default search available on Windows has also matured and there are a lot of options available for geeks like us :)

The following MSDN site gives the various options that are available for searching your computer for files, once you open the search window using 'Win+f" key.

http://msdn.microsoft.com/en-us/library/aa965711(VS.85).aspx