Roshan Book

My Tech Notebook

Monthly Archives: March 2012

Eclipse based Yii IDE for Ubuntu

1. Install Eclipse Indigo edition javascript  – http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/indigo/SR2/eclipse-javascript-indigo-SR2-linux-gtk.tar.gz

2. Install PDT

3. Install yiiclipse 

Update Site (STABLE): http://yiiclipse.maziarz.org/updatesite/STABLE/
Thanks to http://yiiclipse.maziarz.org/
Advertisements

Starting YII development in ubuntu – Part 1

1. Download yii folder

2. Go to var/www directory in terminal

3. TO create a new project follow:

first you need to get into your webroot by

cd /var/www <– in my case

create a folder that you want your demo to be install in my case I create a folder named ‘blog’ under /var/www/yii/

then set permission to 777 by: sudo chmod 777

then type in the following command

php yii/framework/yiic.php webapp /var/www/yii/blog

if your php program has not been installed, the system will give you an install command then do it and come back to do the same.

then you can access your demo by http://localhost/yii/blog <— in my case

4. To enable gii

go to protected>config>main.php and uncomment gii module

5. To access gii generator go to http://localhost/myproj/demo/index.php?r=gii/default/login

6. To convert url mapping into path format go to config>main.php and uncomment

‘urlManager’=>array(
‘urlFormat’=>’path’,
‘rules’=>array(
‘<controller:\w+>/<id:\d+>’=>'<controller>/view’,
‘<controller:\w+>/<action:\w+>/<id:\d+>’=>'<controller>/<action>’,
‘<controller:\w+>/<action:\w+>’=>'<controller>/<action>’,
),
),

 

7. Passing variable data from controller to view

In Controller

public $message = ‘Hello World rom controller’;

public function actionIndex()
{
$this->render(‘index’,array(‘content’=>$this->message));
}

Now variable content is available to modified

In View

<?php echo $content ?>

Alternatively we could do

<?php echo $this->message   ?>

8. CRUD generation

a) Config database

b) Go to protected>>config>>main.php

c) Uncomment db componenent

d) Give the username , password, and db name

e) Comment out sqlite configuration which lie just above the mysql configuration

 

9. GO to gii

10. Select model generator

11. Enter table details and generate the model

12. We now have Message.php under model directory

13. Now click on CRUD generator

13. Enter Model name

14. Click generate

15. You can try it out by goign to baseurl/modelname

16. Access database content via these codes in controller

public $message = ”;

public function actionIndex()
{ $message=Message::model()->findByPK(3);
$this->message=$message->content;
$this->render(‘index’,array(‘content’=>$this->message));
}

Starting YII development in ubuntu – Part 2

Source: http://yiitutorials.net/easy/easy-url-rewriting-with-yii

Nothing is worse than an ugly URL. Well, Hitler was quite bad, but so are ugly URL’s. Not only are they ugly for your users, but as clever as google is, they are ugly for it too. How is google supposed to know that “products/index.php?cat=3&id=46″ is an iPod nano? Today we will be looking at making the sexiest thing in the world, nice URL’s. Jessica Alba isn’t bad either.

william

Yii makes it insanely easy to rewrite URL’s to whatever you want. All of it is done in our config/main.php. Let’s open that bad boy up and see what’s inside. If you scroll down to around line line 34ish you will see the urlManager. If we uncomment this we get much nicer URL’s straight away. Insead of having ugly variables in the URL we will now have pretty good looking controller/action URL’s. So if we are using our product controller and looking at the browser action the URL would look like “index.php/product/browse”. Not to bad, but what about the index.php? We can take that out using our .htaccess file. Nobody understands. htaccess files, so instead of trying to write your own, just download this one that my friend William gave me. Click here to download it.

Just chuck that in your root directory and you never have to see and index.php again. Now, what about custom URL’s? We want the URL to look like it is an apple iPod. Let’s pretend that the URL now looks like “products/browse/prod/46″. Like I said early, we can make it look like whatever we want! Open up your main/config.php again, and scrolldown to somewhere around line 37ish. You will see:

	'<controller:\w+>/<id:\d+>'=>'<controller>/view',
	'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
	'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

That is Yii’s URL rewriting at work. Now, above that we can add the line:

	'catalogue/apple/ipod'=>'products/browse/prod/46',

Thats it. Now when Yii follows the link “catalogue/apple/ipod” the controller/view variable/value it will open is “products/browse/prod/46″ but the URL will be sexy. Told you it was easy. Stay tuned for our advanced tutorial on dynamic URL rewriting coming one day soon.

 
Posted by admin   @   17 November 20101 comments

 
 

How to install an updated version of PEAR / PHPUnit on Ubuntu?

First, install PEAR.

sudo apt-get install php-pear 

Next, tell PEAR to update its own channel.

sudo pear channel-update pear.php.net 

Then, tell PEAR to upgrade itself to the newest version.

sudo pear upgrade-all 

You should now have the newest version of PEAR installed.

To install PHPUnit, let PEAR know where to find PHPUnit.

sudo pear channel-discover pear.phpunit.de 

Then install PHPUnit. (the -a makes sure all dependency packages are also installed)

sudo pear install -a phpunit/PHPUnit 

Update:

According to the latest PHPUnit installation documentation, you can install PHPUnit with the following commands (make sure you have updated PEAR first):

pear config-set auto_discover 1 pear install pear.phpunit.de/PHPUnit

How to Install Webmin on Ubuntu 11.10/11.04 Server

Source: http://www.upubuntu.com/2011/09/how-to-install-webmin-on-ubuntu.html

Webmin is a web-based interface based on Perl for system administration under Unix-based systems. With Webmin, you can easily set up, via your web browser, new user accounts, manage disk quotas, configure files, control the Apache server as well as MySQL and PHP. In this guide, we will see how to install Webmin on a server running Ubuntu 11.04 or 11.10.

Webmin Installation

Before we start, you should first install the LAMP web server on your system. Now follow these instructions to install Webmin on Ubuntu 11.10/11.04:

1. Open the Terminal and run this command:

sudo gedit /etc/apt/sources.list

At the end of the file, add these two lines, then save and close:

deb http://download.webmin.com/download/repository sarge contrib
deb http://webmin.mirror.somersettechsolutions.co.uk/repository sarge contrib

2. Import now the GPG key using these commands:

wget http://www.webmin.com/jcameron-key.asc
sudo apt-key add jcameron-key.asc
sudo apt-get update

3. Install now Webmin with this command:

sudo apt-get install webmin

Accessing Webmin

To start Webmin, open this address using your web browser:

https://ubuntu:10000/

To login to webmin, you need to use your root account details. If you still haven’t assigned a password to your root account, then create a root password using this command via the terminal:

sudo passwd

Enter a new password, then resubmit it to confirm. Then use your root account access details to login to webmin.

 

To restart Webmin, use this command:

sudo /etc/init.d/webmin restart

That’s it!

 

How To Install The GTK3 Mac OS X Lion Theme On Ubuntu 11.10

Source: http://www.upubuntu.com/2011/11/how-to-install-gtk3-mac-os-x-lion-theme.html

In this tutorial we are going to help you install the GTK3 Mac OS X Lion theme for Ubuntu 11.10 Oneiric Ocelot. This will make Ubuntu 11.10 look like the new Mac OS X Lion OS. This theme is created by MBOSSG at deviantART.

A- Mac OS X Lion Theme Installation

1. Installing Cursors

Open the terminal and run these commands:

wget http://dl.dropbox.com/u/47950494/Mac-Lion-Cursors.tar.gz
sudo tar -xzvf Mac-Lion-Cursors.tar.gz -C /usr/share/icons

2. Downloading The Theme

