Categories
Linux Python

Python Script to Monitor Laptop Battery Charge (Ubuntu/Linux Mint)

I got my laptop two days ago. It’s a Compaq Presario CQ42-220TU. Battery backup is around 3 hours. I am using Linux Mint which is a variation of Ubuntu. Just a few minutes ago I wrote a Python script that monitors the battery charge and if it’s discharging, it gives a notification with remaining percentage of charge every 5 minutes.

Here’s the source codes for the curious minds 😉

Download:http://code.google.com/p/masnun/downloads/detail?name=battery.py

For convenience, I added the script to my start up applications. So whenever I log in to my lappy, it gets auto started. If you want to use this script as well, save the above source code in a file. Let’s assume you saved it in a file named “battery.py” in your home folder. Now give it execution permission. Right click on the file. Go to properties. In the “Permissions” tab, tick the option saying “Allow executing file as program”. Close the dialog box.

Now go to “Preferences” menu from Sytem menu (Ubuntu) or Mint Menu (Linux Mint). Go to Startup Applications. Click Add. Type in a name and comment. In the command field, type the full path of the file. Eg. /home/<_username_>/battery.py.

Restart your PC. 🙂

If you can’t get it working, please provide feedback here or catch me on IM. My contact details are available on https://masnun.com.

Categories
PHP

Automated MySQL Database Backup System

I just finished writing a tool to automate mysql database backup. It dumps the configured mysql database, zips the SQL file into a TGZ archive and emails the attachment to a predefined email address.

Download: http://masnun.googlecode.com/files/sqlbackup.zip

What you need to do to use this tool is to download it, extract the folder named “sqlbackup”, edit the index.php file to configure the database and email settings, upload the folder to your webhost and set up a cron job to run the tool periodically.

In fact, it’s simple though it looks complicated. Try it yourself! Gonna be easy.

I am using Yahoo! Mail and a custom filter to store the database backups into a dedicated folder inside my Yahoo! Mailbox. Yahoo! has un-metered storage. So you can use this huge storage to have your databases backed up safely.

I am running the cron job once everyhour for testing purpose. I will set it to run once a day since I don’t have much database operations everyday. If your application sees frequent database changes, use a frequent cron job. Please consider checking out your control panel to know how to set a cron job if you don’t know already.

Enjoy!

Categories
PHP

Coupling Zend Framework with CodeIgniter

CodeIgniter is a super cool web application framework for PHP. It is lightweight and lets you get the jobs done in a fashion. It is the first framework I have used and I am still using it. On the other hand, Zend Framework is from Zend, the PHP company. I appreciate the huge library and the full stack nature. I respect the fact that ZF is from the people who maintain PHP. But honestly, I don’t find it feasible for medium and small projects.

One of the brighter aspects of the Zend Framework is that it has many cool libraries. The framework itself is loosely tied and the components are available as stand alone. We can take this opportunity to integrate the powerful library of the Zend Framework into the beautiful CodeIgniter making ourselves more productive than before. Specially, we can relieve ourselves from writing and maintaining wrappers to different APIs.

Ok then, let’s see how do we integrate the Zend Framework libraries into CI.

1) Setup CodeIgniter.

2) Download the Zend Framework. Extract the archive.

3) From the ZF files, copy the “Zend” directory from inside the “library” directory.

4) Paste the directory into the “system/application/libraries” directory. So ultimately, the new location of the copied “Zend” directory would be “system/application/libraries/Zend”. If you’re on Linux/Unix, we need to deal with file permission. Make the Zend directory accessible by all. I don’t think I need to tell you how to do that with chmod, do I ? 😉

5) In the same “system/application/libraries/” directory, create a new file named “Zend.php” and put the following contents:

🙂 We are done. That completes the integration. Now we can load any Zend component inside our controllers. Let’s make our hands dirty by modifying the default welcome controller. Open the “system/application/controllers/welcome.php” and put the following contents:

If you read the codes above, you already know what it does 🙂 If everything goes right, you’ll see a bunch of Flickr photos with the “worldcup” tag. Clicking on a photo will take you to the Flickr page of that photo.

Now, what we have seen is pretty straightforward. We don’t use any hooks or don’t go for any complexity. We simply put the Zend library in the application library. Then we write a loader class that loads Zend libraries. When we construct this “Zend Loader” object, it adds the Zend library directory to the include path. Then when we use the load() method of the object, it imports the library and adds the functionalities to the current scope 🙂

Click on the following to know how you can access pdf files anywhere without transferring them – sodapdf.com.
Enjoy the Zend Services with the cool CodeIgniter framework! Have fun 😀