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.