Saturday, April 19, 2014

Dirty checking to warn for unsaved changes using jQuery

Copy following code snippet into the application. dirtyCount() method return the number of fields have unsaved changes.
var dirtyChecking = function () {
    $('input, select, textarea').each(function () {
        var ele = $(this);
        ele.attr('data-old', ele.val());
        // Look for changes in the value
        ele.on("change keyup paste click", function (event) {
            if (ele.attr('data-old') != ele.val()) {
            } else {
var dirtyCount = function () {
    return $('.unsaved').length;

//Call dirty checking
Copy following code to show unsaved changes warning on form unload or can define of your own
//Bind warning message showing on form unload 
window.onbeforeunload = function (e) {
    if (dirtyCount()) {
        var message = 'Any unsaved changes will be lost.';
        e = e || window.event;

        if (e) {
            e.returnValue = message;

        // For Safari
            return message;

Friday, June 21, 2013

Extract Urls from a remote webpage using PHP

Scraping data from website is extremely popular now a days. I have written a simple website parser class to grab all the urls from a website. Shared the class below for all to see and fun.

We will use the parser class below to extract all image sources and hyper links from a website.
Create an instance of WebsiteParser class with a website url to get all the urls from their. And, then call getHrefLinks() and getImageSources() method like below to extract hyper links and image sources respectively.

View Demo :: Try it out and rate on

Wednesday, May 29, 2013

ActionView::Template::Error Couldn't find file 'jquery-ui' with Rails 3.2

Today, I have start working after 6 months with one of my existing Ruby on Rails application and found the mentioned error. And then found, jquery-rails removed the jQuery UI and recommended to use jquery-ui-rails or downgrade the gem version.

To use latest version:
Add jQuery UI in to the application.js:
//= require jquery.ui.all
Add jQuery UI CSS to application.css:
*= require jquery.ui.all

To downgrade the jquery-rails:
Lock the version in to an older version. My problem has been solved with 2.0.2
gem "jquery-rails", "2.0.2"

Saturday, March 2, 2013

SMTP, IMAP and POP server settings

Port 995 25 993
SSL Required Yes Yes Yes
Host NA
Port 110 25 NA
SSL Required Yes Yes NA
Host NA
Port 995 465 NA
SSL Required Yes Yes NA
Windows Live POP SMTP IMAP
Host NA
Port 995 25/587 NA
SSL Required Yes Yes NA
Port 995 587/465 993
SSL Required Yes Yes Yes

Sunday, December 16, 2012

Uninitialized constant ActiveSupport::Dependencies::Mutex (NameError)

This error may occur to run older Rails application for conflicting with rubygems version. After a long googling I've come out in to following three solutions:

Using Bundler.:
Click here if you are interested to see the solution.

Changing rubygems version:
  • Downgrade the rubygems to an earlier version using gem update --system {version}
  • Add "require 'thread'" in to - Rakefile, script/server and config/environment.rb

Upgrade Rails:
Upgrade application in to Rails 3 though it's very hard to do for existing/running rails application.

For me, I was trying to run Rails 2.3.5 application where my system had rubygems 1.8.2. I've changed the rubygems version in to 1.7.2 as mentioned above and everything works fine.