Monday, August 24, 2009

How to determine the linux distribution name or version

There are multiple ways to check what linux distribution and version you are using.

Here are some of them.
$ cat /etc/issue
Ubuntu 9.04 n l
$ uname -a
Linux riza-laptop 2.6.28-15-generic #49-Ubuntu SMP Tue
Aug 18 19:25:34 UTC 2009 x86_64 GNU/Linux
$ lsb_release -d
Description: Ubuntu 9.04

Saturday, August 22, 2009

Cursor jump to other location while typing on Ubuntu

Disable mouse clicks with touchpad
I am using Ubuntu 9.04 for my Dell Vostro 1400 laptop, and faced a very annoying problem where the cursor jump to other location - probably to the location of mouse arrow - while I am typing.

How do I solve this problem?

What I do is, I disable the "Enable mouse click with touchpad" in the "Mouse Preferences" dialog box.

To bring up the "Mouse Preferences" dialog, click on System > Preferences > Mouse.

Wednesday, August 19, 2009

Python: How to convert a dictionary into a list of key-value

Using the list() function, we can convert a dictionary into a list of key-value tuple.
>>> x = {'a':1, 'b':2}
>>> x
{'a': 1, 'b': 2}
>>> y = list(x.items())
>>> y
[('a', 1), ('b', 2)
To convert back into dictionary, use the dict() function.
>>> z = dict(y)
>>> z
{'a': 1, 'b': 2}

How to install Adobe Flash Player plugin on Ubuntu

To install Adobe Flash Player plugin

sudo apt-get install flashplugin-nonfree

To check the current version, if installed using Aptitude (the method above)
sudo aptitude show flashplugin-nonfree

Tuesday, August 18, 2009

How to post source code for viewing in WordPress.com

WordPress.com allow you to post source code of some languages.

The supported languages include:

  • bash

  • cpp

  • csharp

  • css

  • delphi

  • html

  • java

  • jscript

  • php

  • python

  • ruby

  • shell

  • sql

  • vb

  • xml


What you need to do is to wrap the source code between sourcecode tag. For example:
[sourcecode language='python']

your code here

[/sourcecode]

Saturday, August 15, 2009

Convert RPM package to deb package format on Ubuntu

How to convert RPM package to deb package format on Ubuntu, and install it with dpkg?

Step 1: Install the required packages

sudo apt-get install alien dpkg-dev debhelper build-essential

Step 2: Convert the RPM file


Run
sudo alien thepackagename.rpm
or
fakeroot alien thepackagename.rpm
and a .deb file called thepackagename.deb will be generated.

Step 3: Use dpkg to install the package

sudo dpkg -i thepackagename.deb

Thursday, August 13, 2009

Python: Remove items from a list that occur in another list

Suppose that you have two list x and y. How to remove items from list x that occur in list y?

Method 1

>>> x = [1, 2, 3, 4, 5, 6, 7, 8]
>>> y = [4, 7, 9]
>>> list(set(x) - set(y))
[1, 2, 3, 5, 6, 8]

Method 2

>>> x = [1, 2, 3, 4, 5, 6, 7, 8]
>>> y = [4, 7, 9]
>>> [i for i in x if i not in y]
[1, 2, 3, 5, 6, 8]
I have presented two methods for removing items from list x that occur in list y. If you have better method, please leave a comment.