Monday, 17 June 2013

MySql Storage Engine Types


A storage engine is a software module that a database management system uses to create, read, update data from a database. There are two types of storage engines in MySQL. Transactional and non-transactional.

The default storage engine for MySQL prior to version 5.5 was MyISAM. For MySQL 5.5 and later, the default storage engine is InnoDB. Choosing the right storage engine is an important strategic decision, which will impact future development.


List of MySQL supported storage engines:


1.) MyISAM

2.) InnoDB

3.) Memory

4.) CSV

5.) Merge

6.) Archive

7.) Blackhole

8.) Federated

9.) Example



1.) MyISAM:- The default MySQL storage engine and the one that is used the most in Web, data warehousing, and other application environments.It is a fast storage engine. It does not support transactions. MyISAM provides table-level locking.

2.) InnoDB:- A transaction-safe (ACID compliant) storage engine for MySQL that has commit, rollback, and crash-recovery capabilities to protect user data. InnoDB row-level locking (without escalation to coarser granularity locks) and Oracle-style consistent nonlocking reads increase multi-user concurrency and performance. InnoDB stores user data in clustered indexes to reduce I/O for common queries based on primary keys. To maintain data integrity, InnoDB also supports FOREIGN KEY referential-integrity constraints.

3.) Memory:- Stores all data in RAM for extremely fast access in environments that require quick lookups of reference and other like data. This engine was formerly known as the HEAP engine.

4.) CSV:- The CSV storage engine stores data in text files using comma-separated values format. You can use the CSV engine to easily exchange data between other software and applications that can import and export in CSV format.

5.) Merge:- Merge operates on underlying MyISAM tables. Merge tables help manage large volumes of data more easily. It logically groups a series of identical MyISAM tables, and references them as one object. Good for data warehousing environments.

6.) Archive:- Archive storage engine is optimized for high speed inserting. It compresses data as it is inserted. It does not support transactions. It is ideal for storing, retrieving large amounts of seldom referenced historical, archived data.

7.) Blackhole:- The Blackhole storage engine accepts but does not store data. Retrievals always return an empty set. The functionality can be used in distributed database design where data is automatically replicated, but not stored locally. This storage engine can be used to perform performance tests or other testing.

8.) Federated:- Federated storage engine offers the ability to separate MySQL servers to create one logical database from many physical servers. Queries on the local server are automatically executed on the remote (federated) tables. No data is stored on the local tables. It is good for distributed environments.

9.) Example:- The Example storage engine is “stub” engine that does nothing. You can create tables with this engine, but no data can be stored in them or retrieved from them. The purpose of this engine is to serve as an example in the MySQL source code that illustrates how to begin writing new storage engines. As such, it is primarily of interest to developers.

Saturday, 2 March 2013

Beginners Guide : How to Install Node.js


Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.



In simple words – is server-side JavaScript. Every function in Node.js is asynchronous,Node.js uses an event-based server execution procedure rather than the multithreaded execution in PHP.

Node.js provide only an environment – meaning that you have to do everything yourself. There is not a default HTTP server, or any server for that matter. This can be overwhelming for new users, but the payoff is a high performing web app. One script handles all communication with the clients. This considerably reduces the number of resources used by the application.


Installation

if you use Windows or OS X; the nodejs.org website offers installers for those operating systems, go to http://nodejs.org/ and  you can directly install.



Installing on Windows

Probably asks for cygwin packages, if not installed.

The http://nodejs.org/dist/latest/ directory contains the latest .msi package (such as node-v0.6.15.msi when Node v0.6.15 was the latest) that you may use to install both Node.js engine and npm.

Installing on Mac

The http://nodejs.org/dist/latest/ directory contains the latest .pkg package (such as node-v0.6.15.pkg when Node v0.6.15 was the latest).



Building on GNU/Linux and other UNIX

There's a number of ways to install Node.js on Linux
The filenames vary with the Node's version. The following examples are for Node v0.6.18.



Prerequisites:-

1. GNU make 3.81 or newer. Pre-installed on most systems. Sometimes called gmake.

2. python 2.6 or 2.7. The build tools distributed with Node run on python.

3. libssl-dev (Node v0.6.x only.) Can usually be installed on *NIX systems with your favorite package manager. Pre-installed on OS X.

4. libexecinfo (FreeBSD and OpenBSD only.) Required by V8. pkg_add -r libexecinfo installs it.


Do something like this

tar -zxf node-v0.6.18.tar.gz   #Download this from nodejs.org
cd node-v0.6.18
./configure
make
sudo make install


Or, if you'd like to install from the repository 

git clone https://github.com/joyent/node.git
cd node
git checkout v0.6.18     #Try checking nodejs.org for what the stable version is
./configure
make
sudo make install

You may wish to install Node in a custom folder instead of a global directory. 

./configure --prefix=/opt/node
make
sudo make install





