ASCII Art in Terminal

I wanted some sort of ASCII art to be displayed everytime I open my good ol' urxvt. What I did is open up the file ~/.bashrc and added at the end of the file this snippet:


echo ""
echo " ##### "
echo " ####### "
echo " @ ##O#O## "
echo " ###### @@# #VVVVV# "
echo " ## # ## VVV ## "
echo " ## @@@ ### #### ### ### ##### ###### # ## "
echo " ## @ @# ### ## ## ## ### ## # ## "
echo " ## @ @# ## ## ## ## ### # ### "
echo " ## @@# ## ## ## ## ### QQ# ##Q "
echo " ## # @@# ## ## ## ## ## ## QQQQQQ# #QQQQQQ "
echo " ## ## @@# # ## ## ### ### ## ## QQQQQQQ# #QQQQQQQ "
echo " ############ ### #### #### #### ### ##### ###### QQQQQ#######QQQQQ "
echo ""

Screenshot:



Found the ASCII art here.

Update: I installed cowsay and replace the snippet above with this cowsay -f tux `fortune`.

Using the Twitter API

Here's a quick HowTo on using the Twitter API. If you aren't familiar with Twitter, here's a brief description taken directly from their homepage:

Twitter is a service for friends, family, and co–workers to communicate and stay connected through the exchange of quick, frequent answers to one simple question: What are you doing?

You might want to register in their service first since
Many Twitter API methods require authentication.

If you have cURL installed, you can already play with the Twitter API. Examples:
curl http://twitter.com/statuses/public_timeline.xml

or
curl -u username:password http://twitter.com/statuses/friends_timeline.xml

And since PHP is the only scripting language that I'm familiar and at the same time comfortable with, here's a simple snippet that does the second method mentioned above:

<?php
$user = $_GET['user'];
$password = $_GET['password'];
$url = "http://twitter.com/statuses/friends_timeline.xml";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HEADER, false );
curl_setopt($ch, CURLOPT_USERPWD, $user . ":" . $password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "count=20");
$xml = curl_exec($ch);
curl_close($ch);

header('content-type: text/xml');

// print out xml
echo $xml;
?>

Usage:
http://somedomain/path/to/file.php?user=username&password=password

References:

Removing a Part of A URL Using A Rewrite Rule

I was given this simple task to redesign a site. The site was developed using plain HTML and CSS so what I've suggested is to use drupal inorder to speed up the redesign and at the same time make it easy for maintenance.

First thing I did was installed drupal in a subfolder so the URL was http://domain.com/subfolder/. I couldn't install drupal in the root directory since there are other files there and I might probably overwrite those. Another thing is that the client wanted to also use wordpress in the site and it's in the folder /blog/. So the only solution for me was to create a rewrite rule wherein when a visitor goes to http://domain.com, it would be similar as to going to http://domain.com/subfolder/ although the URL on the client browser won't change. Anyways, enough of chitchat. Here's what I added in the .htaccess file.


RewriteEngine on
RewriteCond $1 !^(drupal|images|blog|downloads)
RewriteRule ^(.*)$ /drupal/$1 [L]

I guess it's simple. Basically, all requests are directed to the URL /drupal/ except for URL's with drupal/, images/, blog/, or downloads/ on them.

Yeah!

Website Templates

Here are some templates I have designed (click for preview):






Don't like it?? I don't care! :P

Installing Xdebug (Ubuntu)

If you're not familiar with xdebug, here's a brief intro taken from the site:

The Xdebug extension helps you debugging your script by providing a lot of valuable debug information.
Execute this command in terminal:
sudo apt-get install php-dev php-pear && sudo pecl install xdebug

Then restart your web server: sudo /etc/init.d/apache2 restart (since I'm using Apache2)

Create a php file named phpinfo.php in the "Document Root" and add this line:

<?php
phpinfo();
?>

Update: For some reason I can't get it to work with vim yet. Huhu You can find the error message here. If you happen to know the solution, hope you can share it with me.

Anyways, according to the tutorial here, you need to download the vim script found in this link. After that extract the files to /.vim/plugin/. And to test it, open the php file in vim and press F5. Then quickly go to your browser and enter the URL path to your script with the suffix ?XDEBUG_SESSION_START=1. You can do this within only 5 seconds then it will "disconnect". And that's it.

Setup LAMP and PhpMyAdmin in Ubuntu

Here are the steps to setup LAMP in Ubuntu:

  1. Execute this command in terminal: sudo apt-get install apache2 php5 php5-gd mysql-server-5.0 phpmyadmin. During this operation, you'll be prompted to enter some information needed.
  2. Test if setup was successful by opening your browser and entering "http://localhost/".
  3. Execute in terminal: sudo vim /etc/apache2/apache.conf. At this point, you'll be editing a file using vim to configure Apache2 to work with phpMyAdmin.
  4. Add this line at the bottom of the file: Include /etc/phpmyadmin/apache.conf
  5. Restart apache by executing this command in terminal: sudo /etc/init.d/apache2 restart
  6. Open your browser and go to "http://localhost/phpmyadmin/"
  7. You might notice that there is an error message when you restart apache w/c says "Apache2: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName". To remove this, execute the command: echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn. "man tee" if you need information on the command.
  8. Then try restarting Apache2 again. If all is good, proceed to the next step.
  9. The default location where web documents are stored would be on /var/www/ though the folder requires owner permission. What I did is configured Apache2 to look for the files in /home/[user]/public_html. To do this, copy /etc/apache2/sites-available/default to /etc/apache2/sites-available/[name_you_would_like] by executing the command: sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/[name_you_would_like].
  10. Edit the newly copied file: sudo vim /etc/apache2/sites-available/mine
  11. Change the DocumentRoot and Directory to /home/[user]/public_html/
  12. Disable the default configuration file and enable the new one: sudo a2dissite default && sudo a2ensite [name_of_new_configuration_file]
  13. Reload the new configuration: sudo /etc/init.d/apache2 reload
  14. Restart Apache2: sudo etc/init.d/apache2 restart
  15. Done.
Note: I'm not sure what commands "really" require to "sudo". But, basically, those are the commands I went through. ^_^

References:
Update: I just found out after installing wordpress that you need to do:
chmod -R a+w /home/[user]/public_html/

History of Commands Executed in Terminal (Ubuntu)

Do you wish to see the commands that you've invoked in the terminal. Try this command:
cat ~/.bash_history
If you're not familiar with the cat command. Try executing the command "man cat". It'll give you the information you need about cat.

Anyways, I just wanted to share this since I just knew this. Another reason would be to update this blog.

Cheers! And Happy New Year!!