Mini How To

How Many Seconds Are There Till End Of Month?

(datetime.datetime(datetime.datetime.today().year, datetime.datetime.today().month, calendar.monthrange(datetime.datetime.today().year, datetime.datetime.today().month)[1]) - datetime.datetime.today()).total_seconds()

There's a log going on in that one liner. Let's break it down.

The two key Python modules we need to calculate the number of seconds till the end of year are datetime and calendar.

calendar.monthrange(year, month) returns a tuple. The tuple's second element is the number of days in the month.

We create two date objects:

Taxonomy upgrade extras: 

Becoming Productive In Bash Using The Keyboard Shortcuts

Moving around

You can use the arrow keys on keyboard to move around in the command line. Bash also provides convenient keyboard short cuts to navigate effectively. Try them out and see for yourself.

To become a Bash pro user you have to get yourself familiar with the keyboard shortcuts. Once you do, you'll find yourself productive.

CTRL+b move backward one character
CTRL+f move forward one character
ESC+b move one word backward
ESC+f move one word forward
CTRL+a move to beginning of line
CTRL+e move to end of line
CTRL+p move to previous line
CTRL+n move to next line
ESC+ move to first line of history list
ESC+> move to last line of history list

Moving around words using ESC+f and ESC+b are my favourites in this list. Jumping to first and last lines of the history list is also useful.

Taxonomy upgrade extras: 

A Bit Of XML, RSS And CURL In 7 Lines Of PHP And A Useful Program

Today, I was looking for a quick way to get the current weather information on my computer. There are so many websites out there that offer the information. But I was looking for a program I could permanently install on my computer and launch it whenever I want to lookup the weather information. Oddly, I didn't find any satisfying program. At the same time I was also watching a video about network programming. That inspired me to quickly write a program in PHP to print the current weather information where I live.

I started to look out for a web service that offers information about weather for free. Did I tell you programmableweb.com is a useful website to find web services? If you have subscribed to the Tech Chorus blog you know we've been talking about REST, XML-RPC and web services in general for a while. I landed up on the Yahoo! Weather API web page.

I wrote a program to print the weather information in 7 lines of PHP code. I have published this program on Code Album github repository. You can grab it and use it.

If you want to know how to write similar programs, read on. If you know a bit of PHP and have heard about XML and RSS before you can understand the program and start building upon it.

Taxonomy upgrade extras: 

Enable MySQL General Query And Slow Query Log

MySQL has a query logging feature. In order to use it you have to first enable it.

Enabling the general query log

Step 1: Set your log file in /etc/my.cnf

vi /etc/my.cnf

In the [mysqld] section specify the general log file name:

log=/var/log/mysqld.general.log

Step 2: Create the file and make sure it is owned by the system user mysql

touch /var/log/mysqld.general.log
chown mysql.mysql /var/log/mysqld.general.lo
Taxonomy upgrade extras: 

How To Configure Yum To Exclude A Mirror

Many of us have suffered from failing package repository mirrors. Some are slow, some won't have updated content, etc. You might want to remove/blacklist a particular mirror in your yum configuration.

Before trying to remove a mirror, install the fastest mirror plugin.

yum install yum-fastestmirror -y

The fastest mirror plugin is capable of determining mirror speeds and cache it. If that works for you well and good.

Touchpad Tap Function Won't Work On Laptop PC

Issue: The laptop PC has the PS/2 Synaptics TouchPad. The tap function or the double click function does not work out of the box on a fresh Fedora 9 install.

Solution: Add psmouse.proto=imps to the grub configuration file

Step 1: Open the grub configuration from a text editor
vi /etc/grub.conf

Step 2: Append psmouse.proto=imps to the kernel line
I am pasting the information from my computer. It may vary slightly on your computer.

Before: kernel /boot/vmlinuz-2.6.25.10-86.fc9.i686 ro root=UUID=c1c4deb3-cc72-4ce6-b76f-4c4a8d61b61e rhgb quiet

Taxonomy upgrade extras: 

Adding * To Required Zend_Form Field Using CSS

You want to add an asterisk to required fields, huh?

add asterisk to zend form required element

There are many approaches to accomplish this. One among them is setting the requiredSuffix option to the label decorator of the form element. Assuming $element is your Zend_Form_Element object:

<?php
$element
->getDecorator('label')->setOption('requiredSuffix'' * ');
?>

Another option is to add the * while setting the label.

<?php
$element
->setLabel('My Label *')
?>

The third, which I am currently using in one of my Zend Framework powered applications is adding * using CSS. The default label decorator generates the following mark-up.

FOSS Project: 
Content Type: 
Technology: 

How Do I Remove Alpha Channel From The Image Using GIMP

As per the Wikipedia "alpha compositing is the process of combining an image with a background to create the appearance of partial transparency". To remove the transparency or the alpha channel:

  1. Fire up GIMP
  2. Open the image for which the alpha channel has to be removed
  3. Click the Image menu on the image window
  4. Click Flatten Image from the pull down menu
  5. Save

In short, remember to flatten the image when you want to remove the alpha channel.

Quote from the GIMP docs:

Taxonomy upgrade extras: