Sid’s Blog

(life => life.make_it_better)

Why does my mac terminal still uses an older version of Java?

| Comments

While I was working on my mac, I got a pop up to update Java running on it. I did all the process that was required. It was also needed by one of my application being developed in Android Studio on latest platform. But when I checked the version number using System Preferences > Java which opens the Java Control Panel in a separate window. If you click on the About button under General tab of this new window, it displays the Version details which said the following and with other copyright information:

Introduction to Dependency Injection

| Comments

What is Dependency Injection?

In simple words, Dependency Injection (DI), is a type of IoC where the creation and binding of a dependency is moved outside of the class that depends on it.

Say suppose when you pack your lunch, you know what you have packed inside it. But when you know that the food will be provided, you know that you need not to worry about lunch, it will just be served when you need it.

Similar to above example, when you don’t use DI, your class will have the creation and binding of dependencies inside it. But when you use DI, your class will just work taking into consideration that the required dependencies will be provided by a service.

Introduction to Inversion of Control

| Comments

What is Inversion of Control (IoC)? IoC is basically a pattern that we use to apply Depenency Inversion Principle. Most people mix DIP, IoC and DI together! Its good to have your concepts clear.

How does IoC relate to DIP? Please read my post about DIP. This priciple says that the high level module should not depend on low level module.

Introduction to Dependency Inversion Principle

| Comments

Vocabulary required for this article:

  • Dependency Inversion Principle (DIP): This is a principle used in architecting software.
  • Inversion of Control (IoC): This is a pattern used to invert interfaces, flow and dependencies.
  • Dependency Injection (DI): This is the implementation of IoC to invert dependencies.
  • Inversion of Control Container: A framework to do dependency injection.
  • Interface: The term interface will refer to externally exposed way to interact with something.

What is Dependency Inversion Principle?

Many developers gets confuse and mix up the terms like DIP, IoC and DI without even understanding the concepts. The root that one needs to know is DIP. It basically states that instead of lower level modules defining an interface that higher level modules depend on, higher level modules define an interface/abstraction that lower level modules implement.

How to compress, decompress a string in c# using GZipStream?

| Comments

I recently had a scenario where my application was sending raw json data to send to the browser in string format. This data was used as a viewstate by using hidden input element. When the app started to run in production envrionment, we realised that this raw data is very big in size and needs to be compressed.

So, the only solution available here was to compress the raw data and decompress it when app wants to access the data. Both needs to happen server-side. My app uses .NET v4.5, so I thought to use the out of the box classL GZipStream

How to customize Chrome Developer Tools?

| Comments

I spend most of my programming time within Visual Studio and I never liked the white theme that came out of the box. Same is with the Chrome Developer Tools. I use Dark theme for Visual Studio and want something similar for Chrome as well.

In version 32, custom.css was removed from Chrome. I’ll be using an theme extension to setup a custom theme. The old way was to play with a local css file that you can rely on or add your own files.

Use your own font everywhere

| Comments

Have you spent any time thinking of which font to choose while writing a word or any other document either on your laptop, online, etc.? Will it not be easier to have your own handwriting available to you even when you don’t hold a pen in hand and instead press keys on laptop?

I answered it as ah yes, but that must be hard? No, its not. Some dev friends have created a free tool that can be used by anyone to create a font based on your handwriting.

How to get version or product details from a .dll file or running application?

| Comments

I came across a scenario where I had to access some information from a file with .dll extension. And then I thought to write this post. This information may include that assembly’s product name, product version, file version etc. This scenario may be required either to read a .dll file from disk or from the current running application. The code below covers both the scenarios:

1
2
3
4
5
6
7
8
9
10
11
// From executing application.
string assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();

// From a physical file, provide full path to that file.
string assemblyVersion = Assembly.LoadFile('your assembly file').GetName().Version.ToString();

// From executing application, gives file version.
string fileVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion;

// From executing application, gives product version.
string productVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;

HTML5 LocalStorage API to the rescue

| Comments

Recently I had a need to use HTML5 LocalStorage API in my web application project. The requirement was to save the vertical scroll position of window when a user drills down to low level details by navigating to other view. I didn’t wanted to cookies because cookies are sent on every request to the server and I have no need to send this detail to the server as it is just related to client.

Then I was left with LocalStorage and SessionStorage as options. I found that SessionStorage is not maintained when the page reloads and when the browser is closed.

How to get UnAuthorizedAccess (401) HTTP response when using ASP.NET Forms Authentication and AJAX?

| Comments

I’ve a ASP.NET MVC application that uses FormsAuthentication and this application gives single page application experience to users after a user is authenticated where it uses AJAX for all HTTP requests.

The log out action that I have works fine if user uses the logout button in the user interface and the click handler than performs a HTTP POST to Logout action in Account controller.

Today,I was testing some other feature by setting 1 minute timeout for forms authentication in web.config. After a minute, when I performs a POST action to view a different view in my application, I was shown the user login page as set in the web.config under forms configuration. But I was not able to understand why is this happening. Later I figured out that the FormsAuthentication is doing its work and it detects that this user is not authorized. It then redirects the user to the login url as defined in the configuration.