Lazy Hacker Babble

Just some random babblings from a lazy hacker…

VIM copy/paste/navigation in Insert mode.

Posted by hsin on March 6th, 2010

A few months ago, I made a commitment to learn the VIM editor. I was primarily an EMACS user, but I wanted to become proficient with VIM since EMACS is not always available I found myself too slow when using VIM. To learn it, I pretty much told myself that I’m not allowed to use any other editor while programming and just immerse myself in VIM. For the most part, it worked. I’ve been using VIM daily for about 4 months now and I’ve gotten used to it… mostly.

I can see the reasoning and benefits of having a separate mode for inserting text, but for me it isn’t as intuitive to use. Maybe my fingers are just to conditioned to be able to write chunks of text and still be able to copy, paste, etc. The way I work, I edit text while jumping around a lot and that mode leads to a lot of hitting ESC to the point where I’m using more key strokes then on EMACS (where the criticism is that it requires mult-combos to do an action such as ‘C-x C-c’). So I found myself editing text, ESC, move around, ‘i’, edit text. For the most part, I was willing to live with that, but the breaking point is that I just kept making mistakes editing. I’d hit ‘i’ when I’m already in edit mode or be typing outside of edit mode leading to typos and jumping to another part of the screen. I figure that 4 months is enough and while I’ll stay with VIM, I’ll likely be in Insert mode a lot and so I want to reduce bouncing back-and-forth between modes.

I made the following changes to my .vimrc to allow me to do things like move around (without using the arrow keys) and copy/paste without leaving Insert mode:

" Key mappings in INSERT mode
" Tired of lifting hand to hit ESC or having ctrl-[
imap ;; <Esc>

" navigate without lifting hand off of keys
imap <C-h> <Left>
imap <C-j> <Down>
imap <C-k> <Up>
imap <C-l> <Right>

" paste in Insert Mode
imap <C-v> <C-o><S-p>

" undo
imap <C-u> <C-o>u

" Select text
imap <C-c> <C-o>vgG
 

Posted in Main, Programming | No Comments »

If I had some carpentry skills to build my own desk.

Posted by hsin on February 22nd, 2010

I’d want to build this desk.

Posted in Main | No Comments »

WordPress for Android

Posted by hsin on February 3rd, 2010

Another app I’ve been waiting for has been released. WordPress for Android is now available. Each day takes me further from the iPhone.

qr code

Posted in Main | No Comments »

Chrome OSX with Bookmark Manager

Posted by hsin on January 15th, 2010

The latest dev channel build of Google Chrome now have a basic bookmark manager and cookie manager.

With a bookmark manager, even though it is very basic, Chrome for OS X has the basic set of features that I feel makes up a browser and might can make Chrome my default browser on OS X soon.

Posted in Google, OSX, Software | No Comments »

Android 2.1 SDK released

Posted by hsin on January 12th, 2010

For those who has been asking for the 2.1 SDK since the Nexus One launch, the new SDK can be downloaded here: http://developer.android.com/sdk/android-2.1.html

Posted in Google, Programming | No Comments »

Google APIs

Posted by hsin on January 5th, 2010

“Eat your own dog food” is not an uncommon term in Silicon Valley. It means for a company to use the product they built themselves. If a company offers an email product to customers then they should also be using that same email product. It’s not always easy to eat one’s own dog food especially when that dog food provide a critical business functionality or is fairly new. Email, for example, has become vital for companies and they depend on it to be scalable, stable and reliable, but if you’re eating your own dog food you might be using the pre-production version which might not be 100% stable or it’s missing some functionality and which you need to build yourself. Because of this, even though many tech company talk about eating their own dog food, but don’t really pull it off.

I find Google to be very serious about eating their own dog food. Everything released to the public is also used internally and this includes their APIs. Often companies release APIs but don’t use them internally because they have direct access to the underlying technologies. Google does use their own APIs and during my first two months here, I’ve been learning a lot of the APIs in order to do my work. There are some amazing stuff out there and they are all listed at code.google.com.

Specifically, I’ve been learning the Google Data APIs. There is an amazing amount of access to APIs to allow developers to build sophisticated applications so I encourage everyone to try them out!

Posted in Google, Programming | No Comments »

Haagen-Dazs Green Tea Ice Cream!!!

Posted by hsin on January 1st, 2010

10 years ago my wife and I took a vacation to Japan where we found one of the best tasting ice creams we ever had. It was the Haagen-Dazs green tea ice cream. When we came back to the States, we tried looking for it, but it seems that it wasn’t a flavor that Haagen-Dazs sold in the US. We tried other brands’ green tea flavors, but nothing really matched what we had in Japan.

Today, after 10 years of searching, we found this at our local grocery store:

green tea ice cream

Yay!!!

Posted in Main | 1 Comment »

2009 OS of the Year… LINUX!

