Tuesday, August 18, 2009

3 Steps To Turn-On Desktop Cube

In Ubuntu, by default, you cannot see the beauty of compiz desktop cube and desktop rotation. You must turn it on manually. Here are 3 steps to do it:
  1. Open Terminal and type: sudo apt-get install compizconfig-settings-managerThis is the GUI tool to easily manage the compiz configuration.
  2. Go to System->Preferences->CompizConfig Settings Manager. On the left panel, click General. On the right, click General Options. Go to Desktop Size tab and set Horizontal Virtual Size to 4 then click Back button on left panel.
  3. Now click Desktop on left panel. On the right, tick off Desktop Cube and Rotate Cube to enable them. Later, if you want to change the appearance of your cube, just enter the Desktop Cube menu. While if you want to change the rotation setting, enter the Rotate Cube menu.
Now you can try it. Push Ctrl+Alt buttons together then left-click any area on the screen and move your mouse. Wow...look at that. Cool hah?

But wait...if your desktop form is not a cube (cylinder or sphere) or if you want to change the form (or effects), follow these steps:
  1. On the left panel, click Effects. On the right, tick off and click Cube Reflection and Deformation.
  2. In Cube caps tab, you can change the appearance of top and bottom side of the cube.
  3. In Reflection tab, you can manage the background reflection while the cube is rotating
  4. And in Deformation tab, you can change the form of the cube to sphere or cylinder.
Don't forget to leave a comment so I know that this post is useful to you.
Read more...

Monday, August 17, 2009

5 Minutes To Master JSON (JavaScript Object Notation)

To follow this tutorial, you don’t have to be experienced with Javascript. But it’ll be preferred if you have at least a little bit knowledge about Object Oriented Programming. Put all the scripts below inside the body element enclosed by script tag.

Minute 1 - Intro to Object

var myFirstObject = {};

It may not look like much, but those squiggly braces have the potential to record every bit of information humanity has ever gathered, and express the most complex programs computer scientists can dream up. In fact, Javascript itself is stored inside a set of squiggly braces just like that, as are all of its primitive data types -- strings, numbers, arrays, dates, regular expressions, they're all objects and they all started out just like myFirstObject.

Minute 2 - Creating A New Object


The old way to create a new object was to use the new keyword.
var myJSON = new Object();
The above method has been deprecated now in favor of simply defining an empty object with squiggly braces.
var myJSON = {};

Objects as Data
var myJSON = { "firstName": "Barrack", "lastName": "Obama", "age": 44 };

This myJSON object has 3 properties or name/value pairs. The name is a string -- in our example, firstName, lastName, and age. The value can be any Javascript object (and remember everything in Javascript is an object so the value can be a string, number, array, function, even other Objects) -- In this example our values are “Barrack”, “Obama”, and 44. “Barrack” and “Obama” are strings but age is a number and as you can see this is not a problem.

This data format is called JSON for JavaScript Object Notation. What makes it particularly powerful is that since the value can be any data type, you can store other arrays and other objects, nesting them as deeply as you need.

Minute 3 - Accessing Data In JSON


The most common way to access JSON data is through dot notation. This is simply the object name followed by a period and then followed by the name/property you would like to access.

document.writeln(myJSON.firstName); // Outputs Barrack
document.writeln(myJSON.lastName); // Outputs Obama
document.writeln(myJSON.age); // Outputs 44

If your object contains an object then just add another period and name
var myAnimals = { “cat”: { “name”: “mojo”, “color”: “white” }, “dog”: { “name”: “twister”, “color”: “gray” } };

document.writeln(myAnimals.cat.name); // outputs mojo
document.writeln(myAnimals.dog.name); // outputs twister

Minute 4

Array as A Value


If your object contains an object with a type of Array, just specify the index of data after object name. This example will show you how to use a value with type of array
var myAnimals = { “cat”: { “name”: “mojo”, “color”: “white” }, “dogs”: [{ “name”: “twister”, “color”: “gray” }, { “name”: “sweety”, “color”: “brown” }] };

document.writeln(myAnimals.cat.name); // outputs mojo
document.writeln(myAnimals.dogs[0].name); // outputs twister
document.writeln(myAnimals.dogs[1].name); // outputs sweety

Function as A Value


The other power of Javascript is that you can assign a function to a variable directly. This example will create a message box that is called by show function
var myIdentity = { “name”: “joe”, “age”: 23, show: function(){alert(this.name + ‘ ’ + this.age)} };
myIdentity.show();

Minute 5 - Receiving JSON via AJAX


In this minute, if you’ve known a little about AJAX, you’ll figure out that using JSON as data format is much easier than XML.

