Sunday, November 22, 2009

C and C++ Hello World on Ubuntu

This is a nice tutorial on how to run your first c and c++ codes on Ubuntu:
http://www.ubuntugeek.com/how-to-install-c-and-c-compilers-in-ubuntu-and-testing-your-first-c-and-c-program.html

Perl Hello World on Ubuntu

#!/usr/bin/perl
print "Hello World\n";


Those are 2 lines for the Hello World application.
My question is: How can I know the first line should be #!/usr/bin/perl ?

Well, open the terminal, then run which perl
It will show you the location of the Perl interpreter.

To run the code, just type perl hello.pl in terminal.

Now, I want to make the file 'executable'. Go to the directory where I saved the file, then run:
chmod +x hello.pl
./hello.pl


+x is used to put executable attribute to the file.
What about ./hello.pl? Why do we need ./ ? Why don't just type hello.pl?

For the complete explanation, see this website http://www.linfo.org/dot_slash.html
When we execute the file, we need to put the absolute path. The easiest way to put the absolute path is by using ./
./ refers to the current directory.

Wednesday, November 4, 2009

Unmount cdrom in Ubuntu

I wanted to remove a CD from my computer. I pressed the eject button, it didn't work. I right-clicked the CD icon and select 'Unmount' or 'Eject', it didn't work.

So, I tried to open the terminal and run this command 'umount -l /media/cdrom'..and it worked!

What is -l option? According to man page:
Lazy unmount. Detach the filesystem from the filesystem hierarchy
now, and cleanup all references to the filesystem as soon as
it is not busy anymore. (Requires kernel 2.4.11 or later.)

Remove red dot and vertical blue line in jEdit

In jEdit, there's a red dot at the end of each line, and there's a vertical blue line. How to remove them?

Go to Utilities > Global Options > Text Area
Uncheck both 'End of line markers' and 'Wrap guide'.
Done.

Sunday, November 1, 2009

Mount SMB shares

I have 2 ubuntu machines. One of the machine acts as the file server. I want to mount the shared folder to the other machine.

Firstly, install Samba File System and Samba client:
sudo apt-get install smbfs smbclient

Secondly,use smbmount command to mount the share.
Ex: The shared folder is located in 192.168.1.2 machine, and the folder name is java.
I wanted to mount it to /home/adi/java
smbmount //192.168.1.2/java /home/adi/java -o username=adi,pass=mysecretpassword

Done.

Source: http://ubuntuforums.org/showthread.php?t=280473

Get MDB2's mysql package

I installed Pear a few years ago but I only used it a few times.
This morning I decided to try the MDB2 package.

I tried the sample code from the Pear website. When I ran the code, I got this error unable to find package 'MDB2_Driver_mysql' file 'MDB2\Driver\mysql.php'

So, I had to update the package. 2 things that I had to do:
1. 'pear upgrade MDB2' to upgrade MDB2 package to the latest version
2. 'pear install MDB2_Driver_mysql' to get the mysql package

Tuesday, October 20, 2009

MySQL timestamp

When you insert a new row into a table, sometimes we need to record the time of insertion. For example, you have a table called User, which contains columns such as userName and userCreationDate.

To insert the creation date, I often used statement like this:
INSERT INTO USERS (userName,userCreationDate) VALUES ('yourusername',now())

Well, there's an easier way. You can just change the type of userCreationDate column from Date to Timestamp. MySQL will automatically update the column everytime you insert a new row. By the way, I used MySQL Administrator to modify the column type.

Now I've got a new problem. When the row is updated (ex: changing the userName), the userCreationDate is also updated to the current time. I don't want the creation date to be changed, but I can't find the reason by looking the table information in MySQL Administrator. So, let's use open the MySQL using the command prompt.

Type this command 'SHOW CREATE TABLE USERS'. You'll see something like this:
`userCreationDate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP

The problem is in the 'on update CURRENT_TIMESTAMP' statement. It means the column is automatically updated when the row is modified. To turn off this functionality, just alter the table:
ALTER TABLE USERS MODIFY COLUMN userCreationDate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

That's all.

Monday, October 19, 2009

Regular expression to check email address (PHP)

Here's the regex to check email address according to totallyphp.co.uk
^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$

The valid characters for the username part are: underscore,hyphen,letter from a to z, number from 0 to 9.
The valid characters for the domain part are: same as username, but it doesn't include the underscore. In addition, the last part of the domain can only contain 2 or 3 letters (ex: com,au).

What's wrong with this regular expression?
The obvious one is the last part. I own a domain name that end with 'info'. 'info' has 4 characters, so it won't match the last rule, which can only accept 2 or 3 character.

Now, let's take a look at the first part: ^[_a-z0-9-]+
Based on this part, the email address can start with an underscore, letter, number, or hyphen. However, email address can only start with a letter or number. These email address are not valid: _jim@example.com, -jim@example.com

Let's improve the regular expression.
To fix the first mistake, just change the last part from {2,3} to {2,4}.

For the second one, we have to make sure that email address must not start with an underscore or hyphen.
We have to change ^[_a-z0-9-]+ to ^[a-z0-9]+
Then, we have to include the underscore and hyphen in the next part: [_a-z0-9-]*

The complete one is: ^[a-z0-9]+[_a-z0-9-]*(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$

Update:
When I did the practice, I misplaced the hyphen position, and the regex didn't work properly. Instead of [_a-z0-9-], I wrote [_-a-z0-9]
Hyphen has a special meaning in regular expression. So it's better to 'escape' the hyphen. This one will work [_\-a-z0-9]


Sources:
http://www.totallyphp.co.uk/code/validate_an_email_address_using_regular_expressions.htm
http://www.melbourneit.com.au/help/index.php?questionid=1118
http://www.alertsite.com/help/RegexMatching.html

Wednesday, October 14, 2009

A quick way to create rounded corners

When you need to create a box with rounded corner, you normally need to create the rounded images using software such as photoshop. I've just found a website that can create the images quickly. Here's the link: RoundedCornr

Monday, September 21, 2009

Amazon Product Advertising API signature

A couple months ago I got this email from amazon:
Dear Developer,

We want to remind you that all calls to the Product Advertising API must be authenticated using request signatures by August 15, 2009. Please remember that calls to the Product Advertising API that are not signed will not be processed after August 15, 2009. For help on request signatures, please see the Resources section below.

The Product Advertising API Team.


Well, I tried to find an example about this signature on amazon's website, but none of the examples is using PHP. Fortunately, there's a guy who wrote the example using php.
Here is the link:
http://www.codediesel.com/php/accessing-amazon-product-advertising-api-in-php/

Tuesday, September 15, 2009

Printing multiple pages in 1 sheet of paper (OpenOffice Writer 3)

I want to print 2 pages in 1 sheet of paper.

Firstly, go to Page Preview. Then click 'Print options page view' button and change the format to Landscape.

Next, click 'Page Preview: Multiple Pages' button, choose '2 x 1 pages'.

Finally, click 'Print page view' button.

Done.

Sharing printer connected to Windows 7

My printer is connected to the Windows 7 PC. I would like to add the printer to my XP PC. However, my XP PC couldn't see the Windows 7 PC. Well, Windows 7 has a concept called Homegroup. It seems that Homegroup is only used for Windows 7. So, what I have to do is to leave the Homegroup, then join the Workgroup.

If you go to Network section in control panel, there's an option to leave the Homegroup.

To change the Workgroup, click the start button, right click on Computer and choose Properties. Change the workgroup, then restart the computer.

Next, what I have to do is to activate the printer sharing (right click on printer name).

That's all the steps needed in Windows 7. Now my XP PC can see the printer attached to Windows 7.

Done.

Friday, September 11, 2009

Can't access Netcomm NB9W's settings page

After I changed some settings in NB9W, I couldn't access the settings page in web browser anymore. However, I still could ping it successfully.

Somebody suggested to run 'netsh winsock reset' in the command prompt, then reset the computer. I did it and I still couldn't access the router.

The next thing that I did was to reset the router. Well..that's all..I can access the router now.

Friday, September 4, 2009

Viewing NEF file in Linux Mint

NEF file is Nikon's raw image format. When I tried to open it in Eye of GNOME, I could only see the image in 160x120 pixels.

I remember that I never have this problem with Ubuntu. So, I downloaded the Ubuntu's image viewer called gThumb.

Well, gThumb can open the file perfectly. But I've got one more problem. Everytime I opened the image, it was displayed in the full size. Most of my photos are 3900 pixels wide, so I don't want to open it in its original size.

To change this behaviour, go to Edit > Preferences, go to Viewer tab. In the 'After loading an image' options, choose 'Fit to window if larger'.

Done.

Thursday, September 3, 2009

Modifying google in Opera's search bar

I want to change the default Opera's search from google.com to google.com.au.
To change it, go to Tools > Preferences, go to Search tab, select google, and click edit.
Click the Details button, then enter http://www.google.com.au/search?q=%s in the address text box.

Done.

Monday, August 31, 2009

Second argument in javascript's link method (CakePHP)

To create a link to javascript files, we can use 'link' method.
For example, if I type echo $javascript->link('tiny_mce/tiny_mce.js',false);

The second argument is 'false'. It means the script link will be displayed in the html's head section.
If it is 'true', the link will be displayed in html's body section.

Well, there's actually more story to how CakePHP choose where to put the link.
Actually, if second argument is 'false', the link will be displayed in $scripts_for_layout section, and if it's 'true', it will be displayed in $content_for_layout.

Both $scripts_for_layout and $content_for_layout is written inside the layout file.
If you create your own layout, you should find the file inside app/views/layouts folder.
If you use the default layout, the file is cake/libs/view/layouts/default.ctp

You will see that the $scripts_for_layout is written inside the head section, and $content_for_layout is written inside the body section.

Remove sql statement at the bottom of the page (CakePHP)

By default, CakePHP display a list of sql statements at the bottom of the page.
This is the result of CakePHP debug level.

To remove the sql statements, we need to change the debug level to 0.

Open the app/config/core.php, search for this line
Configure::write('debug', 2);

Then change it to 0
Configure::write('debug', 0);

Done.

Wednesday, August 19, 2009

Activate Backspace to go to previous page in Firefox

I often use Backspace to go to the previous page. However, it didn't work in my newly installed Ubuntu machine (Ubuntu 9.04, Firefox 3.0.8).

To fix this, type 'about:config' in the address bar, then type 'browser.backspace_action' in the filter box. The value was 2, so I need to change it to 0. Done!

Monday, August 17, 2009

Watching TPG IPTV on Firefox (Ubuntu 9.04)

By default, we can't watch TPG IPTV on firefox. We'll get error saying that your VLC player is too old.

To fix this problem, we have to install vlc,vlc-plugin-esd, mozilla-plugin-vlc. Use Synaptic to install those packages.

Source: http://www.videolan.org/vlc/download-ubuntu.html

Playing DVD on Ubuntu 9.04

By default, DVD can't be played on Ubuntu.
We have to add some libraries.

The installation details can be found here:
http://ubuntuforums.org/showthread.php?t=766683

These are the steps that I did based on information from that forum.
Run below command to add medibuntu to the repository.
sudo wget http://www.medibuntu.org/sources.list.d/`lsb_release -cs`.list --output-document=/etc/apt/sources.list.d/medibuntu.list; sudo apt-get -q update; sudo apt-get --yes -q --allow-unauthenticated install medibuntu-keyring; sudo apt-get -q update

Then run:
sudo apt-get install libdvdcss2 libdvdread4 libdvdnav4 vlc

Until this point, I still can't play DVD.
Well, it seems I have to run this command:
sudo apt-get remove gnash gnash-common libflashsupport mozilla-plugin-gnash swfdec-mozilla && sudo apt-get install alsa-oss faac faad flashplugin-nonfree gstreamer0.10-ffmpeg gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse gstreamer0.10-plugins-ugly gstreamer0.10-plugins-ugly-multiverse gstreamer0.10-pitfdll libmp3lame0 non-free-codecs sun-java6-fonts sun-java6-jre sun-java6-plugin unrar

Perfect..I can play DVD now.

Install Flash Player

By default, Flash Player is not installed on Ubuntu 9.04. An easy way to install it is to use Firefox to open a website with flash content, then click the 'Install Missing Plugins' button, choose the Adobe's one, and just follow the instructions.

Thursday, July 9, 2009

Menampilkan EasyBook di Front-End Joomla

1. Klik Menus, dan pilih salah satu menu (misalkan: main menu).




2. Klik tombol New di kanan atas.




3. Klik EasyBook, kemudian klik Guestbook Entryform




4. Isi Title (misalkan: 'Buku Tamu').


5. Di sebelah kanan, klik Parameters (Component). Kemudian, cari bagian 'Group for adding an entry' (agak bawah), dan ganti isinya ke 'Everybody'.



6. Klik tombol Save. Setelah ini, EasyBook bisa terlihat di Front-End.

Instalasi EasyBook di Joomla

1. Download file EasyBook dari http://joomlacode.org/gf/project/easyjoomla/frs/?action=FrsReleaseBrowse&frs_package_id=225. Pilih file yang terbaru, dan berawal dengan kata 'com', contoh: com_easybook_2.0_rc4_valid.zip

2. Di bagian Administrasi Joomla, pilih menu Extensions > Install/Uninstall.

3. Klik tombol Browse, pilih file EasyBook, kemudian klik Upload File & Install.


4. Jika instalasi berhasil, akan ada tulisan 'Install Component Success', dan EasyBook akan keluar dibawah menu Components.



Friday, June 26, 2009

An Jing Le - Chords


C Am
Zhi shen xia gan qing pei wo zhan zai zhe li
F
Meng xiang zhong shu yu wo men de hun li
Fm G
Que cheng le dan ren jie hun jing xing qu
C Bb A7
Zai zhe chang ai qing jiao li de ba he li
Dm
Ai wo hai shi ai ni
F Em
Ni xuan ze le zi ji


Am
Sha jiao de ke ai de
G
Mi ren de ai ku de
F Em
Zao pian li cheng jing dou shi ni xi huan de
Dm
Ru jin wo hai zai yuan di
F G
Ni que zou hui ni de ji yi


C
Ni shuo wo ai ni tai duo
C/B
Jiu kuai yao ba ai yan mo
Am
Ni hai pa xing fu
Em
Duan zhan yi miao jiu beng luo
F G
Fen kai shi yi zhong jie tuo
Em Am
Rang ni hao hao de xiang wo
Dm
Wo xiang yao de na pian tian kong
F G
Ni shi bu shi neng gou gei wo


C
Ni shuo wo gei ni tai duo
C/B
Que bu neng gei wo shen me
Am Em
Fen bu qing ji qing cheng nuo yong heng huo mi huo
F G
Ai qing shi yi dao shang kou
Em Am
Wo men ge zi ku tong
Dm
Shen me shi wo zui hou wen rou
G C
Shi yin wei wo tai ai ni

Wednesday, May 13, 2009

New Mic + Rain and Tears video

I've just purchased the Logitech USB Desktop Microphone. I decided to purchase it after viewing some reviews from youtube. The sound quality of my old guitar videos was really poor. So, I hope the audio can be improved by using a microphone.

At first, I was really disappointed with the mic. The audio quality was only improved a little. I can still hear the background noise in my video. However, when I use the windows sound recorder, the audio was really good. So, there must be something wrong with my quickcam software.

I didn't realise that Windows Movie Maker can also capture video from webcam. So, I tried to record a new video using the Movie Maker. I'm very happy with the result. It is much better than my previous videos.

This is my first video which was recorded using the new mic. Enjoy!

Sunday, May 3, 2009

Guitar - Spirited Away


This is the guitar version of Spirited Away's ending theme.

I started to play guitar when I was in High School. However, I never learn it seriously. In recent years, I've seen so many good guitarists in Youtube. I've got so much inspirations from them. Recently, I play guitar more often than before.

The first video that I uploaded to Youtube is Sprited Away's ending theme. If you've seen the movie, you will agree that the ending theme is very beautiful piece of music.

I recorded my playing with my old webcam. The sound quality is not good. I hope I can get a better camera soon. I hope you will enjoy my playing.