Tuesday 6 September 2016

Disable f5 and browser refresh using javascript | Inside Window or Iframe

Disable f5 and browser refresh using javascript | Inside Window or Iframe

Javascript code:

function disableF5(e) { if ((e.which || e.keyCode) == 116) e.preventDefault(); };
$(document).on("keydown", disableF5);


Friday 12 September 2014

TOP Free and Paid APIs to kickstart your job board web application

Start your Job Board online website application with these free and pay per query APIs.

What is Free and Paid API?

           Free API are 100% free of cost. You don't have to pay nothing for these API calls. But Paid API are provided as pay per usage basis. for example, if you make 10 API calls then you will be charged some dollar as fee.Don't Worry most of Jobs APIs are almost come with free of cost. So you can Go ahead without any worry.

How to use these APIs?

      These APIs can be called in two ways,
  • Normal HTTP calls. 
  • SOAP webservice
And you can get results of these API calls in either JSON format or XML. Finally you can use in your applications easily.

Here is the list of  TOP Free and Paid APIs

 

Tuesday 2 September 2014

Ruby on Rails tutorial with Blog application with database and CRUD

Creating a new Rails app:

 

after successful Rails installation in a machine do the below steps:

1. Open command prompt and type:

$ rails new my_app_name

2. Move to the current application directory:

$ cd my_app_name

3. Next Start web server as below:

$ rails server

4. Open your browser and goto:

http://localhost:3000

Blog Application with Database and CRUD operations

Usage Specficiations:

– Blog is a discussion or information site published on the Web.

We will have two types of users
         –  The blog administrator and 
         – Blog users.

The blog administrator able to enter new posts.

Users able to visit the blog site, and enter comments for postings.

– The blog administrator can modify/remove any post or comment.

– Finally users should not be able to modify postings or other users’ comments.

Before we move on Please have a look at below videos:

Blog Application tutorial – Initial Steps to do

Our First step is to create the rails application as mentioned below: 

$ rails new blog  

Next, use the scaffold generator to create the MVC components needed for posts and comments: 

 $ rails generate scaffold post title:string \ body:text $ rails generate scaffold comment post_id:integer \ body:text


Now, create the database tables for post and comment using: 

$ rake db:migrate


If you type: 

$ rake routes a list of all the URLs currently recognized by your application will be provided.

At this stage all necessary files (model, view and controller) are generated successfully. But You didn't write even a single line of code. Framework done all the works for you.  

 Start the web server: 

$ rails server and point your browser to: http://localhost:3000

That's it. Your first blog application powered by ruby on rails is created.

What is next?
  
           We have just created a new application with basic design. Further more we need to work on design and validation part.

Where to work on validation and Design?
     
         Design works can be done at view files and Validation can be done at Model and controller files.
 

Thursday 17 April 2014

Yii Framework Tutorial Set 2

cont......

       Before reading this post you must read my previous post Yii Framework Tutorial Set 1. Its been a long time i am writing this post, because i was busy with my Yii projects. In the previous post you have successfully installed Yii framework application. You can check it at this below url:

http://localhost/firstapp/index.php
 
If everything is Ok, it will be like this.
 
Source: yiiframework.com
 
You can change the contents of this home page at
protected/views/site/index.php .
in the same way you can edit about us page at
protected/views/site/pages/about.php
contact us page at
protected/views/site/contact.php
log in page at
protected/views/site/login.php
and finally error page at
protected/views/site/error.php


YII CHANGE APP NAME:

           In default, The application name will be "My Web Application". You can change this to your preferred name at protected/config/main.php . You have to change the 'name' parameter in array. In the same file you have to change Database details also. In default, DB connection is connected to SQLITE database. So, you must change the DB Details also.
 

YII LAYOUT:

        Do you confused by thinking from where this layout came? The main layout files for yii framework is in  protected/views/layouts/ .
at this layouts folder you can see three different files as below.
  • main.php
  • column1.php
  • column2.php
It means in default we have two different layout at present (You can also add layout files and modify these two files based on you view). As the name suggests the difference between these two layout is first one is single column and second is double column with sidebar. Where does the layout file is selected?      The layout for particular page or view can be selected in their respective controller file. For instance, in controllers/sitecontroller.php we have variable $layout. In this variable we have to specify either column1 or column2 (note: don't use column1.php and column2.php, Yii will point this automatically. In the same way at any situation in you want to include any file don't use php extension).

YII FRAMEWORK CSS STYLING:

         When you open these layout files, index.php, contact.php all html elements will use blueprint css framework. I prefer you to go through this blueprint css at their official website http://www.blueprintcss.org. for your reference i will give you one example:
          To design a DIV with 590px you can specify class name as span-15. 
So, you don't need to write your own css for each and every html elements. Once again i am asking you to read about blueprint css framework to design your application effectively.        

 

       

Tuesday 8 October 2013

Yii Framework Tutorial Set 1

Installing Yii:       

Installing of Yii Framework in your server is not a big thing. It is a quit simple to do. Even a person with not having web experience can also do it.

Installation involves only two steps:     

1. Download latest and stable version Yii Framework from yiiframework.com. Note this is free since it is a open source.   

2.Unzip the Yii file to a Web-accessible directory (Means in your server either local server or web-hosted server).      

That is it. You have done it. Now you can access Yii framework Since you have installed.
 
This insallation process does not end with just unpacking it in your sever. You have to do one more thing called Requirement checkup as below. It is mandatory to check it up because because this will let you know whether your server has satisfied all the requirements of yii framework. These requirements includes php version, database and so many other things.

to do this just paste this your in your browser.
http://hostname/path/to/yii/requirements/index.php

if it is local server the http://hostname/yii/requirements/index.php
your browser will display the following thing.

all the things must be passed and should not fail. You may get some warnings but that problems wont lead to huge problems.

Important:
          Yii Framework requires PHP 5.1, so Your server must have PHP 5.1 or above version of PHP. Yii team have tested yii framework with Apache HTTP server on Windows and Linux and It may also run on other Web servers and platforms, provided with PHP 5.1 or above version of PHP as mentioned in their site.

Don't forget to view my tutorial on youtube at https://www.youtube.com/watch?v=G7_2tdZRQnE

Your First Yii Application:

           It will be easier to create basic app with yiic (command line tool) in Yii Framework. We have an another tool Gii (powerful web based code generator) to automatically create code for certain tasks like CRUD Operations.

To create basic skeleton for Yii App:


% cd WebRoot
% php YiiRoot/framework/yiic.php webapp firstapp

Where,
Webroot -> Your your web root location
php -> your php.exe location
firstapp -> the folder in which you create your app

These works are done by yiic, this is a command line tool provided by yii team.

Nice it is quit nice to do know.
 
  That is it you have created basic structure for yii application.

NOTE:

Please continue this in my next post at http://webdevelopmentcodes.blogspot.in/2014/04/yii-framework-tutorial-set-2.html and don't forget to view my video at https://www.youtube.com/watch?v=G7_2tdZRQnE


Friday 23 August 2013

Side Bar in Yii Framework

Introduction:

In this post I will show you how to put sidebar in Yii framework Web application.

This Sidebar can be displayed on the left or right side of the browser. This slides in on mouse over on the sidebar and slides out automatically when user mouse leaves the sidebar.

Already we have leftsidebar and rightsidebar extensions in Yii framework. But these can be used to display sidebar on either left side or right side of the browser.

But this extension will avoid the use of two different extensions for displaying sidebars on left and right side of browser.

This sidebar can be used to display menu or some other useful things in your application.

 Download and Usage Details:

     You can download this extension at http://www.yiiframework.com/extension/sidebar/ . For Further Comments Please comment below.

      Extract folder to your protected/extensions/ folder.

Example Usage:

You have to specify 'position' to be left or right. If you don't specify it will display in right side. 



in Your view file



$this->beginWidget('application.extensions.sidebar.Sidebar',
array('title' => 'Menu', 'collapsed' => true, 
'position'=>'left'));

//here you display a cmenu or gridview or any other 
thing as per your needs.
//or you can simply display contents form variable like below

echo $var;
$this->endWidget();






If you don't specify 'position', Then a right sidebar will be displayed by default. So, if you want a right sidebar then you don't need to specify position in the widget.

Result:

Like below a sidebar will b shown either left or right side of your browser based on 'position'.

 Arrow mark as in rightsidebar extension:

You can able to display an arrow mark in your sidebar by just doing some modification the extension. For this do the below steps.

In Sidebar/sidebar.php change the below things

Step 1: Change This,
echo '<div class="title">' ;
        echo  CHtml::encode($this->title);
 echo '</div>';

To,


echo '<div class="title">' ;
        echo CHtml::encode($this->title);
        echo CHtml::ajaxLink('&gt;&gt;', '', false, array('id' => 
 'toggle_left_menu'));     
        echo '</div>';



Step 2: Change This, 
echo '<div class="title">' ;
  echo  CHtml::encode($this->title);
        echo '</div>';

To,

echo '<div class="title">' ;
        echo CHtml::encode($this->title);
        echo CHtml::ajaxLink('&gt;&gt;', '', false, array('id' => 
 'toggle_right_menu'));
        echo '</div>';
 
and in js folder, 

Step 3: In leftsidebar.js line 64 change Pin and Hide.
Step: 4 And finally in rightsidebar.css line 61 change float to right.

That is it. Now a arrow mark will be displayed in the sidebar. You can click on the arrow mark to display and again click to hide the sidebars.

I think it is useful to someone.


Saturday 1 June 2013

How to Use Jquery?

Introduction:

           Jquery is a lightweight JavaScript Open Source library. jQuery is to make it much easier to use JavaScript on your website since it is a Lightweight Component.

jQuery almost simplifies lots and lots of lines in basic javascript and do the same task within a single line. So most of developers use jquery only instead javacsript.
The scope of jquery just not end with javascript task, With this jquery we can do
               ->Ajax calls(with this you can call a PHP page and insert or change data)
               ->DOM (Document Object Model) Manipulation
               ->We can change CSS of the Page
               ->Add Effects to text or images
               ->And lots more
Before Starting to work on this you must know,
  • HTML
  • CSS
  • Javascript 

How to use:

        Before using Jquery You must have jquery library. You can download it from Jquery.com for free of cost. Then insert it in your html page like you insert your javacsript page that is it. Here i will show you a demo,
 <head>
<script src="jquery.js"></script> //this is your downloaded jquery librray
</head>

Syntax:

<script type="text/javascript">
$(document).ready(function(){
//here goes your jquery functions
  });         
 </script>
               
$(document).ready(function(): Always we must start to use jquery function within this function. The Reason is we must start functions once our document is fully loaded in the page else it will not be a safe one, It results in unwanted actions.

Examples with explanation: 

Let's say we want to hide all <h2> elements in the page. It can be done easily in this jquery.

HTML: <h2>Heading name</h2>
to hide the h2 element You just use this:
       $(document).ready(function(){
    $("h2").hide(); //this will hide the h2 elements fully
  }); 
         The above code hides all h2 elements in the entire page. But if we need to hide only a particular h2 element in the page then we have to use selectors.
What is selector?
           Selector is a Class or ID of the particular element. Let me explain with our above h2 example
HTML: <h2 class="classname" id="idname">Heading name</h2>
 In this example we have two selectors "classname" (via class) and "idname" (via id).
Note: We have to use classname selector as .classname and idname as #idname in jquery function
  
Now move to our problem, Our jquery code here hides all h2 elements. We have clear this problem with this selectors help. Here is the trick
$("#idname").hide(); //this will hide elements only with "idname"
$(".classaname").hide(); //this will elements only with "classname". 

Other Selectors in Jquery:

$("*")   It selects all elements       
$(this)   It selects current element    
$("p.intro")   It selects <p> element with 'intro' as classname
$("p:first")   It selects first <p> element in the entire DOM
$("ul li:first")   It selects first <li> element in first <ul>
$("ul li:first-child")   It selects first <li> element in all <ul>
$("[href]")   It selects all element with href as attribute
$("a[target='_blank']")   it selects all links with target value as blank
$("a[target!='_blank']")   it selects all links with target not as blank

Friday 17 May 2013

PHP file upload and Saving

PHP file upload and Saving:

                PHP file upload and saving in server is simple. We need to have a HTML form and PHP script to get the file and upload to server. Here i am going to tell you the step by step guidance to do this.

  HTML form:

<form action="file.php" method="post" enctype="multipart/form-data">
//First start aform tag, Method may be POST or GET. POST method is recommended since it is secured, Then encryption type
<label>File Name:</label>
//this is jus a label
<input type="file" name="myfile" id="myfile"><br>
//file is the tag to upload files
<input type="submit" name="submit" value="Submit">
//this is normal submit button to submit the form
</form>
//that's it

Now we have to write PHP script to do further things.

PHP Script(file.php); 

The following code is to just verify whether file is uploaded correctly or not. Later i will show you how to store the uploaded file into server.
<?php
if ($_FILES["myfile"]["error"] > 0)
//first check whether errors are there or not. If not then proceed
  {
  echo "Sorry Have some Error: " . $_FILES["myfile"]["error"] . "<br>";
//Displays error message and exact reason for error
  }
else
  {
//if no error then display details of file
echo "Well your file has been uploaded successfully in to server";
  echo "File name: " . $_FILES["myfile"]["name"] . "<br>";
  echo "Your File Type: " . $_FILES["myfile"]["type"] . "<br>";
  echo "Your File Size: " . ($_FILES["myfile"]["size"] / 1024) . " kB<br>";
  echo "Your file stored : " . $_FILES["myfile"]["tmp_name"];
  }
?>
That is it. Now we move on to PHP script to to store files in server Location

 PHP Script:(to store in file)

  As everyone do, We also Store files in Upload folder. Here is the code for that. Just copy and paste it after above code. If you do like this then you can able able to see uploaded file information and success message if uploaded correctly.
if (file_exists("upload/" . $_FILES["myfile"]["name"]))
//we must check whether file is Already exist or not. We must do it for hassle free operation
      {
      echo $_FILES["file"]["name"] . " already exists. ";
     //if it exist then we have to say exist
    // we can upload even if it is already exist by renaming it. I showed you the codes below for that
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["myfile"]["name"]);
//it is PHP function to move files to server
      echo "Stored in: " . "upload/" . $_FILES["myfile"]["name"];
//final message to echo stored location
      }

PHP script:(to rename before Store in folder)

 Always we need to rename the files before saving to server. Because users may upload files with same name. If that happens then the old file with same name gets replaced with new one. So we need to rename all files before uploading to server. For that use the below piece of code:  $randomdigit=rand(0000,9999);
//generate a randome number. You may use letters or alphanumeric also
$filename=$_FILES["myfile"]["name"];
//get the filen ame in to $filename
$newfilename=$randomdigit.$filename;
//Now combine random number and filename to get ne file name
$path= "resumes/".$newfilename;
$path variable holds the location of folder
copy($_FILES["file"]['tmpname'], $path);
//this php function can also upload files to server like move_uploaded_file

Check one more time whether new file name is exist in upload/ folder. If it exists the generate random number one more time and then copy to server.

That is it.