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