[Note]: If you have already a “.themes” folder at your home directory, then skip the fisrt command.

Run these commands:

mkdir ~/.themes
wget http://dl.dropbox.com/u/47950494/Mac-Lion-Theme.tar.gz
tar -xzvf Mac-Lion-Theme.tar.gz -C ~/.themes

3. Installing Icons:

[Note]: If you have already an “.icons” folder at your home directory, then skip the fisrt command.

Run these commands:

mkdir ~/.icons
wget http://dl.dropbox.com/u/47950494/Mac-Lion-Icons.tar.gz
tar -xzvf Mac-Lion-Icons.tar.gz -C ~/.icons


B- Enabling The MAC OS X Lion Theme

Method 1

Install first GNOME Tweak Tool with this command:

sudo apt-get install gnome-tweak-tool


Launch GNOME Tweak Tool and in the Theme tab, enable these options then reboot:

Cursor theme > Mac-Lion-Cursors
Icon theme > Mac-Lion-Icons
GTK+ theme > Mac-Lion-Theme
Window theme > Mac-Lion-Theme

Method 2:

Or run simply these commands from the terminal:

gsettings set org.gnome.desktop.interface gtk-theme ‘Mac-Lion-Theme’

gsettings set org.gnome.desktop.interface icon-theme ‘Mac-Lion-Icons’

gconftool-2 –set –type string /apps/metacity/general/theme ‘Mac-Lion-Theme’



Screenshots:

 

 

Enjoy!


Add New Comment

Optional: Login below.

Image

Showing 5 of 15 comments

Make you own private cloud

Source: http://netsentries.com/create-your-own-private-cloud-with-eyeos/


Today I want to introduce you one of the most amazing light weight cloud based operating system known as eyeOS. eyeOS is a cloud based operating system which can be accessed from any where , think about your desktop from everywhere any device , your documents , files & applications on the web , that means your files on your private cloud.It is a complete open source offering , simply speaking it a light weight OS that can be accessed from anywhere through a web browser , currently there are two options to start with eyeOS.

It is a complete open source offering , simply speaking it a light weight OS that can be accessed from anywhere through a web browser , currently there are two options to start with eyeOS.

1. eyeOS 1.x stable


2. eyeOS 2.x beta


eyeOS 1.9 is equipped with

* More than 250 applications from eyeOS community

* 35 available languages &

* To be used in production environments


eyeOS 2.x includes live collaboration and many more social capabilities than eyeOS 1.x & is soon going to replace the 1.x

In this article we are going to install eyeOS 1.9 stable over ubuntu 10.10 32 bit OS , so sit back , relax & watch the art in detail.

Prerequisites


In order to install eyeOS we need to have the following first in your linux distro

.

  • Apache HTTP Server 2.x
  • MySQL-server and MySQL-client 5.x
  • & PHP5.2 or higher

Apache HTTP Server 2.x


Install Apache 2 in your ubuntu 10.10 as shown below.

Fig -1

MySQL-server and MySQL-client 5.x


Install mysql client in your linux distro as shown below.

Fig -2

Install mysql server as shown below.

Fig -3

You need to enter a password for the administrative user of mysql server , type in a password of your choice.

Fig -4

PHP  5.2, or higher


Install php as shown in your linux distro.

Fig – 5

eyeOS installation


Now it is time for us to get in to the real installation of eyeOS , download eyeOS 1.x stable version from their site.

http://www.eyeos.org/downloads/

Extract the eyeos1.x.zip to our website directory & assign chmod 777 to eyeos directory.

Fig – 6

From the console type

sudo chown -R www-data.www-data /var/www/eyeOS

&

sudo chmod 750 -R /var/www/eyeOS

Fig -7

Restart your pc , go to the web browser & type http://127.0.0.1/eyeOS/install as shown below.

Fig – 8

Now it is time for you to set a password for the root user , you will also get an option to allow your end users to add their accounts themselves .

Fig -9

Fig -10

