Thursday, July 30, 2009

Convert CHM to PDF on Ubuntu

By default, you cannot view CHM file in Ubuntu. To view the CHM file, you can use GnoCHM. However, I found that GnoCHM is not so stable and crash a lot. Hence, another option is to convert it to PDF. What you need is the chm2pdf and python-beautifulsoup packages.


Install the packages

sudo apt-get install chm2pdf python-beautifulsoup

Convert the CHM file to PDF

chm2pdf --webpage --beautifulsoup filename.chm
You can even change colour, font, and margin of the generated PDF file. For more information on how to do so, please invoke
man chm2pdf
command on the terminal.

Determine CPU temperature on Ubuntu

Most PCs these days use ACPI. The ACPI shows information such as battery status or thermal information. Hence, to determine the CPU temperature on Ubuntu, you can use the acpi package.


Install the acpi package

sudo apt-get install acpi

Display the temperature


acpi options:
-b, --battery battery information
-B, --without-battery suppress battery information
-i, --capacity show battery capacity information if available
-a, --ac-adapter ac adapter information
-A, --without-ac-adapter suppress ac-adapter information
-t, --thermal thermal information
-T, --without-thermal suppress thermal information
-c, --cooling cooling information
-C, --without-cooling suppress cooling information
-V, --everything show every device, overrides above options
-s, --show-empty show non-operational devices
-S, --hide-empty hide non-operational devices
-f, --fahrenheit use fahrenheit as the temperature unit
-k, --kelvin use kelvin as the temperature unit

For example, to display information for every device, use the -V option.
$ acpi -V
Battery 0: Full, 100%
Battery 0: design capacity 7800 mAh, last full capacity 7791 mAh = 99%
AC Adapter 0: on-line
Thermal 0: ok, 36.5 degrees C
Cooling 0: LCD 0 of 7
Cooling 1: Processor 0 of 10
Cooling 2: Processor 0 of 10

Wednesday, July 29, 2009

View CHM file on Ubuntu

Microsoft Compiled HTML Help (CHM) is a common format for e-book and online documentation.

To view CHM file in Ubuntu, you need to have a CHM viewer installed. GnoCHM is one of the CHM file viewer, designed to integrate nicely with Gnome, using PyCHM.
GnoCHM CHM Viewer
GnoCHM can be installed by pasting the following command in the terminal.
sudo apt-get install gnochm
The shortcut will appear in Applications > Accessories menu as "CHM Viewer".
Access GnoCHM from the menu


This article discuss a simple way to view CHM file. If you know a better CHM viewer other than GnoCHM, please leave a comment.

Thursday, July 23, 2009

Solar eclipse

Solar eclipse

Date: July 22, 2009
Time: 0930 GMT +8
Location: Dewan Kuliah 5, UiTM Perlis, Arau, Malaysia.
Photo courtesy of Syed Mohd Hijan Syed Hamzah.

Tuesday, July 14, 2009

How to use multiple windows in Vim

This article provides some tips on how to use multiple windows in Vim.

Start Vim with n multiple windows

  1. n verticals windows.
    vim -On filenames
  2. n horizontal windows.
    vim -on filenames
Note: n is the number of windows.

Close a window

  1. Close the current window.
    Ctrl+W c
  2. Close the current window. If it is the only window left, quit Vim.
    Ctrl+W q

Split a window

  1. Split horizontally the current file.
    Ctrl+W s
  2. Split horizontally and open a file.
    :sp filename
  3. Split vertically the current file.
    Ctrl+W v
  4. Split vertically and open a file.
    :vsp filename

Move the cursor between windows

  1. Move to the right window from the current windows.
    Ctrl+W l
  2. Move to the left window from the current windows.
    Ctrl+W h
  3. Move to the top window from the current windows.
    Ctrl+W k
  4. Move to the bottom window from the current windows.
    Ctrl+W j
  5. Move to the next window below the current one. If no below window exist, move to the top window.
    Ctrl+W w

Rotate windows location

  1. Move the current window to the right.
    Ctrl+W L
  2. Move the current window to the left.
    Ctrl+W H
  3. Move the current window to the top.
    Ctrl+W K
  4. Move the current window to the bottom.
    Ctrl+W J

Window resizing

Resizing windows can be made by using the mouse as well as the following commands.
  1. Make all windows equal in height.
    Ctrl+W =
  2. Increase height.
    Ctrl+W +
  3. Decrease height.
    Ctrl+W -
Note: Thanks to Ferd T-H, resizing could also be done by using
Ctrl+W < or >

Conclusion

I hope that these commands are enough for you to start using windows in Vim. However, if you know some good command(s) to please don’t hesitate to leave a comment.

Sunday, July 12, 2009

7 Habits For Effective Text Editing 2.0 video

Tips on using Vim effectively by the main author of Vim, Bram Moolenaar, who writes the core Vim functionality.

Python interactive help mode

Python provides an interactive help mode inside the interactive Python interpreter.

This tutorial provides some basic on how to use the help mode.

Enter the help mode


To use it, start the Python interpreter (or, IDLE), and then type help() and press Enter to start the interactive help mode.




Quit the help mode


To exit the help mode, type quit and press Enter.


List of Python keywords


To get a list of available keywords in Python, type keywords and press Enter.

To get help on certain keyword just type the keyword and press enter.


List of available modules


To get a list of available modules in Python, type module and press Enter.

To get help on certain module just type the module name and press enter.


List of available topics


The topics command gives a list of topics regarding Python programming language.

To get a list of available topics, type topics and press Enter.

To get help on certain topic, just type the topic name and press enter.

Friday, July 10, 2009

WordPress: Display only on first page

This code will enable you to display items such as text or image only on the first page of the homepage or archive.

It can be use in index.php, category.php or archive.php.

What you need is the $page WordPress variable. 1 for the first page of results, 2 for the second page, etc.

To use it, put the code inside The Loop.
<?php if ( $paged < 2 ) { ?>

Your text or image for the first page goes here!

<?php } else { ?>

WordPress 2.8.1 is avalaible for download

According to the WordPress blog, WordPress 2.8.1 is now ready for download. Version 2.8.1 includes updates and security patches for version 2.8 bugs. One of the most important update is the reduce of memory usage of the Dashboard.

Click here to download the latest WordPress release.

Friday, July 3, 2009

How to disable Flickr automatic updates in Nokia 5800

Nokia 5800 supports Flickr services via its Share Online feature. It can even updates the Flickr photos automatically. The bad thing is that this feature is turned on by default when you enable the Flickr service. The default setting is it will update to Flickr every 6 hours, and it will consumes for about 600kb of data transfer. This feature is bad for users that do not subscribe to the unlimited data plan.


How to turn the automatic update feature off?



  1. Press the XpressMusic button.

  2. Select Settings (The bottom third right most icon).

  3. Select Advance.

  4. Disable Use cellular. Disable Use cellular will disallow the phone to use mobile network to connect to Flickr.

  5. Disable Roaming. The phone will not update Flickr outside when you are overseas.

  6. Select Download interval option to Manual.

Count the number of occurences using Counter() in Python

Counter is an object of collections module, and it is a dict subclass for counting hashable objects, in Python 3.

To count the number of elements occurrences in a list

>>> from collections import Counter
>>> z = ['blue', 'red', 'blue', 'yellow', 'blue', 'red']
>>> Counter(z)
Counter({'blue': 3, 'red': 2, 'yellow': 1})

Count the number of alphabet occurrences in a text

>>> from collections import Counter
>>> Counter("This is a test")
Counter({' ': 3, 's': 3, 'i': 2, 't': 2, 'a': 1, 'e': 1, 'h': 1, 'T': 1})

To find the n most common words in a text

n is the number of most common words to find
Counter(the_text).most_common(3)
For more information, read The Python Standard Library

Archive and Compress Files Using zip

Zip and unzip are two free command line programs that comes with Linux. For Windows, they can be downloaded from the Info-ZIP Website. This article provides the basic of archiving and compressing files using the command line zip program.

Zip one file

zip filename.zip file_to_compress

Zip multiple files

zip filename.zip file_to_compress1 file_to_compress2 file_to_compress3

Compression options


The compression level ranges from 0 to 9. Level 0 means no compression, 1 compress faster, and 9 compress better. The default is 6.
zip -9 filename.zip file_to_compress

Password protect zip archive

zip -P the_password filename.zip file_to_compress

To be prompted for password instead of specifying the password in the command line, use -e instead of -P.
zip -e filename.zip file_to_compress
Enter password:
Verify password:

Unzip files

unzip filename.zip

Unzip files with informations (verbose mode)

unzip -v filename.zip

List files that will be unzipped

unzip -l filename.zip

Test Files That Will Be Unzipped

unzip -t filename.zip

Thursday, July 2, 2009

How to disable A-GPS in Nokia 5800

Nokia 5800 comes with an integrated GPS device. Besides, Nokia 5800 also support Assisted GPS (A-GPS), and it is turn on by default.

A-GPS could help the phone to connect to the satellite faster. However, A-GPS requires the internet connection. Therefore, if you are not subscribed to the unlimited data plan package, you may want to disable the A-GPS support.

My ignorance of this issue had cost me a few hundreds Ringgit.

To disable the A-GPS support in Nokia 5800, follow this steps:

  1. Press the white Menu button.

  2. Select Apps.

  3. Select Location.

  4. SelectPositioning.

  5. Select Positioning Methods.

  6. Select Assisted GPS, and select Disable.

Wednesday, July 1, 2009

How to list out Python reserved words

To list out the Python reserved words, just enter the following lines into the Python interpreter.
>>> import keyword
>>> print(keyword.kwlist)

['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
Python Reserved Words