Thursday, September 23, 2010

how to swapping ctrl key and capslock key in console



% loadkeys /usr/share/keymaps/i386/qwerty/emacs2.kmap.gz

Tuesday, September 21, 2010

how to disable automatic captializing the first letter of sentences in OpenOffice.org

The automatic captilizing the first letter of every sentences is very annoying [for me][I believe many people still have good reasons to use it][but this is just for me].

You can disable it by going to Tools => AutoCorrect Options

Please see the screenshot:

Thursday, September 16, 2010

how to update facebook status via command line

Recently, I found a text-based twitter client named "twidge".  It allows me to tweet right from command line.  For example, if you want to do a hello world tweet, you run this:

% twidge update "hello world"

I then think it would be a good idea if I can do the same thing with facebook i.e. to update facebook status right from command line.  However, when I did search on google, I found nothing.

Well, actually, there is an indirect way by:
  1. Adding facebook application "Selective Tweet".
  2. With the same twitter account you use to add "Selective Tweet", whenever you append "#fb" to your tweet, that tweet will also appear on facebook status.
But for many personal reasons, I just dislike this method as the same thing will be put onto both twitter and facebook which is not always what I want.

So what if I want to do it directly...

Recently, I had a chance to try out the Perl module "WWW::Mechanize" - Handy web browsing in a Perl object.  It is a subclass of the well-known LWP::UserAgent module which is a User Agent module for Perl which we use to write robot, spider and such.

Here is the Perl script I use to update facebook status:

#!/usr/bin/perl

use WWW::Mechanize;

$mech = WWW::Mechanize->new;
$mech->agent_alias('Windows Mozilla');

$base_url = 'http://m.facebook.com';

# {{{ login
$mech->get($base_url);
$response = $mech->submit_form(
  fields => {
    email => 'your_email_address',
    pass => 'facebook_password'
  }
);
die $response->status_line unless $response->status_line;
# }}}
 
while (1) {
  print "What's on your mind? : ";
  $status = <STDIN>;
  $response = $mech->submit_form(
    fields => {
      status => $status
    }
  );
  die $response->status_line unless $response->status_line;
}

Here is what you will see when you run it:

unsigned_nerd@linuxsucks ~ % fbset
What's on your mind? : it's easier to update facebook status from command line

By the way, isn't it better if I use some Facebook API instead...?  Umm... maybe later.

Friday, September 10, 2010

how to set up crypted partition under Ubuntu 8.04 or Debian stable (5.0)

Install cryptsetup:

# apt-get install cryptsetup

Load 2 modules:

# modprobe dm-crypt 
# modprobe dm-mod

Use luks to format partition and map it to a device:

# luksformat -t ext3 /dev/sdb1
# cryptsetup luksOpen /dev/sdb1 crypteddisk


crypteddisk is a user defined name.  You can name it whatever you want.  It will be found under /dev/mapper.

I put this line in /etc/crypttab:

crypteddisk /dev/md0 none luks,noauto

I also put this line in /etc/fstab:

/dev/mapper/crypteddisk /data ext3 defaults,noauto 0 0 

Make sure you have /data/ directory and maybe prevent it to be used before being mounted by chattr +i /data.

Now you can mount your new encrypted partition by:

cryptdisk_start crypteddisk
mount /data


Note that I config fstab and crypttab in such a way that it won't automatically mount the encrypted partition at boot time.  You know why?  Thinking about when the machine you are working on is a server located in some data centre (no need to be so far away from your house).  If you set it to be auto mount, it will ask you to enter the LUKS passphrase at boot time which means you won't be able to ssh to the machine as it will just wait there forever until you enter the password lol

vimdiff - useful configuration

Say you want vimdiff to open in horizontal mode and also wrap long lines, you just put the below code into your .vimrc:

" for vimdiff
set diffopt+=horizontal
au FilterWritePre * if &diff | exe 'windo set wrap' | endif
" [end] for vimdiff