Posted by hsin on January 1st, 2010

Looking back on my computer usage this past year, I realized that I’ve stopped using Windows. For the first time, I don’t even have a Windows computer at work. Having mostly used DOS/Windows (usually along side a linux server) for so long I didn’t expect that my usage to stop so quickly, but before I knew it I was doing everything I needed to do on another OS. One of the key changes that I made that contributed to being able to stop using Windows is that I stopped PC gaming. However, I would have expected that OSX would have been the primary OS following Windows (especially since I replaced my main Windows machines with a MBP), but the work horse OS that I used the most turned out to be Linux. Where consumer apps on Linux used to lag behind Windows and OSX, developers are now building them for Linux including media players (VLC) and programs like Picasa and Handbrake with the arcane interfaces that are often associated with the Unix world. I believe having these types of user accessible applications will drive Linux more then just having windows/osx-like window managers.

Posted in Linux, OSX, Software, Windows | No Comments »

Approaching the End of the Decade

Posted by hsin on December 30th, 2009

Did 10 years really just went by?!? I still remember when we were gearing up to tackle Y2K and we’re now approaching the end of the first decade of the millennium.

Posted in Main | No Comments »

Restoring RPM and YUM on Fedora after an accidental yum remove rpm

Posted by hsin on December 28th, 2009

By default there is nothing that prevents an user from accidentally removing both yum and rpm from a Fedora system and once removed it is very painful to try to put them back. If only yum was removed it would be a little easier to restore. Yum can be reinstalled through rpm using the yum-*.rpm package downloaded from Fedora or the install disc. Without RPM, it’s like a chicken-and-the-egg problem. The packages from Fedora and install discs (including the rpm package itself) are .rpm files and needs rpm to install.

Today I found myself in the situation where both YUM and RPM got removed by accident. I was following Fedora’s instructions on finding and removing orphaned packages after upgrading and had yum remove some Fedora 11 packages that was left over. Being distracted by other things at the time, I noticed too late that removing those F11 orphaned packages also led yum to remove a bunch of F12 packages including rpm and yum.

So, what does one do in this situation besides “backup and reinstall? which I wanted to avoid if at all possible. It took me awhile to figure out but I was get rpm back on my system and restore it to its earlier state. Here are the steps I took.

My first inclination was to try to compile RPM. However, this was a FAIL since it required additional packages that I didn’t have installed and I didn’t have a package management system… Instead, I downloaded the rpm-*.rpm package from Fedora and was hoping to extract the files so I can use them to reinstall rpm and yum. To extract files out of an RPM package requires… rpm! Oh, the irony. There is a rpm2cpio program that will do that but that is available in . . . the rpm-build-*.rpm package! Fortunately, there are a lot of scripts available that will do it including some shell scripts. The Fedora RPM docs included some scripts and I downloaded the bash script version but it didn’t work. After a little more digging, I found out that Fedora changed the compression scheme it uses in F12 from gzip to xz, so I modified the shell script as follows:

#!/bin/sh

pkg=$1
if [ "$pkg" = "" -o ! -e "$pkg" ]; then
   echo "no package supplied" 1>&2
   exit 1
fi
leadsize=96
o=`expr $leadsize + 8`
set `od -j $o -N 8 -t u1 $pkg`
il=`expr 256 \* \( 256 \* \( 256 \* $2 + $3 \) + $4 \) + $5`
dl=`expr 256 \* \( 256 \* \( 256 \* $6 + $7 \) + $8 \) + $9`
# echo "sig il: $il dl: $dl"
sigsize=`expr 8 + 16 \* $il + $dl`
o=`expr $o + $sigsize + \( 8 – \( $sigsize \% 8 \) \) \% 8 + 8`
set `od -j $o -N 8 -t u1 $pkg`
il=`expr 256 \* \( 256 \* \( 256 \* $2 + $3 \) + $4 \) + $5`
dl=`expr 256 \* \( 256 \* \( 256 \* $6 + $7 \) + $8 \) + $9`
# echo "hdr il: $il dl: $dl"
hdrsize=`expr 8 + 16 \* $il + $dl`
o=`expr $o + $hdrsize`
dd if=$pkg ibs=$o skip=1 2>/dev/null | xz -d
 

With this script, I extracted the rpm (rpm, rpm-build, rpm-libs, rpm-devel, rpm-python) files to a temp directory and install the files manually:

rpm2cpio.sh rpm-*.rpm | cpio -d -i
tar cf – ./usr ./etc ./bin ./var | (cd /; tar xvf -)
 

This installs the files onto the system but doesn’t update the rpm databases, so I did a ‘rpm -ivh rpm*.rpm’ in addition to the dependent packages they needed.

With RPM installed, I was able to install YUM . I had kept a list of all the files that got removed earlier so I had yum reinstall all those packages and my system is now restored.

Posted in Linux | No Comments »