Thursday, May 29, 2014

Install and run PHP CodeIgniter under XAMPP in Windows 7




CodeIgniter is a powerful PHP framework 
based on the Model-View-Controller development pattern
Download page:
http://ellislab.com/codeigniter
Documentation page:
http://ellislab.com/codeigniter/user-guide/toc.html

1) Download CodeIgniter_2.1.4.zip and unzip to
C:\xampp\htdocs\xampp\codeigniter\
note I installed XAMPP under C:\xampp
2) Run
http://localhost/xampp/codeigniter/
welcome page should appear.
3) Create test.php under
application/controller
run
http://localhost/xampp/codeigniter/index.php/test
4) configure database\application\config\database.php
In mycase, conect to localhost test database with root and no password
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'test';

Example code:
5) controller test.php
C:\xampp\htdocs\xampp\codeigniter\application\controllers\test.php
<?php

class Test extends CI_Controller {
    public function index() {
        $data = array();
        $this->load->model('Users');
        $user = new Users();
        $user->setUsername("jiansen");
        $user->setPassword("pass1");
        $data['message']= $user->login();
        echo '<tt><pre>' . $data['message'] . '</pre></tt>';
       
        //$this->load->view('magazines');
        echo '<h2>This is a test</h2>';
        $this->load->view('test',$data);
    }
}

?>
6) model users.php
C:\xampp\htdocs\xampp\codeigniter\application\models\users.php
<?php
Class Users extends CI_Model
{

    private $_username;
    private $_password;

    function __construct()
    {
        parent::__construct();
    }
    public function setUsername($value)
    {
        $this->_username = $value;
    }
   
    public function setPassword($value)
    {
        $this->_password = $value;
    }
   public function login()
   {
        $this->load->database();
        $username = $this->_username;
        $password = $this->_password;
        $this -> db -> select('id, username, password');
        $this -> db -> from('users');
        $this -> db -> where('username', $username);
        $this -> db -> where('password', $password);
        $query = $this -> db -> get();
         if($query -> num_rows() == 1)
       {
           return "user name and pasword matched";
       }
       else
       {
         return "user name and pasword not matched";
       }
    }   
}
?>

7) view test.php
C:\xampp\htdocs\xampp\codeigniter\application\views\test.php
<?php
echo "from view ".$message;
?>

Video: Install and run PHP  CodeIgniter under XAMPP in Windows 7

Saturday, May 17, 2014

Set up Git server in Ubuntu 14.04




To setup Git server in Ubuntu 14.04, log in  admin account  in Ubuntu:
1) Install git-core
  sudo apt-get install git-core
2) create   git master firectory, using --bare for not directly editable
sudo mkdir -p /opt/git/directory.git
sudo git init --bare /opt/git/directory.git

3)  create group gitgroup make directory.git and its sub-directories  write permission by  gitgroup
sudo groupadd gitgroup
sudo chmod -R g+ws *
sudo chgrp -R gitgroup *

4) Set sharedRepository true
cd directory.git
sudo git config core.sharedRepository true

5) For test purpose, create new user Andy and assign him to group gitgroup:
sudo adduser andy
sudo groupadd gitgroup


Now in andy account (normal user account):
1) set name and email for git
 git config --global user.email "andy@example.com"
  git config --global user.name "andy"

2) Clone from master, change  192.168.1.80 to your git server IP, a newdirectory /home/andy/directory will be created
 git clone andy@192.168.1.80:/opt/git/directory.git
3)Create a new file README under directory and commit it
cd  directory
 vim README
git add README
 git commit -am 'fix for the README file by Andy'

4) push to server
git push origin master
Reference:
https://help.ubuntu.com/14.04/serverguide/git.html

Video: Set up Git server in Ubuntu 14.04

Sunday, May 4, 2014

Install statistics R and R studio in Windows 7




Statistics R is a free software environment for statistical computing and graphics. It compiles and runs on a wide variety of UNIX platforms, Windows and MacOS. Statistics R can be downloaded from HERE.

After installing R, you can download R studio, which has a better interface than original R. Statistics R studio can be downloaded from HERE.

Both of them are free open source and work for Linux, Windows and Mac.

code example to plot in R and statistics data summary:

x=c(1,2,3,4,5,6,7,8)
y=x
plot(x,y)
summary(x)
Video: Install statistics R and R studio in Windows 7