Posts

Showing posts from December, 2011

Tip for VIM

For splitting window.    : split ( for horizontal split )    : vsplit ( for vertical split ) Switch between splitted window    Ctrl-ww Resize splitted window    Ctrl-w + / -   ( 1 unit each time, height )    10 Ctrl-w +   ( resize 10 unit height )    Ctrl-w < / >   ( 1 unit each time, width ) Search and replace    :%s/original/replace/g   ( every occur in file )    :1,$s/original/replace/    :s/original/replace/g ( replace all in current line ) For multiple files    :e ( edit file in new buffer )    :bn ( switch to next file in buffer )    :bp ( switch to previous file in buffer )    :bd ( delete file in buffer , ake close file )    :sp ( edit file in new window ) ETC    :sh ( switch to console ) and Ctrl-d to get back    other way    Ctrl-z (switch to console ) and $fg to get back    show path of current editing file    Ctrl-g ( display file's location )    Ctrl 1 g (display full file's location )

Linux : find out if a dir exist or not

for linux command line, do $ [ -d /tmp] && echo 'dir /tmp not found' then if /tmp not found, it's will display "dir /tmp not found".

Basic with Postgresql

For psql command line, We'll start with >>> psql Create User psql::CREATE USER joe; psql::ALTER ROLE joe PASSWORD 'secret_password'; Or psql::CREATE USER username WITH PASSWORD 'xxxxx'; Or Create an account where the user can create db; psql::CREATE USER username WITH PASSWORD 'xxxxx' CREATEDB; Give him a right on superuser psql::ALTER ROLE joe WITH CREATEDB; psql::ALTER ROLE joe WITH SUPERUSER; Create Database psql::CREATE DATEBASE mydb; Or psql::CREATE DATABASE dbname OWNER rolename; Grant all available privileges to user psql::GRANT ALL PRIVILEGES ON mydb TO joe; psql::GRANT admins TO joe;

Insert text in the middle of text file by sed

I found problem on how to add text line in the middle of the hosts file. Just like below 127.0.0.1   localhost < i want to add text line here > xxxxxxxxxxxxxxx xxxxxxxxxxxxxxx and want to use 'sed', My friend, Sajal Kayan (God of Scripting) introduce me on ref#1, actually I quite not understand that. So he get me 2 approaches. #1   for each time i have to add text line, then do   >>> sed -i 's/127.0.0.1   localhost/127.0.0.1   localhost\n this is new line /' /etc/hosts   >>> sed -i 's/127.0.0.1   localhost/127.0.0.1   localhost\n this is new line 1/' /etc/hosts   >>> sed -i 's/127.0.0.1   localhost/127.0.0.1   localhost\n this is new line 2/' /etc/hosts   then we'll get   127.0.01   localhost   this is new line 2   this is new line 1   this is new line   this is good enough if we don't care about the order. But if you care , Sajal has 2nd approach #2   >>> sed -i 's/127.0.0.1

Do you wanna know what linux's codename you using and its 32 or 64 bits

If you wanna know that, try     >>> lsb_release -cs # for code name or      >>> lsb_release -a # for all information then     >>> uname -m # for display 32/64 bits (i686 or xxx) of     >>> uname -a # for show more information 

Celery issue

(Thank for http://permalink.gmane.org/gmane.comp.python.amqp.celery.user/1695) To create a queue? You know celery automatically declares queues right? You wouldn't 'create' a queue per se, you only declare them, in some context the queue is only actually created when a message is delivered to it. For some transports queues and exchanges *must* be declared by every process that uses them. If you use RabbitMQ then you can create a queue manually like this: from celery import current_app as celery from kombu import Queue, Exchange q = Queue("foo", Exchange("foo", type="direct"), routing_key="foo") with celery.broker_connection() as conn: with conn.channel() as channel: q(channel).declare()

Lubuntu : add kb layout switching

It's just. >> setxkbmap -option grp:switch,grp:alt_shift_toggle,grp_led:scroll us,ar (thank  matata   on  http://ubuntuforums.org/showthread.php?t=1039107 )

Python Advanced Ref

(thank  Gaël Varoquaux)  http://gael-varoquaux.info/computers/python_advanced/index.html