Friday 30 September 2016

Trigger an event in input text after I stop typing/writing?

How to trigger an event in input text after I stop typing/writing?



You need to include:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<input type="text" id="example" />//
// $('#element').donetyping(callback[, timeout=1000])
// Fires callback when a user has finished typing. This is determined by the time elapsed
// since the last keystroke and timeout parameter or the blur event--whichever comes first.
//   @callback: function to be called when even triggers
//   @timeout:  (default=1000) timeout, in ms, to to wait before triggering event if not
//              caused by blur.
// Requires jQuery 1.7+
//
;(function($){
    $.fn.extend({
        donetyping: function(callback,timeout){
            timeout = timeout || 1e3; // 1 second default timeout
            var timeoutReference,
                doneTyping = function(el){
                    if (!timeoutReference) return;
                    timeoutReference = null;
                    callback.call(el);
                };
            return this.each(function(i,el){
                var $el = $(el);
                // Chrome Fix (Use keyup over keypress to detect backspace)
                // thank you @palerdot
                $el.is(':input') && $el.on('keyup keypress paste',function(e){
                    // This catches the backspace button in chrome, but also prevents
                    // the event from triggering too preemptively. Without this line,
                    // using tab/shift+tab will make the focused element fire the callback.
                    if (e.type=='keyup' && e.keyCode!=8) return;
                    
                    // Check if timeout has been set. If it has, "reset" the clock and
                    // start over again.
                    if (timeoutReference) clearTimeout(timeoutReference);
                    timeoutReference = setTimeout(function(){
                        // if we made it here, our timeout has elapsed. Fire the
                        // callback
                        doneTyping(el);
                    }, timeout);
                }).on('blur',function(){
                    // If we can, fire the event since we're leaving the field
                    doneTyping(el);
                });
            });
        }
    });
})(jQuery);

$('#example').donetyping(function(){
  $('#example-output').text('Event last fired @ ' + (new Date().toUTCString()));
});That will execute when:
  1. The timeout has elapsed, or
  2. The user switched fields (blur event)
(Whichever comes first)

Monday 26 September 2016

Start multiple servers for same project with different ports

Rails uses the pid of your running server to check whether a server is already running or not.
This is stored under tmp/pids/server.pid If you want to run the same application again , you need a different pid for your server.
rails s -p 4000 --pid tmp/pids/server2.pid
Happy Coding..!!

Friday 23 September 2016

How to hide border of overlapping div using css

Just use below mentioned code to hide overlapping border of two div. 


.class_name + .class_name {
border-top: none;
}

Wednesday 21 September 2016

Open mail box by clicking email id and calling functionality on click of mobile no

It will open mail popup if user is already login/ thunder mail implemented

<%= mail_to @contact_email %>

In view page to add calling feature for mobile number (for mobile view) - Use gem 'tel_to_helper'

<%=tel_to @contact_phone %>

Tuesday 20 September 2016

Ruby On Rails Database Backup and Restore


MySQL


You can backup your MySQL data by using the mysqldump command. This command connects to the MySQL server and creates an SQL dump file. The dump file contains the SQL statements necessary to re-create the database.


Backup:

mysqldump -u user -p database_name > dump.sql
(Enter password)

Restore:

mysql -u user -p new_database_name < dump.sql
(Enter password)



Postgres Database backup and Restore to dump file

Here is the quick snippet of how backup and restore postgres database 

Backup:

1

"pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"

Restore:

1

"pg_restore --verbose --host #{host} --username #{user} --clean --no-owner --no-acl --dbname #{db} #{Rails.root}/db/#{app}.dump”


Postgres Database backup and Restore to sql file



Backup:

1

$ pg_dump -U {user-name} {source_db} -f {dumpfilename.sql}

Restore:

1

psql -U {user-name} -d {desintation_db}-f {dumpfilename.sql}