Replace a string in all files recursively within a directory

Power of NIX:

find /some/dir -type f | xargs sed -i 's|string1|string2|'

Even stronger, replace a string in all files that match a regex:

grep -rlE "^regexhere$" /some/dir | xargs sed -i 's|string1|string2|'

Note that grep uses POSIX regex, not perl-like regex. But i think POSIX regex is sufficient for most cases.

Or you can use rpl (I don’t)

SEO for your own personal brand

Update Nov 6.: Yup, first place now, not even one week. Given my name is quite unique, it’s not something extraordinary :-P

I searched for my own name “Ngo Ky Lam” and this website is not even in the top five. Have a look:
Ngo Ky Lam SEO
I knew this a long time ago but i didn’t bother to optimize my website for my name. No more. I changed the title of the blog’s homepage a bit, let’s see if i can get to number one spot in one month …

PS: it’s strange to see Quora profile page get the first position. Quora has PR of 5, when Github has 7. Because the search term shows up in title, content and URL ? I think so.

Remove GNOME panel

How to remove GNOME panel (it’s not to remove gnome-panel package)

Removing the last panel isn’t possible, and as long as the panel is running as Gnome component it will automatically spawn back if you try to kill it.

So, if you want to remove the Gnome-panel from your desktop you need to start gconf-editor and then remove “panel” from the list in desktop/gnome/session/required_components list (and perhaps also unset the desktop/gnome/session/required_components/panel -key).

But if you are planning to just run some other panel or dock instead it would make sense the leave the panel in the session components, and then just set the desktop/gnome/session/required_components/panel to use whatever program you are planning to run. This would automatically start that app for you and also autospawn it back if it crashes or is killed.

Also note that if you disable Gnome-panel you will loose the Alt-F2 Run dialog as well, so make sure you have some other way to start applications that the Run dialog and panel menus.. If you want similar functionality without running the Gnome-panel Gmrun is a nice app for the purpose, just set Alt-F2 as keyboard shortcut to launch it.

I don’t understand why we aren’t allowed to remove the last panel ? And loose the Run Dialog as consequence ???

Sometimes it’s beyond your imagination

The sheer stupidity of this registration form is unfathomable. Not only they don’t allow white spaces, they also forbid vietnamese characters ! How can I submit my name now ?!

lacviet mtd registration form stupidity

On the other side, i really give kudos to LacViet for having an usable ecommerce site. They make online transactions quite pleasant to go through (except the atrocity above, of course)

Interesting Windows hotkeys you should know about

non trivial windows hotkeys

Vim has shown me the power of muscle memory. That’s why i always try to learn hotkeys of any thing i use daily. Managing your desktop environment of course is one of those tasks.

Below are non-trivial and useful windows hotkeys that you probably don’t know about.

Win + Pause = System Properties

Win + D = Show Desktop

Win + M = Minimize all windows

Win + E = Launch Win Explorer (@ My Computer),

Win + R = Run Command

Win + L = Lock the screen

Win + X = Open Windows Mobility Center

Win + T = Shift through windows list in task bar (Win7)

Win + P = Change display output between Computer and Projector

Win + B = Let you select items in task bar’s tray

Ctrl + Esc = Start Menu (for those who use old keyboard)

Ctrl + Shift + Esc = Show Task Manager

Win + Shift + M = Maximize all windows

Alt + Spacebar + X = Maximize window

Alt + Spacebar + N = Minimize window

Alt + Spacebar + R = Restore

Alt + Tab = Shift between Windows (this one is trivial but do you know that Alt + Shift + Tab = Shift between Windows in reverse order ?)

Ctrl+ Shift + F10 = Shows Context Menu (Mouse Right Click Effect)

Application Specific (generally): Ctrl + S = Save, F3/Ctrl + F = Find

Desktop/Win Explorer: F2 = Rename File, F3/Win + S = Launch Search

Php-fpm error after reinstall PHP

Error:

lamnk@lamnk:~% sudo php-fpm start