Remember that JSON data is simply string received from the server. Suppose that responseText contains string from server that is called by XMLHttpRequest.
var responseText = "fruits = { ‘name’: ‘apple’, 'color' : 'red' }"; // example of what is received from the server.
eval(responseText); // Execute the javascript code contained in responseText.

document.writeln(apple.color); // Outputs ‘green’


eval() function is just a built-in Javascript string compiler which can run very fast.

I think that’s all the essence of JSON. I suggest you to go to json.org to learn some more advance concept.

Don’t forget to leave a comment so I know that this post is useful to you.
Read more...

Sunday, August 16, 2009

MySQL Backup and Restore Using PHP

It is very important to make regular backup of your important data to keep them from data loss. There are several ways to backup and restore your MySQL database. The easiest way is by copying the database directory in:
/var/lib/mysql
or
C:\xampp\mysql\data (or MySQL installation folder if you are not using Xampp)
But you cannot do this if your database table is using InnoDB engine. Your InnoDB table will not be recognized when it is restored in another MySQL server. So I don’t recommend this way to backup your MySQL database. This tutorial will show you how to backup and restore your database safely.

Backup Databases


There are at least three ways to backup your MySQL Database:
  1. Use phpMyAdmin to do the backup.
  2. Run mysqldump from command line or using php system() function.
  3. Execute a database backup query from PHP file.
If you want to backup your database from your application (PHP), you can do ways 2 or 3. I prefer to backup with mysqldump and I use this in all of my project.
The format of mysqldump command is like this:
$ mysqldump --opt -u [uname] -p[pass] [dbname] > [backupfile.sql]
or
C:\xampp\mysql\bin\mysqldump.exe --opt -u [uname] -p[pass] [dbname] > [backupfile.sql]
  • [uname] Your database username
  • [pass] The password for your database (Note: there is no space between -p and the password)
  • [dbname] The name of your database
  • [backupfile.sql] The filename for your database backup
  • [--opt] The mysqldump option
For example, to backup a database named 'Tutorial' with the username ‘root’ and password ‘toor’ to a file tutor_backup.sql, you should accomplish this command:
$ mysqldump -u root -ptoor Tutorial > tutor_backup.sql
This command will backup the 'Tutorial' database into a file called tutor_backup.sql which will contain all the SQL statements needed to re-create the database.

Backup Certain Tables

With mysqldump command you can specify certain tables of your database you want to backup. For example, to back up only php_tutorials and asp_tutorials tables from the 'Tutorial' database accomplish the command below. Each table name has to be separated by space.
$ mysqldump -u root -ptoor Tutorial php_tutorials asp_tutorials > tutor_backup.sql

Backup Certain Databases

Sometimes it is necessary to back up more than one database at once. In this case you can use the --database option followed by the list of databases you would like to backup. Each database name has to be separated by space.
$ mysqldump -u root -ptoor --databases Tutorial Articles Comments > t_a_c_backup.sql

Backup All Database

If you want to back up all the databases in the server at one time you should use the --all-databases option. It tells MySQL to dump all the databases it has in storage.
$ mysqldump -u root -ptoor --all-databases > alldb_backup.sql

The mysqldump command has also some other useful options:
--add-drop-table: Tells MySQL to add a DROP TABLE statement before each CREATE TABLE in the dump.
--no-data: Dumps only the database structure, not the contents.
--add-locks: Adds the LOCK TABLES and UNLOCK TABLES statements you can see in the dump file.


Restore Databases


Above we backup the Tutorial database into tut_backup.sql file. To re-create the Tutorial database you should follow two steps:
Create an appropriately named database on the target machine
Load the file using the MySQL command:
$ mysql -u [uname] -p[pass] [db_to_restore] < [backupfile.sql]
or
C:\xampp\mysql\bin\mysql.exe -u [uname] -p[pass] [db_to_restore] < [backupfile.sql]

Have a look how you can restore your tutor_backup.sql file to the Tutorial database.
$ mysql -u root -ptoor Tutorial < tutor_backup.sql

If you need to restore a database that already exists, you'll need to use mysqlimport command. The syntax for mysqlimport is as follows:
$ mysqlimport -u [uname] -p[pass] [dbname] [backupfile.sql]

Here are my scripts to backup and restore MySQL database through PHP.With this backup script, the output file can be downloaded. Just load the script from browser and save the output file. The output file is compressed in ZIP format.
The restore script gets the file through upload form. Just browse the output file that has been downloaded with backup script and click Upload button.

Please post below if you get a problem applying this tutorial.
Read more...

Saturday, August 15, 2009

Compiz Error After Setting Desktop Effect To None

May be this is one of many reasons why people still thinking that Linux is wearying OS. For example, when you are playing with the system settings or your desktop preferences, your system suddenly stop working and you don’t know what the hell is going on. Then you are shocked and thinking hard what you have to do to make your system works again.

