(datetime.datetime(datetime.datetime.today().year, datetime.datetime.today().month, calendar.monthrange(datetime.datetime.today().year, datetime.datetime.today().month)) - 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:
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.
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.
MySQL has a query logging feature. In order to use it you have to first enable it.
Step 1: Set your log file in /etc/my.cnf
In the [mysqld] section specify the general log file name:
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
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.
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-126.96.36.199-86.fc9.i686 ro root=UUID=c1c4deb3-cc72-4ce6-b76f-4c4a8d61b61e rhgb quiet
You want to add an asterisk to required fields, huh?
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:
$element->getDecorator('label')->setOption('requiredSuffix', ' * ');
Another option is to add the * while setting the label.
$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.
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:
In short, remember to flatten the image when you want to remove the alpha channel.
Quote from the GIMP docs: