Monday, February 22, 2010

Universal archive unpacking tool

###   Handy Extract Program

extract () {
    if [ -f $1 ] ; then
        case $1 in
            *.tar.bz2) tar xvjf $1   ;;
            *.tar.gz)  tar xvzf $1   ;;
            *.bz2)     bunzip2 $1    ;;
            *.rar)     unrar x $1    ;;
            *.gz)      gunzip $1     ;;
            *.tar)     tar xvf $1    ;;
            *.tbz2)    tar xvjf $1   ;;
            *.tgz)     tar xvzf $1   ;;
            *.zip)     unzip $1      ;;
            *.Z)       uncompress $1 ;;
            *.7z)      7z x $1       ;;
            *)         echo "'$1' cannot be extracted via >extract<" ;;
        esac
    else
        echo "'$1' is not a valid file"
    fi
}
Поместить в ~/.bashrc или profile

original

Thursday, February 4, 2010

Setting up a network adapter alias

sudo ifconfig eth0:[0-254] 192.168.1.2 up.

Instead of eth0 you can use any of existing interfaces

Wednesday, January 27, 2010

Firefox extension. Thoughts.

While I try to see into Firefox Extension development, I found not evident things for me. And here I'll list'em.
  • You want to append event handler to created by you DOM-element somewhere in '1body' descendants. Don't try to use onclick or like it - you'll get a fail. Use addEventHandler method, and you'll get success :)

Tuesday, January 26, 2010

Django model field inheritance

To inherit model field in Django is not enough simply inherit a field class. It is needed to add attribute __metaclass__ = models.SubfieldBase. After that, you can overload any method you want.

Firefox extension. The first tries

I am developing the service which I'll describe further. And I decide to create a Firefox extension for it. And what I have dug:
  • To create a developer profile may that
    firefox -profilemanager
  • To run another -- development -- copy of Firefox
    firefox -no-remote -P <profile name>
And I assume firefox binary in your path.

Monday, December 28, 2009

Django and Oracle support

To get work Django and Oracle client in Ubuntu:

Download cx_Oracle (choose for your system), Oracle InstantClient and Sql*Plus (in this page you can choose your OS and download the packages (in my case are oracle-instantclient11.2-basic-11.2.0.0.2-1.x86_64.rpm and oracle-instantclient11.2-sqlplus-11.2.0.0.2-1.x86_64.rpm).

Move the files into one directory for simplicity and run

alien -k *.rpm
dpkg -i *.deb
to convert all the downloaded packages to ubuntu deb-format and install them.

Then make symlink to lib, otherwise module won't be found by Django

cd /usr/lib/python2.6
ln -s site-packages/cx_Oracle.so

To avoid

Traceback (most recent call last):
  File "", line 1, in 
ImportError: libclntsh.so.10.1: cannot open shared object file: No such file or directory
add to ~/.bashrc (or /etc/bash.bashrc to system-wide apply)
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/11.2/client64/lib

If you see the message
Traceback (most recent call last):
  File "", line 1, in 
ImportError: libaio.so.1: cannot open shared object file: No such file or directory
run
sudo apt-get install -y libaio1

P.S. If you choose more modern (or older) version of Oracle IntstantClient you have to create symlinks for necessary version, e.g. you see the following error:

Traceback (most recent call last):
  File "", line 1, in 
ImportError: libclntsh.so.10.1: cannot open shared object file: No such file or directory
but in /usr/lib/oracle/11.2/client64/lib directory exists libclntsh.so.11.1. Just make it symbolic link with
ln -s libclntsh.so.11.1 libclntsh.so.10.1

Install RPM in Ubuntu

To install Rpm-package in Ubuntu Linux (to run commands needs to be a superuser or using sudo):
  1. install alien package:
    sudo apt-get install alien
  2. Convert Rpm to Deb (in current directory)
    alient -k <package-file>.rpm
  3. Install the new Deb package
    dpkg -i <package-file>.deb

Problems with VPN-connections in Ubuntu Karmic

I need to connect to Cisco VPN. I had got a file with connection settings. Through NetworkManager I created new VPN connection by import the settings file. Trying to connect - no result. In /var/log/syslog I found the line:
NetworkManager: nm-vpn-connection.c.828: NeedSecrets failed: dbus-glib-error-quark Rejected se
nd message, 1 matched rules; type="method_call", sender=":1.5" (uid=0 pid=969 comm="NetworkManager) interface="org.freedeskt
op.NetworkManager.VPN.Plugin" member="NeedSecrets" error name="(unset)" requested_reply=0 destination="org.freedesktop.Netwo
rkManager.vpnc" (uid=0 pid=7971 comm="/usr/lib/network-manager-vpnc/nm-vpnc-service))
Some googling gives me a bit of information - Keyring manager denied connection of the VPN service. And how to grand access I didn't know. Googling more brings me the answer:
In /etc/dbus-1/system.d/nm-vpnc-service.conf
--- nm-vpnc-service.conf.fixed 2009-04-18 17:56:45.000000000 -0500
+++ nm-vpnc-service.conf 2009-04-18 17:57:37.000000000 -0500
@@ -6,6 +6,10 @@
   <allow own="org.freedesktop.NetworkManager.vpnc"/>
   <allow send_destination="org.freedesktop.NetworkManager.vpnc"/>
  </policy>
+ <policy user="at_console">
+  <allow own="org.freedesktop.NetworkManager.vpnc"/>
+  <allow send_destination="org.freedesktop.NetworkManager.vpnc"/>
+ </policy>
  <policy context="default">
   <deny own="org.freedesktop.NetworkManager.vpnc"/>
   <deny send_destination="org.freedesktop.NetworkManager.vpnc"/>

Thursday, December 24, 2009

Ubuntu's Archive Manager and RAR-archives support

To add support of RAR-archives for Ubuntu's Archive Manager run
sudo apt-get install unrar

Wednesday, December 16, 2009

Disabled Mercurial's strip command

Mercurial command hg strip is disabled by default in Ubuntu. To enable it add to hgrc file (in .hg directory of repository or /etc/mercurial/hgrc) these lines
[extensions]
hgext.mq =

Wednesday, December 9, 2009

Reinstall Ubuntu automatically

There is a very simple command that reinstalls all the distribution packages and reconfigures them automatically. This is particularly helpful when you have done a partial upgrade and eventually have broken the system dependencies tree.
sudo dpkg-reconfigure -phigh -a
since this command would take a lot of time to process (~1 hour) depending on your hardware in case you have a minor dependency problem you can fix it via
sudo apt-get install -f
Source.

Tuesday, December 8, 2009

Create a MySQL database for new user

To create a database and a user, to grant some privileges:

CREATE DATABASE test_db DEFAULT CHARACTER SET UTF8;
CREATE USER 'user'@'%' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON test_db.* TO 'user'@'%';

Mercurial server in haste

Just now I need to pull to spontaneous remote Mercurial repository. I ran hg serve and have tried to push. The server rejects my connection, because it demands secure connection. Attempts to change protocol to HTTPS were failed.
As decision I found the following: in hgrc (or mercurial.ini in Windows) add
[web]
allow_push = *
push_ssl = false

Profit :)