But it doesn’t matter if you have a big curiosity in Linux. Just open firefox or the other browsers and start to search the solutions of your problems like what I will explain in this post.

It was an accident when I click None option in desktop effect setting. I thought it’s not a problem coz I could reset the setting back to Extra option. So I reset the option. But I was wrong, suddenly I got the message telling me that compiz-daemon couldn’t be started. Oh sh*t…what’s the going on?

After searching for the solutions by using many keywords, I got a nice script to detect compiz problems. The script name was compiz-check. This script doesn’t only detect compiz problems but it can also repair the problems. So if you get this problem just download compiz-check and run in your terminal.

Before you run compiz-check, change the permission to make it executable:
$ chmod 744 compiz-check
$ ./compiz-check



Don't forget to leave a comment so I know that this post is useful to you.
Read more...

Friday, August 14, 2009

Transform Ubuntu Jaunty to Mac OSX Leopard

I was in my college laboratory yesterday and I got a nice tutorial from this site about transforming Ubuntu to Mac OSX Leopard. Because I was started to get bored with Ubuntu Studio theme that I installed a few weeks ago, I decided to transform my Ubuntu to the new taste of theme.

As a matter of fact, I'm not PRO enough with the super advanced OS called Linux and it get worse coz I didn't mention that the tutorial I got is for transforming Ubuntu Hardy which is older than my current Ubuntu version (Jaunty). My notebook stuck into trouble while it was in the middle of transforming process. The screen was blinking after login to Gnome and I didn't know which package had caused this suck problem.

I'm not a type of a loser, so I backup all of my data, reinstalled my Ubuntu and the Mac theme. There as a package that looks suspicious and I didn't reinstalled it. Now I got Mac OSX Leopard running on my notebook.

Because I'm a good person (lol), I made this this tutorial so you don't fall into the same hole as me. Before we start the transformation you must download all of these files:


Once you finish download the files, follow the steps below:

1. Goal: Install the base of Mac OSX Leopard theme


1. I assume you downloaded the files to your home directory (/home/username). Extract Mac4Lin_modified_theme.tar.gz in that directory.
Go to System->Preferences->Appearance then you get this window:
2. Click Install and select the Mac4Lin GTK theme (/home/username/Mac4Lin_v0.4/GTK Metacity Theme/Mac4Lin_GTK_v0.4.tar.gz).
Click Install again and select the Mac4Lin mouse cursor theme (/home/username/Mac4Lin_v0.4/GTK Cursor Theme/Mac4Lin_Cursors_v0.4.tar.gz). Select “Apply new themes” when prompted.
Next, click Install again and select the Mac4Lin icon theme (/home/username/Mac4Lin_Icons_modified.tar.gz). When prompted, select “Apply new themes“.
Don't worry if your window doesn't look like Mac yet.
Click Customize and choose Mac4Lin_GTK_v0.4. Go to the Window border tab, choose Mac4Lin_GTK_v0.4. Click Close

3. Ups...may be you're now wondering why the buttons looks so large and ugly. This is because the new Ubuntu version doesn't automatically hide the button icon so you must manually set the setting.
Press Alt+F2 buttons till you get this window:
Type gconf-editor and click Run the you meet Gnome Configuration Editor window.
On the left panel, go to desktop->gnome->interface. Then on the right panel clear the sign at buttons_have_icons variable. This change will effect immediately. Your all buttons icon must have gone now.

4. Haha, don't be happy yet! Now we will change the window traffic light buttons to the left side. Still in Gnome Configuration Editor window (if you already close this window, back to step 7 to open it again), on the left panel go to the /->apps->metacity->general. Then on the right panel double click button_layout till you get this window:
Change the Value from menu:minimize, maximize, close to close, minimize, maximize:menu.

5. Now, look at your top menu bar panel, we will transform this thing. Remove all the icon and applications on the left side of the top panel. Right-click on the icon and select ‘Remove from panel‘. You will left with something like this:
On the right of the top panel, remove the logout icon. Still on the right hand side of the top panel, right click and select ‘Add to panel‘. Scroll down the list and add ‘Search for files‘. This will add the spotlight icon to the panel.
6. On the extreme left, right-click and select ‘Add to panel‘. Scroll down the list and add ‘Menu Bar‘. This will add the apple icon on the left.
Actually the next step is to install global menu as to display the menu bar for each application just like the real OSX, but this package is not compatible with Ubuntu Jaunty and I think this package that caused my previous Ubuntu stop working. So we won't install this package.

2. Goal: Install the Dock


At first, we will edit APT repository to point to http://ppa.launchpad.net/. Here are the steps:

1. Open Terminal (Applications->Accessories->Terminal)
Type this command: gksu gedit /etc/apt/sources.list
Add the following lines to the end of files
deb http://ppa.launchpad.net/awn-testing/ubuntu jaunty main
deb-src http://ppa.launchpad.net/awn-testing/ubuntu jaunty main


2. Next we will update our new repository and install the dock package. Save and close the file then in your terminal, type:
sudo apt-get update
sudo apt-get install avant-window-navigator-trunk awn-manager-trunk awn-extras-applets-trunk


3. Once the installation is finished you can launch the AWN but before you do that, remove the bottom panel from the desktop first. Right click on the bottom panel and select “delete this panel”. Open AWN via Applications->Accessories->Avant Window Navigator. Once it is activated, you can simply drag and drop the applications into the dock.
The dock is running now but we will do some tweak to mimic the real OSX Leopard dock. Go to System->Preferences->AWN manager so you got this window:
4. First, add the glass theme which you have downloaded. On the left panel, click on the Theme, On the right panel, click Add and navigate to the /home/username/Mac4Lin_v0.4 directory. Select the Elegant_glass.tgz file. Select the Elegant glass theme and click Apply. Next on the left, click on the Applet icon. On the right, scroll down to the Stacks Applet. Highlight it, then click Activate. This will add the Mac Leopard stack to your dock.

3. Goal: Install OSX Fonts.


Huff, let me guess. You're getting tired or bored with this tutorial. But it's not enough bro! Try to guess what will we do next. Hmm, I'm sure you can't guess it. Ok, do you realize that your fonts taste is still “Very Linux”? Aha...you got it now. Yes, we will change the font. So you must download the package first.

1. Open a terminal and type the following:
sudo apt-get install msttcorefonts
This will Install the Microsoft core fonts.

2. Next, copy the OSX fonts to the system fonts directory
cd /usr/share/fonts
sudo tar xvzf /home/username/Mac4Lin_v0.4/Fonts/OSX_Fonts.tar.gz

3. Configure the fonts
cd/
sudo tar xvjpf /home/username/Mac4Lin_v0.4/Fonts/fontconfig.tbz -C /etc/fonts

4. Open the Appearance window (System->Preferences->Appearance) and select Fonts tab. Select the following fonts according to the image below:

4. Goal: Transform the login screen


Easy bro...easy...it's almost done coz there are only 'sweet'-seventeen steps more to complete this transformation (haha).

1. Click on the Apple icon, go to System->Administration->Login Window. On the Local tab, click Add. Navigate to the path /filesystem/home/username/Mac4Lin_v0.4/GDM Theme and select the file Mac4Lin_GDM_v0.4.tar.gz. Check the box beside the newly installed theme to activate it.
2. Underneath, there is a color selection field, select it and key in the number E5E5E5 into the color code field. Click Ok. Log out. You should see the login screen as the picture below:

5. Goal: Configure Usplash Screen


1. Usplash is the screen that you see when your computer is booting up. We are going to change it to show the white apple screen. Type in your terminal: sudo apt-get install startupmanager
Go to System->Administration->Start-Up Manager Go to Appearance tab.
Click on the ‘Manage bootloader theme‘. Click Add and navigate to the file /filesystem/home/username/Mac4Lin_v0.4/GRUB Splash/appleblack.xpm.gz. Check the box “Use background image for bootloader menu” and select ‘appleblack”.
Next, click “Manage usplash theme”. Click Add and add the file /filesystem/home/username/Mac4Lin_v0.4/USplash Theme/osx-splash.so. Click OK. Select osx-splash from the dropdown box.
Now reboot. You should see the following images:

2. Cool hah??

6. Goal: Creating Dashboard effect.


Do you like desktop effects? If you do, then you must be happy to hear this. We will use a combination of Screenlets and Compiz widget plugin to achieve the dashboard effect.

1. Install Screenlets sudo apt-get install screenlets compizconfig-settings-manager
Go to System->Preferences->CompizConfig Settings Manager.

On the Left, click on Desktop. On the right, put a check beside ‘Widget layer’

2. Go to Accessories->Screenlets. Activate the widgets that you want to display. Right click on the widget and select ‘Properties’. Go to Options tab and select ‘Treat as widget’. Do this for all the widgets that you have activated.

3. You can now see your dashboard in action by pressing F9.

7. Done.

You have completed the transformation of your Ubuntu desktop to Mac OSX Leopard. Wait...wait...wait, don't forget to change you wallpaper. Using Archive manager, extract the Mac4Lin_Wallpapers_Part3_v0.4.tar.gz. Go to System->Preferences->Appearance. On the top, go to the Background tab. Click Add and select the Leopard wallpaper. (/home/username/Wallpapers/Leopard.jpg). Click Close to terminate the Appearance window.
Don't forget to leave a comment so I know that this post is useful to you.
Read more...