Set default index.html page in NGINX

By , July 23, 2016 4:54 pm

Recently I setup Jekyll-Blog on nginx server which is pure html code.  When I tried to call url without index.html (http://domain.com/blog/) in path, it was not working.

To allow default index.html, I need to change following in /etc/nginx/nginx.conf file

from


default_type application/octet-stream;

to


default_type text/html;

and restart nginx server.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Webnews
  • Digg
  • del.icio.us
  • Reddit
  • Bloglines
  • LinkedIn
  • YahooMyWeb
  • Facebook
  • Google Bookmarks
  • Mixx
  • MySpace
  • Technorati
  • TwitThis

Custom error pages in Rails 3.2+

By , June 11, 2016 3:04 pm

Here are steps to show custom error pages in Rails 3.2+
1. Register your own app as the application responsible for showing error pages by adding

 config.exceptions_app = self.routes 

2. Add routes for the error pages, by appending this to your config/routes.rb:


match '/404' => 'errors#not_found'
match '/422' => 'errors#server_error'
match '/500' => 'errors#server_error'

3. Add an ErrorsController like this one:


class ErrorsController < ApplicationController
skip_before_action :verify_authenticity_token

def not_found
render :status => 404, :formats => [:html]
end

def server_error
render :status => 500, :formats => [:html]
end
end

4. Add the corresponding views.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Webnews
  • Digg
  • del.icio.us
  • Reddit
  • Bloglines
  • LinkedIn
  • YahooMyWeb
  • Facebook
  • Google Bookmarks
  • Mixx
  • MySpace
  • Technorati
  • TwitThis

Uploading file with Ajax, without submitting a form

By , March 1, 2016 5:05 pm

Here is the code for uploading an image or file without submitting a form with Ajax.

For this we will create object of FormData class and will append the properties of the file field in a attribute of FormData object, finally we will set the FormData object with the data key of ajax method of JQuery.

 <input id="avatar" type="file" name="avatar" />
 <button id="upload" value="Upload" />
 $('#upload').on("click", function(){
    var file_data = $('#avatar').prop("files")[0];   // Getting the properties of file from file field
    var form_data = new FormData();                  // Creating object of FormData class
    form_data.append("file", file_data)  // Appending parameter named file with properties of file_field to form_data
    $.ajax({
      url: '/teams/inventories/upload_image',
      dataType: 'script',
      cache: false,
      contentType: false,
      processData: false,
      data: form_data,                         // Setting the data attribute of ajax with file_data
      type: 'post'
    })
  });
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Webnews
  • Digg
  • del.icio.us
  • Reddit
  • Bloglines
  • LinkedIn
  • YahooMyWeb
  • Facebook
  • Google Bookmarks
  • Mixx
  • MySpace
  • Technorati
  • TwitThis

Install FFmpeg on Ubuntu 14.04

By , February 12, 2016 12:09 pm

In this tutorial, I will show you how to install FFmpeg from mc3man ppa.

Add the mc3man ppa:


sudo add-apt-repository ppa:mc3man/trusty-media

And confirm the following message by pressing :


Also note that with apt-get a sudo apt-get dist-upgrade is needed for initial setup & with some package upgrades
More info: https://launchpad.net/~mc3man/+archive/ubuntu/trusty-media
Press [ENTER] to continue or ctrl-c to cancel adding it

Update Package List:


sudo apt-get update
sudo apt-get dist-upgrade

Install FFmpeg Package

sudo apt-get install ffmpeg
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Webnews
  • Digg
  • del.icio.us
  • Reddit
  • Bloglines
  • LinkedIn
  • YahooMyWeb
  • Facebook
  • Google Bookmarks
  • Mixx
  • MySpace
  • Technorati
  • TwitThis

Jquery Validate format of multiple emails

By , November 28, 2013 2:17 pm

Jquery form validator provides email format validation by simply add rule with {email: true} option.

We need often add multiple email address in text area box and validate all email format.

To do this with jquery form validator , we need to add method which check each email and validate format.

Add method multiemails

$.validator.addMethod(
        "multiemails",
         function(value, element) {
             if (this.optional(element)) // return true on optional element
                 return true;
             var emails = value.split(/[;,]+/); // split element by , and ;
             valid = true;
             for (var i in emails) {
                 value = emails[i];
                 valid = valid && $.validator.methods.email.call(this, $.trim(value), element);
             }
             return valid;
         },
        $.validator.messages.email
    );

validate multiple email format

$("#form_id").validate({
   rules: {
   	"email_address": {required : true,multiemails: true}
   }
});
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Webnews
  • Digg
  • del.icio.us
  • Reddit
  • Bloglines
  • LinkedIn
  • YahooMyWeb
  • Facebook
  • Google Bookmarks
  • Mixx
  • MySpace
  • Technorati
  • TwitThis

Panorama Theme by Themocracy