Saturday, 23 February 2013

How to Disable Ubuntu’s Guest Account

Here i am giving a quick tip that shows you how to remove / disable the guest account from  login screen of Ubuntu.



By default, Ubuntu is comes with the guest account enabled and shown on the login screen. If you want to remove it .

open the terminal and run below command

sudo sh -c 'echo "allow-guest=false" >> /etc/lightdm/lightdm.conf'


Now Restart your computer and the guest account should be gone.





Friday, 15 February 2013

Installation of Webmin on a CentOS server




Repository Configuration

Before install Webmin, you'll need to set up your repositories to pull the Webmin package via yum. To do this, we need to create "webmin.repo" file in the /etc/yum.repos.d/ directory.

sudo nano /etc/yum.repos.d/webmin.repo

In this file, place the following lines:

[Webmin]
name=Webmin Distribution Neutral
baseurl=http://download.webmin.com/download/yum
enabled=1

Save and close the file.
Now we'll import the GPG key for the repository.

sudo rpm --import http://www.webmin.com/jcameron-key.asc

Now the repository is configured! 

Install Pre-Requisites
Now that we have the software downloaded we need to install a few pre-requisites before installation. Type the following command below to install the required modules:

sudo yum -y install perl-Net-SSLeay
Note: It *is* case sensitive.

Installation
Now it is time to install the Webmin package.To do so, use the command below

sudo yum install webmin

Once the installation has completed you should get the following message:

Webmin install completed . You can now login https:server:10000/ as root with your root password.



Thursday, 14 February 2013

Check your Array type in PHP


if you want to know your array is a numerical or associative for some specific task but PHP don't have any in built functions.i write down one function which return output in Boolean if Array is a Associative it will return True else it will return False..
 

//function
 
 function is_assoc($array) {
 
  return (bool)count(array_filter(array_keys($array), 'is_string'));
 
}


 //test some array
 
var_dump(is_assoc(array('a', 'b', 'c')));  // false(numeric key)
 
var_dump(is_assoc(array("0" => 'a', "1" => 'b', "2" => 'c')));  // false(numeric key)
 
var_dump(is_assoc(array("1" => 'a', "0" => 'b', "2" => 'c')));  // false(numeric key)
 
var_dump(is_assoc(array("a" => 'a', "b" => 'b', "c" => 'c')));  // true(associative key)
 
 
 
 
 

Wednesday, 13 February 2013

Camera and Video Control with HTML5

Client-side APIs on mobile and desktop devices are quickly providing the same APIs.  Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop.  One of those APIs is the getUserMedia API, providing developers access to the user's camera.  Let me show you how to get simple camera access from within your browser!

Demo



The HTML 

Please read my note about the HTML structure below:
<!--
  Ideally these elements aren't created until it's confirmed that the 
  client supports video/camera, but for the sake of illustrating the 
  elements involved, they are created with markup (not JavaScript)
-->
<video id="video" width="640" height="480" autoplay></video>
<button id="snap">Snap Photo</button>
<canvas id="canvas" width="640" height="480"></canvas>


Each of these elements should be created once confirmation of camera support is confirmed, but for the sake of this tutorial, I wanted to show you what the elements look like with basic HTML.  Do note that the dimensions we're working with are 640x480.

The JavaScript

Since the HTML elements above are already created, the JavaScript portion will look smaller than you think:
// Put event listeners into place
window.addEventListener("DOMContentLoaded", function() {
  // Grab elements, create settings, etc.
  var canvas = document.getElementById("canvas"),
    context = canvas.getContext("2d"),
    video = document.getElementById("video"),
    videoObj = { "video": true },
    errBack = function(error) {
      console.log("Video capture error: ", error.code); 
    };

  // Put video listeners into place
  if(navigator.getUserMedia) { // Standard
    navigator.getUserMedia(videoObj, function(stream) {
      video.src = stream;
      video.play();
    }, errBack);
  } else if(navigator.webkitGetUserMedia) { // WebKit-prefixed
    navigator.webkitGetUserMedia(videoObj, function(stream){
      video.src = window.webkitURL.createObjectURL(stream);
      video.play();
    }, errBack);
  }
}, false);
Once it's been established that the browser supports getUserMedia, a simple method sets the video element's src to the user's live camera/webcam.  Calling the play method of the video then enacts the element's live video connection.  That's all that's required to connect your camera to the browser!
Taking a photo is only marginally more difficult.  Simply add a click listener to a generic button and and draw an image from video!
// Trigger photo take
document.getElementById("snap").addEventListener("click", function() {
  context.drawImage(video, 0, 0, 640, 480);
});
Of course you could add some sexy image filters and make a billion dollars...but I'll save that for another post.  At minimum you could convert the canvas snapshot to an image though!  I'll talk about canvas image filters in the future...

Being able to access the camera within the browser without using third party software is an incredible advancement.  Paired with canvas and a bit of JavaScript, the camera has become quickly and easily accessible.  Not only it the camera accessible, but since canvas is ultra-flexible, we'll be able to add sexy Instagram-style image filters in the future.  For now, however, simply accessing the camera in our browser moves us miles ahead.  Have fun taking images within your browser!
Post source davidwalsh.name.


Tuesday, 12 February 2013

Store any language data in your Mysql Database with unicode solution

Do you want to use any language data in your data base like Hindi(हिंदी), Chinese(中国的), Arabic(العربية), Russian(русский) etc...

Follow some Steps:-

Step First: SET THE CHARSET TO UTF-8 IN THE HEAD SECTION 

First of all, the browser needs to know that you are going to display or use Unicode in this page. So, go to your <head></head> section and set the charset to utf-8. So, the browser will be able to show the Unicode text without any error and smoothly. 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
......
</body>
</html>

Step Two: CREATING THE DATABASE

When you create your (a) Database and (b) any Table in the database, set the Collation of both of them to utf8_unicode_ci.

Step Three: DATABASE INITIALIZATION

When you initialize the database connection, please add the “extra lines” in your database file.
 
define('HOSTNAME', 'localhost');
define('USERNAME', 'user_name');
define('PASSWORD', 'password');
define('DATABASE', 'database_name');

$dbcon= mysql_connect(HOSTNAME, USERNAME, PASSWORD); 

mysql_query("SET character_set_results=utf8", $dbcon);
 
mb_language('uni');
 
mb_internal_encoding('UTF-8');

mysql_select_db(DATABASE, $dbcon);
mysql_query("set names 'utf8'",$dbcon); 

mysql_query("SET character_set_client=utf8", $dbcon);
 
mysql_query("SET character_set_connection=utf8", $
dbcon); 

mysql_query("SET character_set_results=utf8", $dbcon);


Now you can easily select,insert and Update any Language data...









Sunday, 10 February 2013

AUTO REFRESH DIV CONTENT USING JQUERY AND AJAX

So today I needed content in a div to refresh every 5 seconds so I decided to do a quick demo to show you how it can be done. It initially loads the content using AJAX shorthand method .load() and then simply sets a recurring call for the data every 5 seconds.

Demo
The demo displays the latest blog posts from the rss feed on my blog and displays the date and time for the latest data refresh. I’ve also hooked up a loading image for the AJAX requests using $.ajaxSetup() but this is optional if you didn’t want to see a loading image you could remove this code or even display a smaller loading image so the data is still visible on screen while the new data is loading asynchronously.


jQuery and AJAX Call Code:-
(function($)
{
    $(document).ready(function()
    {
        $.ajaxSetup(
        {
            cache: false,
            beforeSend: function() {
                $('#content').hide();
                $('#loading').show();
            },
            complete: function() {
                $('#loading').hide();
                $('#content').show();
            },
            success: function() {
                $('#loading').hide();
                $('#content').show();
            }
        });
        var $container = $("#content");
        $container.load("rss-feed-data.php");
        var refreshId = setInterval(function()
        {
            $container.load('rss-feed-data.php');
        }, 9000);
    });
})(jQuery);
PHP Data Script Code :-
This PHP script loads the blogs RSS feed and sends back the data along with the current date and time.
<?php
$feed_url = 'http://blogoola.com/blog/feed/';
$content = file_get_contents($feed_url);
$x = new SimpleXmlElement($content);
$feedData = '';
$date = date("Y-m-d H:i:s");

//output
$feedData .=  "<ul>";
foreach($x->channel->item as $entry) {
    $feedData .= "<li><a href='$entry->link' title='$entry->title'>" . $entry->title . "</a></li>";
}
$feedData .= "</ul>";
$feedData .= "<p>Data current as at: ".$date."</p>";

echo $feedData;
?>

Full Code:-
<html>
<head>
<title>Auto Refresh Div Content Demo | jQuery4u</title>
<!-- For ease i'm just using a JQuery version hosted by JQuery- you can download any version and link to it locally -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
(function($)
{
    $(document).ready(function()
    {
        $.ajaxSetup(
        {
            cache: false,
            beforeSend: function() {
                $('#content').hide();
                $('#loading').show();
            },
            complete: function() {
                $('#loading').hide();
                $('#content').show();
            },
            success: function() {
                $('#loading').hide();
                $('#content').show();
            }
        });
        var $container = $("#content");
        $container.load("rss-feed-data.php");
        var refreshId = setInterval(function()
        {
            $container.load('rss-feed-data.php');
        }, 9000);
    });
})(jQuery);
</script>
</head>
<body>
<div id="wrapper">
    <div id="content"></div>
    <img src="loading.gif" id="loading" alt="loading" style="display:none;" />
</div>
</body>
</html>


Taken from jquery4u.com