Keyboard shortcuts in interactive psql

Posted on December 19, 2008
Filed Under PostgreSQL, bash, mac os x | Leave a Comment

psql = PostgreSQL interactive terminal

I’ve read this article (http://www.depesz.com/index.php/2008/03/30/keyboard-shortcuts-in-psql) today and decided to try on my MacBook.

Interestingly, all shortcuts were working fine in normal shell, but no action as soon as run “psql db_name” and go into interactive psql prompt.

After searching google, found out that psql on Mac OS was using libedit instead of “readline”, so had to edit $HOME/.editrc file as below:

postgres@deimos:~ $ vim $HOME/.editrc
bind -s “^[e" "explain analyze "
bind -s "^[s" "select * from "

To have the special characters "ctrl-v" and "option-e" insterted while in vim, I had to tick/enable "Terminal.app --> Preferences --> [*] Use option as meta key”

How to create iTunes Store account without credit card details?

Posted on November 28, 2008
Filed Under mac os x | Leave a Comment

Recently we’ve bought an iPod Touch (8gb model) and obviously went to iTunes Store to check out/download some applications… On first access, it prompted me to create an account, so I followed on-screen instructions to do so. The problem came out when it asked me for credit card details. I do not have one, and it would not allow me to skip that portion of registration process.

After some google’ing around, I’ve found out that it is possible to create an account without providing credit card details:

  1. Find a free application first.
  2. Click on “GET APP” link (if the application is not free it will be “BUY APP”).
  3. You’ll be prompted to login or create an account.
  4. Now, it will provide another option “(o) NONE” in credit card details section, which you can choose and complete the registration process.

Go get them!

Mac OS X and colorized Terminal.app

Posted on November 28, 2008
Filed Under bash, mac os x | Leave a Comment

I used to like colorized bash prompt on my Linux boxes, whereas default Terminal.app prompt will give you a bit boring colors.

You can change that with below snippet of code in your .bashrc

PS1=’\[\033[01;32m\]\u\[\033[01;34m\] @ \[\033[01;31m\]\h \[\033[00;34m\][ \[\033[01;34m\]\W \[\033[00;34m\]]\[\033[01;32m\] \[\033[00m\]‘

If you want to test above prompt without doing any changes to your current/default prompt, you can just copy/paste below in your prompt and press [Enter]:

export PS1=’\[\033[01;32m\]\u\[\033[01;34m\] @ \[\033[01;31m\]\h \[\033[00;34m\][ \[\033[01;34m\]\W \[\033[00;34m\]]\[\033[01;32m\] \[\033[00m\]‘

Update: Forgot to link the source that I’ve used http://twistedcode.blogspot.com/search/label/howtos

Mac OS X VirtualBox and Shared Folders

Posted on August 5, 2008
Filed Under mac os x | Leave a Comment

I use eclipse to play around with some ruby/php/jsp code. And usually that’s ~/Projects/workspace/my_site

Now, let’s assume that I would like to host these files off my Ubuntu guest OS… What do I do?
1. Add the folder in “Shared Folders” screen as seen on the screenshot.
2. Boot the guest OS up and run this command:

root@virtuozo~$ mount -t vboxsf -o uid=1000,gid=33 blog /var/www/blog/

As you can see, I used exactly the same name that’s set in the

screenshot above. What’s next? Just restart apache and point your browser to the right IP/hostname. In the example above, uid=1000 is normal user, whereas gid=33 is the www-data user (apache).
PS: You might need to do some port forwarding, so that when you point your browser to http://localhost:8000 it will be forwarded to localhost:80 on your guest OS.

VirtualBox on Mac OS X and port forwarding

Posted on August 5, 2008
Filed Under mac os x | Leave a Comment

I’ve been using VirtualBox for some time already, and frankly speaking I’ve got no problems.

VBoxManage setextradata “ubuntu-lts” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestweb/Protocol” TCP
VBoxManage setextradata “ubuntu-lts” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestweb/GuestPort” 80
VBoxManage setextradata “ubuntu-lts” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestweb/HostPort” 8000

VBoxManage setextradata “ubuntu-lts” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssl/Protocol” TCP

VBoxManage setextradata “ubuntu-lts” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssl/GuestPort” 443
VBoxManage setextradata “ubuntu-lts” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssl/HostPort” 8443

VBoxManage setextradata “ubuntu-lts” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol” TCP

VBoxManage setextradata “ubuntu-lts” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort” 22
VBoxManage setextradata “ubuntu-lts” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort” 2200

VBoxManage setextradata “xp_pro” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestremote/Protocol” TCP

VBoxManage setextradata “xp_pro” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestremote/GuestPort” 3389
VBoxManage setextradata “xp_pro” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestremote/HostPort” 3388

Now, let’s say you want to remove any of the above port forwardings (I’ll do for SSL port forwarding in my case):

VBoxManage setextradata “ubuntu-lts” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssl/Protocol”

VBoxManage setextradata “ubuntu-lts” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssl/GuestPort”

VBoxManage setextradata “ubuntu-lts” “VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssl/HostPort”

Basically, you just remove the last string from the same set of commands.

How to brute-force password protected zip file?

Posted on November 9, 2007
Filed Under bash, linux, mac os x | Leave a Comment

Imagine a situation when you need to unzip a password protected zip file. So, how do we do it? 

synack@deimos $ cat crack.sh
#!/bin/bash
# Author: K. Jusupov
# Date: 09/11/2007
# Description: Brute force the password protected zip file using ‘password’ from a file

while read line; do
unzip -P $line $1;
if [ $? = 0 ]; then
# successful unzip
clear
echo “Password found: $line”
break
fi
done < passwd.txt

Leopard upgrade

Posted on November 4, 2007
Filed Under mac os x | Leave a Comment

Well, it was 26th when I went to our local (read nearest) Mac shop, I knew that I’m not gonna be purchasing Leopard, it was more of to see what is gonna happen… Basically, when I reach the shop, the doors were half closed, and some sort of crowd was outside.

Next day onwards I’ve read different post talking about the experience the users were having installing, configuring, customizing or upgrading, etc… There were people who had that experience in a bit salty way…

So, today I eventually got my copy of Leopard and after getting all my backups done, started upgrade… To be on the safe side, I did verify and repair my hard disk, just in case my upgrade will fail. It took about 1.5 - 2 hours to finish the upgrade and get my very first experience with Leopard :)

I got my mail (about 500mb) without any issues, all my pictures (about 20gb) without any problems. I think all my apps are OK, working fine… I don’t think I will be able to do any benchmarks on the performance, speed, etc… As never had problems running on my 2gb RAM and 2.16 Ghz Core 2 Duo MacBook. So, overall I can say - my upgrade went very smooth, no issues. Right after the upgrade finished, was able to get on-line (wi-fi) and get some software updates.

Hopefully next few posts will be able new features, new apps, etc…

Read/write activity on tables - PostgreSQL

Posted on November 3, 2007
Filed Under PostgreSQL | Leave a Comment

If you ever wanted to know which tables are actively being hit on your database, please pay attention to: http://www.postgresql.org/docs/8.1/static/monitoring-stats.html

postgres@server:~$ psql testdb  -c “select relname, idx_tup_fetch as seeks, n_tup_ins + n_tup_upd + n_tup_del as writes from pg_stat_user_tables order by writes desc limit 5;”
relname        |  seeks   | writes
——————+———+——–
user                    |  364963 | 355314
employee          |     232     | 282747
class                   |  587978 | 190938
task                    |      79      | 125255
project               |                | 117282
(5 rows)

Based on these kind of output you might want to reconsider some… Maybe reconsider how your database is setup? Put most active tables as a separate database? Move them to a separate discs? etc…

How big is PostgreSQL database size?

Posted on November 1, 2007
Filed Under PostgreSQL | Leave a Comment

Today found another very useful info from http://www.planetpostgresql.org/

tempdb=# SELECT pg_database.datname,
pg_size_pretty(pg_database_size(pg_database.datname)) AS size
FROM pg_database;

And this is what it shows:

     datname      |  size
——————+———
postgres         | 3480 kB
jasperserver  | 82 MB
testdb             | 3480 kB
template1      | 3537 kB
template0     | 3480 kB
tempdb          | 127 MB
(6 rows)

Time: 143.405 ms

xfce4 + kiosk mode

Posted on October 8, 2007
Filed Under linux | 2 Comments

Additional to my previous post where I’ve mentioned about LTSP setup and xfce4, I’d like to post a little about how we’ve setup xfce4.

Following this info (http://wiki.xfce.org/kiosk_mode), we’ve setup xfce4 in “kiosk” mode, which means standard xfce4-panel through-out the system for all non-wheel users.

root@server~# cat /etc/xdg/xfce4/kiosk/kioskrc
[xfce4-panel]
CustomizePanel=%powerusers,foo

[xfce4-session]
CustomizeSplash=ALL
CustomizeChooser=ALL
CustomizeLogout=ALL
CustomizeCompatibility=%wheel
Shutdown=%wheel
CustomizeSecurity=NONE

Now, only those users in “wheel” group can customize their xfce4-panel items, the rest of the users will get the standard configuration files from /etc/xdg/xfce4/panel/*

First we had some problems trying to get this standards to work, i don’t know why, but we could not grasp the idea of “kiosk” mode, and were trying to add customized configuration files into $HOME/.config/xfce4/panel/* and were wandering why our custom panel is not there on login…

Later we understood that by creating “kioskrc” file, we’ve forced the xfce4 not to read $HOME/.config/xfce4/panel/* but read /etc/xdg/xfce4/panel/*

Eventually (today) we’ve all that to behave as we wished. You can see below how all that will/should look like:


synack@xcpmd /etc/xdg/xfce4/panel $ ls
actions-12.rc launcher-9.rc separator-6.rc
launcher-10.rc orageclock-11918073222.rc systray-4.rc
launcher-11918071840.rc panels.xml tasklist-3.rc
launcher-11918072271.rc separator-11915433711.rc xfce4-menu-5.rc
launcher-7.rc separator-11918074303.rc
launcher-8.rc separator-13.rc

keep looking »