Starting php_fpm Error in argument 1, char 1: no argument for option -
Usage: php-cgi [-q] [-h] [-s] [-v] [-i] [-f ] php-cgi [args...]
-a Run interactively
-C Do not chdir to the script's directory
-c | Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value 'bar'
-e Generate extended information for debugger/profiler
-f Parse . Implies `-q'
-h This help -i PHP information
-l Syntax check only (lint)
-m Show compiled in modules -q Quiet-mode. Suppress HTTP Header output.
-s Display colour syntax highlighted source.
-v Version number
-w Display source with stripped comments and whitespace.
-z Load Zend extension
................................... failed

Reason:

The old config file php-fpm.conf is located at /etc. However the new config file is moved to /usr/etc.

I don’t know why is that. I’ve used the exact same old configuration directives …

Fix:

Move or copy php-fpm.conf from /etc to /usr/etc. Problem solved.

Reset TCP/IP networking stack in Windows 7 and Vista

Sometimes your DHCP service is not able to pull an IP address, the reason could be that the network stack on Windows goes banana. To fix the problem, open command prompt with administrator privilege (click on Start → type in “cmd” → right click on the command prompt and choose “Run as Administrator”) and type these command:

netsh int ip reset C:\netsh.log.txt
netsh winsock reset

… then all your network configuration will be reset.

Update: The command netsh is very powerful, you can control a lot of things in Windows with it, like network interfaces, route table …

Some examples:

  • Set the LAN adapter to static IP address:

    netsh interface ip set address name="Local Area Connection" static 192.168.10.15 255.255.255.0 192.168.10.1 1

  • Set the LAN adapter to DHCP:

    netsh interface ip set address name="Local Area Connection" dhcp

  • Configure the LAN adapter’s secondary DNS:

    netsh interface ip add dns name="Local Area Connection" 8.8.8.8 index=2

Almost there …

Yesterday I wanted to clean around my home directory:

rm dmesg.txt feh_02 * boot.txt test.txt test.txt~ xxxtest.txt

And this is the result:

zsh: sure you want to delete all the files in /home/lamnk [yn]? n
zsh: sure you want to delete all the files in /home/lamnk [yn]? y
rm: cannot remove `feh_02': No such file or directory
rm: cannot remove `Customization': Is a directory
rm: cannot remove `Desktop': Is a directory
rm: cannot remove `Documents': Is a directory
rm: cannot remove `Download': Is a directory
rm: cannot remove `Dropbox': Is a directory
rm: cannot remove `Ebooks': Is a directory
rm: cannot remove `Movies': Is a directory
rm: cannot remove `Music': Is a directory
rm: cannot remove `Photos': Is a directory
rm: cannot remove `Pictures': Is a directory
rm: cannot remove `Truyentranh': Is a directory
rm: cannot remove `backup': Is a directory
rm: cannot remove `builds': Is a directory
rm: cannot remove `boot.txt': No such file or directory
rm: cannot remove `test.txt': No such file or directory
rm: cannot remove `test.txt~': No such file or directory
rm: cannot remove `xxxtest.txt': No such file or directory

Luckily i didn’t issue rm -rf as usual …

I will look at shell’s warning before press Y

I will look at shell’s warning before press Y

I will look at shell’s warning before press Y

[repeat 1000 times]

… and still press y on reflex …

How to install Cisco VPN client on Ubuntu Jaunty Jackalope and Karmic Koala 64 bit

Update 2011-05-09: There is a new patch that works (I still recommend the vpnc client instead of Cisco client). I’ve mirrored the patch to my server: fixes-2.6.38.patch. Please note that you should apply the patch against a vanilla vpnclient setup directory (no other patch applied).

cd vpnclient/setup/directory/
wget http://www.lamnk.com/download/fixes-2.6.38.patch
patch < ./fixes-2.6.38.patch
sudo ./vpn_install

Again, from the awesome tuxx-home.at forum.
Update 2011-05-08: Doesn't work for Natty Narwhal 11.04. There is currently no fix for this. You should use vpnc instead. It should be compatible with your VNP server, you just have to install vpnc using Synatics/apt-get and use pcf2vpnc convert your .pcf profile from Cisco client to vpnc .conf profile. Or install network-manager-vpnc-gnome package for a GUI client (doesn't have all capabilities of vpnc on command line).
Update 2010-10-31: Work for Maverick Meerkat 10.10 too
Update 2010-08-26: You can now install with this cisco vpn patch applied. It's all the old patches combined.

cd vpnclient/setup/directory/
wget http://www.lamnk.com/download/fixes.patch
patch < ./fixes.patch
sudo ./vpn_install

This patch is tested on Ubuntu Lucid Lynx 10.04 LTS on 32bit and 64bit.

Old post:
Cisco module again doesn't let us compile against the new kernel in Ubuntu 9.04 and 9.10 beta:

/home/lamnk/vpnclient/interceptor.c: In function ‘interceptor_init’:
/home/lamnk/vpnclient/interceptor.c:132: error: ‘struct net_device’ has no member named ‘hard_start_xmit’
/home/lamnk/vpnclient/interceptor.c:133: error: ‘struct net_device’ has no member named ‘get_stats’
/home/lamnk/vpnclient/interceptor.c:134: error: ‘struct net_device’ has no member named ‘do_ioctl’
/home/lamnk/vpnclient/interceptor.c: In function ‘add_netdev’:
/home/lamnk/vpnclient/interceptor.c:271: error: ‘struct net_device’ has no member named ‘hard_start_xmit’
/home/lamnk/vpnclient/interceptor.c:272: error: ‘struct net_device’ has no member named ‘hard_start_xmit’
/home/lamnk/vpnclient/interceptor.c: In function ‘remove_netdev’:
/home/lamnk/vpnclient/interceptor.c:294: error: ‘struct net_device’ has no member named ‘hard_start_xmit’
make[2]: *** [/home/lamnk/vpnclient/interceptor.o] Error 1
make[1]: *** [_module_/home/lamnk/vpnclient] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-2.6.31-1-generic'
make: *** [default] Error 2
Failed to make module "cisco_ipsec.ko".

Before installtion I assume that you have the latest version 4.8.02.0030 and the required packages for compiling ie gcc, libstdc++6 ... The kernel version should be from 2.6.30 to 2.6.32

  • Download the client and extract it
  • Go to vpnclient folder:
    cd vpnclient

  • Download patch file for 64 bit and apply it (users on 32bit systems can skip this step):

    wget http://lamnk.com/download/vpnclient-linux-4.8.02-64bit.patch

    patch < ./vpnclient-linux-4.8.02-64bit.patch

    sed -i 's/^CFLAGS/EXTRA_CFLAGS/' Makefile

  • Download patch file for newer kernel (2.6.30+) and apply it:

    wget http://lamnk.com/download/vpnclient-linux-2.6.31-final.diff

    patch < ./vpnclient-linux-2.6.31-final.diff

  • Next we must edit a kernel source file

    sudo sed -i 's/const\ struct\ net_device_ops\ \*netdev_ops;/struct\ net_device_ops\ \*netdev_ops;/' `find /usr/src -name netdevice.h`

    Yes, it is a one liner, you should copy & paste that command instead of typing ;) The command's translation into English: find the string const struct net_device_ops *netdev_ops; and change it to struct net_device_ops *netdev_ops; in the file locates at

    find /usr/src -name netdevice.h

  • And finally, install Cisco VPN Client:

    sudo ./vpn_install

The patch files are not from me. All credit goes to the people at tuxx-home.at forum

If you can't install or have a problem please leave a comment

Compile rtorrent on CentOS 64bit

Update 10.03.2011, 2 years later on a new Macbook: brew install rtorrent on Mac OS X (Snow Leopard 10.6.6) also falls for this error. The habit of writing work logs saves me a lot of time again :-)

I always fall for this error when compile rtorrent, so … :

Error:


checking for STUFF... configure: error: Package requirements (sigc++-2.0) were not met:

No package 'sigc++-2.0' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables STUFF_CFLAGS
and STUFF_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

Fix:

$ updatedb
$ locate pkgconfig | grep sigc++-2.0.pc

You will see something like /usr/lib/pkgconfig/sigc++-2.0.pc. If it is not there, then go install libsigc++ (it’s not in official CentOS repo).
Then define the PKG_CONFIG_PATH variable as the configure script suggests:

$ export PKG_CONFIG_PATH=/usr/lib/pkgconfig/

Run configure script for libtorrent again. --prefix= should be the same for libsigc++, libtorrent and rtorrent, otherwise they will complain ;)

./configure --prefix=/usr && make