Now we have done with it , we are in eyeos Desktop as shown below.

Fig -11

Customizing the defaults.

The default upload size with eyeos is only 2 MB , you can change it to a value of your choice by editing the php.ini file at

/etc/php5/apache2/php.ini

In php.ini change upload_max_filesize & post_max_size values

Eg:

upload_max_filesize = 200M

post_max_size = 200M

Upload size changed to 200 MB now  as shown below.

Introduction to creating desktop applications with PHP and Titanium

Source: http://www.sanisoft.com/blog/2011/01/03/introduction-to-creating-desktop-applications-with-php-and-titanium/

Welcome back! and a very Happy New Year. Yes, you saw it right. The post is about creating desktop applications with the help of PHP. And No, we are not using PHP-GTK. You can now create desktop applications without learning a completely new programming language! That is with the help of a free and open source tool called “Titanium”. Whats more you will use your existing CSS and Javascript and PHP knowledge. In this post I am going to briefly explain what Titanium is and show you how you can use the same to create a simple desktop application. So grab your text editors and get ready go!

What is Titanium ?

Titanium is a Free and open source (Uses Apache 2.0 License) framework for building native desktop and mobile applications using open web technologies (JavaScript, HTML and CSS). The framework also has support for PHP , Python and Ruby with access to both the Titanium framework itself and the DOM.

Now, Appcelerator Titanium (or simply Titanium) Platform consists of :

1) Titanium Desktop SDK

This will be our focus in this post. The best it could be described is by the appcelerator titanium documentation itself “The Titanium Desktop SDK provides a runtime environment for creating native desktop applications in HTML, CSS, and JavaScript. Titanium Desktop packages up your application source code (HTML/CSS/JavaScript) with a heavily augmented build of the popular Webkit open source web browser engine.”. Basically your application will be a set of webpages but with the power of native functionality. So you can ofcourse connect to remote servers like any web application and access the local media, the filesystem run processes and also use the languages like PHP, Ruby and Python and do lots more! As we will explore you can target the same code for a Windows, Linux or Mac OS Desktop without getting into the complexities of each of them.

2) Titanium Mobile SDK

The Titanium Mobile SDK empowers you to not just create but also run and even package real native mobile application for your favorite iOS, Android and even Blackberry (still in beta) using it cross platform JavaScript APIs and the final application will actually be a native application. We won’t be covering this in this post but, don’t worry I will be exploring mobile development with Titanium for iOS and Android in the future posts.

Titanium Developer

To create the applications using the above we need to install a tool called Titanium Developer (built using Titanium! itself) which is a desktop application that allows us to create, run and even package our desktop or mobile application. This tool basically does all the hardwork under the hood to manage your project with a nice and easy GUI.

Why would you use it. Whats so special about it ?

While it may sound like its another Adobe Air and frankly in some ways it is similar but its actually have many advantages over it :

  • Its open source software so it can be extended and modified.
  • You have already have the webkit browser engine for your desktop application so you can use the bleeding edge technologies like HTML5 and CSS3. Use what you know even JavaScript / css frameworks like JQuery are welcome.
  • With Titanium you can have access to a lot of unique native apis that your desktop applications. So its not just the look and feel of the desktop application it also performs like one.
  • If you are a web developer you can use your existing web development skills for creating desktop applications as well.
  • You don’t need to get into the complexities about each targeted OS. Titanium takes care of it for you.

What do you need to learn ?

Your existing knowledge of HTML / Javascript/ CSS and PHP (or Ruby / Python) will do. Apart from this for certain features you need to learn about the Titanium Javascript API so as to create menus / tool bars and so on.

What tools do you need ?

  • Download and install the Titanium Developer. The download and installation procedure has been discussed at length in the Titanium documentation in a simple and understandable way and even the steps on creating a new project and hence I am not putting the same here. I am assuming that you will download and comeback right here to know what next.
  • Text Editor with HTML / PHP syntax highlighting – If you are a web developer then you can’t be alive without one. Use your favorite.

On my Ubuntu 10.04 I got an error like : symbol lookup error: /usr/lib/lib-something: undefined symbol: something:

I did this to get rid of it :

– cd ~/.titanium/runtime/linux/1.0.0 if you install in your home dir.

or if you install in /opt/titanium/runtime/linux/1.0.0

– rm libgobject* libgthread* libglib* libgio*

Ready ?  What next ?

You now need to start “Titanium Developer” for e.g if you install it in your home dir

– /home/you/Titanium Developer-{version}/Titanium Developer

As you might have seen you get a screen like this :

Click on new project

The following screen will appear

Note: The AppId is the unique string that identifies your project and the Directory is the directory where the project files will be stored. Since we will be using PHP language module select the same.

Now enter the details as required and hit ‘Create Project’ L

You will see a screen like this :

Now Go to the “Test and Package” Tab you will see a screen with tabs to “Launch”, “Package” and “Link” hit the “Launch Application” button. The application screen will open up. Congrats! you just created your first desktop application.

If you installed titanium in the home dir you should see a directory structure like this :

In the above structure the :

– dist contains the binary files which you won’t need to change.

– Resources : This is where your source code lives and you should see a file named “index.html”.

– tiapp.xml : This is the config file for your project can controls the attributes like window size, title etc.

If you edit the the file index.html you see that this is a normal harmless html file. Make any changes to this and the window that opens on launching your application will reflect the same.

Enter PHP ..

Ok, lets move on and create a simple desktop application that does currency conversion, nothing complicated this is simply done using using a simple file_get_contents on web url (you need Internet access when using this app).

Now, there are some rules on writing PHP inside your application file and the documentation describes this at best. but basically this is done this way :

CODE:

  1. <script type=”text/php”>
  2.  // Your code goes here
  3. </script>

and include like :

CODE:

  1. <!– method one –>
  2.  
  3. <script src=”my_file.php” type=”text/php”>
  4.  
  5. <!–  method two –>
  6. <script type=”text/php”>
  7.     include(“my_other_file.php”);
  8. </script>

ok, our first page or interface does not need php so lets just put in a simple html form

Let put in the following code in the index.html

PHP:

  1. <head>
  2. <title>Your First Desktop Application</title>
  3. </head>
  4. <body>
  5.  
  6. <h1 align=’center’>Currency Converter</h1>
  7. <h4 align=’center’>A Desktop Application by SANIsoft</h4>
  8. <form action=”convert.php”>
  9.         <table align=”center”>
  10.                 <tr>
  11.                         <td>
  12.                                 Input From
  13.                         </td>
  14.                         <td>
  15.                                 <select name=”from”>
  16.                                     <option value=”eur”>Euro</option>
  17.                                     <option value=”usd”>US Dollar</option>
  18.                                     <option value=”gbp”>Pound Sterling</option>
  19.                                     <option value=”inr”>Indian Rupee</option>                                   
  20.                                 </select>                               
  21.                         </td>
  22.                 </tr>
  23.                 <tr>
  24.                         <td>
  25.                                 Input To
  26.                         </td>
  27.                         <td>
  28.                                 <select name=”to”>
  29.                                     <option value=”inr”>Indian Rupee</option>
  30.                                     <option value=”gbp”>Pound Sterling</option>
  31.                                     <option value=”usd”>US Dollar</option>
  32.                                     <option value=”eur”>Euro</option>
  33.                                 </select>
  34.                         </td>
  35.                 </tr>                       
  36.                 <tr>
  37.                         <td>
  38.                                 Amount
  39.                         </td>
  40.                         <td>
  41.                                 <input type=”text” name=”amount” value=””>
  42.                         </td>
  43.                 </tr>   
  44.                 <tr>
  45.                         <td colspan=”2″ align=”center”>
  46.                                 <input type=”submit” name=”submit” value=”Convert”>
  47.                         </td>
  48.                 </tr>                       
  49.         </table>
  50. </form>
  51.  
  52. </body>

Note : Its best practice to keep the styling / CSS outside your html and make it themable. but for the sake of this example we put in the same inside. You are free to have a css file style your app.

Now, in the next page that appears after this :
convert.php : We put in this simple HTML / PHP code:

We will be using the Exchange API. You need the Api key to use it in place of the code GET-YOUR-OWN-API-KEY
PHP:

  1. <head>
  2. </head>
  3. <body>
  4.  
  5. <h1 align=’center’>Currency Converter</h1>
  6. <h4 align=’center’>First Desktop Application by SANIsoft</h4>
  7. <table align=”center”>
  8. <tr>
  9. <?php
  10. if ($_GET[‘submit’]) {
  11.     $result = file_get_contents(“http://www.exchangerate-api.com/&#8221;.$_GET[‘from’].”/”.$_GET[‘to’].”/”.$_GET[‘amount’].”?k=GET-YOUR-OWN-API-KEY”);
  12. ?>
  13.     <td>
  14.         <h1>Result :</h1>
  15.     </td>
  16. </tr>
  17. <?php
  18. // Available currencies
  19. $currencies = array(“eur” => “Euro”, “gbp” => “Pound Sterling”, “usd” => “US Dollar”, “inr” => “Indian Rupee”);
  20. ?>
  21. <tr>
  22.     <td>
  23.         <h4><?php echo $_GET[‘amount’] .’ ‘.$currencies[$_GET[‘from’]] .’ = ‘. $result.’ ‘.$currencies[$_GET[‘to’]]; ?></h4>
  24.     </td>
  25. </tr>
  26. <tr>
  27.     <td>
  28.         <a href=”index.html”>Back</a>
  29.     </td>
  30. </tr>       
  31. <?php
  32. }
  33. ?>
  34. </table>
  35. <h5 align=”center”>&copy; All Rights Reserved – Jatin Chimote (jatin@sanisoft.com)</h5>
  36.  
  37. </body>

We made a few changes in the config file tiapp.xml and added a bit of style to make it slightly attractive and the final output after you go to the “Test and Package” -> “Launch App” is the following

And after you convert :

Wasn’t that easy! Now this is not where it ends you can :
– Package your application for various os and get a direct link where you can download the same using the “Package” tab in the “Test and Package” tab. The links you create will always be available for you in the “Links” tab.
Its important to note that your application will need the Titanium Runtime Environment (Similar to the way Adobe Air needs) to run and use can either bundle the same with your application or provide an option for the user to install the same while installing your application.

– You can use the Perspectives (Left hand top) corner and Switch to the “Community” perspective to view feeds and tweets and even use the “Sandbox” to test out your code without creating a project!

Well, this topic too large and we just had our first bite of it. But I hope you have understood the basics of how you can create a desktop app. So what are you thinking ? that cloud based application or a desktop frontend to your web application the possibilities are endless. So when are you starting. Until next time .. Chao .. :)

How to Send Text Messages with PHP

A Nice Article comparing various PHP frameworks

Stephen Musoke Senkomago

There is just too much going on so I thought I should put these thoughts down so that I do not lose my mind from the excitement and anticipation that comes from things moving very fast and innovation being spured at a pace which is mind boggling.

PHP

In my opinion the stabilization of PHP 5.3 which introduced namespaces (similar to Java Packages) was the first shot across the bow, and I expect 5.4 with traits to bring even more reusability. However our hosting providers are slow to upgrade most are still running PHP 5.2, without general availability for 5.3 just starting to appear

Frameworks

There are two main frameworks in the bull pen Symfony 2 (http://symfony.com/) and Zend Framework 2 (http://zendframework.com/) currently in beta. However they are as different as can be. While Symfony 2 has been refactored from a full blown framework to a…

View original post 674 more words

%d bloggers like this: