Ubuntu/Debian: see files installed by package

Checking the files installed by a package is easy enough with the Synaptic package manager (Right-click package > properties > installed files tab).

Here’s how to get that information without leaving the comfort (cough) of your bash terminal:

$ dpkg-query -L package_name

For example:

$dpkg-query -L flashplugin-installer
/.
/usr
/usr/lib
/usr/lib/xulrunner
/usr/lib/xulrunner/plugins
/usr/lib/mozilla
/usr/lib/mozilla/plugins
/usr/lib/iceape
/usr/lib/iceape/plugins
...
Advertisements

Vim: pasting text without it cascading

If you’re like me and use highlight + middle click pasting in Linux a lot, you may have tried to paste text in a Vim window at some point… with surprising results.

For example, highlight the following text:

import re
for test_string in ['555-1212', 'ILL-EGAL']:
    if re.match(r'^\d{3}-\d{4}$', test_string):
        print test_string, 'is a valid US local phone number'
    else:
        print test_string, 'rejected'

Pasting it into a Vim terminal window when in insert mode will give you something like this:

mport re
for test_string in ['555-1212', 'ILL-EGAL']:
    if re.match(r'^\d{3}-\d{4}$', test_string):
                print test_string, 'is a valid US local phone number'
                                else:
                                                        print test_string, 'rejected'

Eh?

To make it paste as expected, first use the following command in Vim:

:set paste

Paste your text and it will come out formatted correctly. When you’re done, unset it with:

:set nopaste

(Python code example from http://wiki.python.org/moin/SimplePrograms)

MySQL + ODBC + Python

How to connect Python programs to a MySQL database using ODBC on Ubuntu 10.04 LTS (Lucid)

This guide assumes you already have a MySQL server set up somewhere

  1. Install needed packages:

    sudo apt-get install unixodbc unixodbc-dev python-dev libmyodbc

    (libmyodbc is the MySQL driver for ODBC)

  2. Get current version of pyodbc:
    If you have python-setuptools installed:

    sudo easy_install pyodbc

    Or with pip (from python-pip):

    sudo pip install pyodbc

    Or if all else fails, download the latest source archive from https://code.google.com/p/pyodbc/downloads/list
    (I used v2.1.8) extract it somewhere on disk, cd into the directory, and run

    sudo python setup.py install

  3. Add a reference to MySQL driver to ODBC config file /etc/odbcinst.ini:

    [MySQL]
    Description = ODBC for MySQL
    Driver = /usr/lib/odbc/libmyodbc.so
    FileUsage = 1

  4. Test it:

    python
    import pyodbc
    cn = pyodbc.connect('DRIVER={MySQL};SERVER=localhost;DATABASE=test;UID=root;PWD=abc;')

For more examples of pyodbc usage the official documentation is very good: https://code.google.com/p/pyodbc/wiki/GettingStarted

This was pieced together from a number of sources which I’ll credit when I find the links again…