Archive for the 'Tech' Category

JVM : Out Of Memory PermGen

Interesting thing I did not know about Java – PermGen. Apparently other than just the stack (local variables and methods) and the heap (everything else), java uses this extra storage which can also cause OOMs.

PermGen is where a few very long-lived types of objects are persisted in Java, such as class definitions and ‘intern’ed Strings.  It uses separate storage from the heap and the stack.  If you run out of PermGen you will get out of memory errors.  If you run very low you will get a JVM that spends all its time garbage collecting.

Few things I came about when I googled around:

Luckily I’ve never had to deal with PermGen OOM before. Apparently it’s hell-of-a-job debugging this issue.

From The SDE Tip – Amazon

Popularity: 1% [?]

Mac : Create Password Protected Folder

The Disk Utility app of Mac allows one to create a password protected folder. An encrypted disk image is created. To mount the disk one has to enter the password set at the time of creation. The steps to create one is very easy.

Open up the Disk Utility app. Goto File -> New -> Blank Disk Image. Enter a name for the image. Choose the location. Disk name will be the name of the mounted image. Set a size that you want. Importantly enable encryption from the drop down. And for the image format drop down, select the Sparse Disk Image option. Click on create.

A new window comes up to set a password. Remember to uncheck the “Remember password in Keychain” option. Set the password and you are done.

Double clicking on the image file will bring up a window to enter the password. Authenticate yourself and you’ll see that the image has been mounted. Add files, remove files, etc and do whatever you want to. Remember to eject the image after your work is done.

There you go. A password protected image is all setup.

Popularity: 1% [?]

Impossible Null Pointer Exceptions

I must admit this had never occurred to me before but after reading, the explanation seems so obvious!

You can get NullPointerException from lines in Java which appear to have no possibility of throwing them, such as;

this.setCount(num)

The null pointer exception can come about when num is of type Integer and setCount takes an int parameter. Java’s auto-boxing will automatically call num.intValue(), and if num is null you get an exception.

Of course, the fix is to check for null-ness and treat it however the semantics of your operation requires.

From the SDE Tip – Amazon

Popularity: 1% [?]

Find Files Of A Given Name Instantly

Usually when I have to find a file, I use a find and a grep command together – because I still haven’t learnt to use find properly. This is what I do:

find -L . | grep <name>

But this process is usually slow as it traverses the whole directory structure recursively following the symlinks to find all the files and then greps for the name that I need.

Recently I learnt about a faster way of doing the same – use locate to find files of a given name quickly. The command is:

locate <name>

It creates an index of all the files on the system and searches off it when called for. The index is rebuilt (by default) once a day by a cron’d find so results maybe stale by 24 hours.

If locate is not already present on your system, you could install it by:

sudo yum install mlocate

From the SDE Tip – Amazon

Popularity: 1% [?]

Save File With Sudo Permissions In VIM

A lot of time I open a file, make changes and when the time comes to save it realize that I hadn’t sudo’ed it. Learnt that the following command helps:

:w ! sudo tee %

Here’s the reason:

:w tells the vi to save modification of the file

! sudo tee executes the tee command with sudo permissions taking it’s input from :w

% here means the current file name

From the SDE Tip – Amazon

Popularity: 1% [?]

Kill A Process Running On A Particular Port In Windows

This has become a very common scenario for me these days. I have my grails application running on localhost:8080 and at times I need to manually kill the process. I am writing down the steps so that I know where to look it up quickly.

  • List the processes running on ports
    • netstat -a -o -n
  • Find the one you need. I search for 0.0.0.0:8080 and get the PID.
    • taskkill /F /PID <pid>

Task complete!

Popularity: 1% [?]

Weird Issue With Urchin Campaign Tracking

Urchin has this feature to track campaigns. One can use the utm_source, utm_medium, etc; variables to track which of the campaigns drive greater traffic to the website. There is no extra setup required. I just consolidated all the information required to decorate the campaign urls and gave the wiki link to the pms.

Our website requires one to be logged in. Being signed out, if one were to enter the url to a page which required the user to be logged in, the website redirects to the login page even before urchin can kick in and set the campaign cookies. After the login procedure we redirect the user to the same url he had entered – the one which contained the utm_source variable. So, logically speaking Urchin should be setting the right campaign values here. This is where things started to go wrong. Urchin did not set the correct cookie values!

To make things more bizzare, no matter how many times you refresh the page Urchin would just disregard the utm variables. But if the same link was to be copied and pasted into a new tab Urchin would kick into life and recognize the campaign parameters. The same url getting differential treatment! World is not fair.

The issue was killing me. That is when I checked the window.location in the browser console. And guess what I found out? The first url had encoded characters – _ converted into %5F. So the utm_source variable becomes utm%5Fsource! Obviously Urchin could not find any tracking variables in the url. I changed the code to un-escape the login redirect url and things worked like a charm.

Otherwise a simple problem, it became complicated in this case because my browsers were always showing the url to contain utm_source variables whereas the window.location was actually utm%5Fsource. I never knew that the two could differ.

Popularity: 2% [?]

Quora Topics Need Time Expiration

People ask a lot of questions which make sense only with some time reference. For example, there’s this question -

Will Chelsea win the Premiere League in the 2010/11 season?

The question was asked in February 2011 when Chelsea and Manchester United were to play each other twice. It made sense to discuss that topic then. Fast forward to the current date – 8th of May 2011 with both the games over. We are left with only 2 games and Manchester United have a lead of 6 points. The same question has lost its sense now. A couple of weeks later, the question would be simply pointless.

Quora should allow users to set an expiration time for a question. After the expiry date, people will not be allowed to comment on the question or post a new answer. However one can always view the question and refer it later.

Popularity: 3% [?]

My Gmail’s Gotten Too Slow

I love Gmail. I’ve used it as the only mail service since 2005. And thanks to the generous capacity, I’ve never had to delete any conversation. The tons of thousands of chat logs are all archived in my account. And when they rolled out the labels feature, I adopted it pretty quickly and cleaned up my inbox.

I am currently using 1808 MB of space – 23% of their allotted capacity.

But I have a complain now. My gmail’s gotten too slow! It’s not because of network issue. At home I have a 4mbps broadband connection. And yet I have to wait for like half a minute after sign-in action for the inbox to appear. Also when I send a mail, it takes forever. In fact, it has now become a routine for the message – Sending – to appear when I hit the send button.

And apparently, I am not the only one. Read this article at TechCrunch : http://techcrunch.com/2011/04/05/gmail-new-deal/

I know a few seconds or a minute is not going to kill me. But I hate having to stare at empty screen waiting for the action to complete. It’s the user experience which is being effected now.

I can only hope that whatever issue is causing the latency gets resolved soon.

Popularity: 5% [?]

Firefox Awesome Bar Auto Complete

The Awesome Bar of Firefox is too good. However, when compared to Google Chrome’s bar it lacks in one aspect. Search for single keywords.

I always use the location bar to search. Say I wanted to lookup the techcrunch webpage. In Chrome all I have to do is to type techcrunch and hit enter. The Google search shows me the result. In Firefox the same does not happen. Instead, Firefox interprets the single keyword as http://techcrunch/ and then goes on to display an error page. Shucks!  They force me to either break up the keyword into two, for example; as tech crunch, or else open google.com and then search for the single keyword.

That is when I stumbled across a plugin for Firefox which does the instant search thing. Good though it was, I decided to get rid of it after just an hour. The reason? Well, it required me to type g every time if I wanted google search. And habits are not easily changed.

But after removing it, I noticed that my Awesome Bar wasn’t showing me the drop down option bar as it used to earlier. Upon googling, I found that the config can be corrected by going to the about:config and searching for the keyword browser.urlbar.

I noticed one another config option that was turned off by default: browser.urlbar.autoFill. Turn this on, and Firefox will try to auto-complete the search string using the best option from the Awesome Bar, mimicking Chrome’s behavior.

Awesome Bar just got more Awesome!

Popularity: 8% [?]