Random Bits

Technical Log from Didik Setiawan

Convert Text to Pdf on Linux

Background: failed to build linux kernel documentation (still too lazy to solve problems).
Goal: generate pdf files of linux documentation, because I have reading problem when using text files. Text files look ugly when I open using my reader (Android).

Install needed packages.

$ sudo apt-get install enscript ps2pdf

Do this simple tricks.

$ cd Documentation/
$ for i in `ls -p | grep -v /` ; do ; enscript -p$i.ps $i ; done
$ for i in `ls *.ps` ; do ; ps2pdf $i ; done

Now I have pdf files of all the text files.
It still have a problem, it just convert files on the same directory. So other files under this directory must be processed separately, which mean I must move to each directory.

My Vim Configuration

This is my Vim configuration a.k.a .vimrc. You can download the file from here. Feel free to use and customize.

Below are some description of its contents:

Use vim settings instead of vi

set nocompatible

No backup or swap

set nobackup nowritebackup noswapfile autoread

Enable per-directory .vimrc files

set exrc

Don’t unload buffer when switching away

set hidden

Allow per-file settings via modeline

set modeline

Disable unsafe commands in local .vimrc files

set secure

Saving and encoding

set encoding=utf-8 fileencoding=utf-8 termencoding=utf-8

Command completion

set wildmenu

Allow backspacing over everything in insert mode

set backspace=indent,eol,start

Display status line which contains current mode, file name, file status, ruler, etc.

set laststatus=2

Always set autoindenting on

set autoindent

Display incomplete commands

set showcmd

Keep upto 50 lines of command line history

set history=50

Show a vertical line at the 79th character

set textwidth=80

Highlight column after ‘textwidth’

set colorcolumn=+1

Switch syntax highlighting on

syntax on

Switch highlighting on the last used search pattern

set hlsearch incsearch ignorecase smartcase

Don’t hide the mouse cursor while typing

set nomousehide

Right-click pops up contect menu

set mousemodel=popup

Show cursor position in status bar

set ruler

Show line numbers on left

set number

Disable code folding

set nofoldenable

Scroll the window so we can always see 10 lines around the cursor

set scrolloff=10

Kernel coding style

set tabstop=8                                           
set softtabstop=8                                       
set shiftwidth=8                                        
set noexpandtab

Enable file type detection

filetype plugin indent on

Shortcut to search visually selected text

vnoremap // y/<C-R>"<CR>

Check if running on gvim

if has("gui_running")

Set terminal color to 256

set t_Co=256

Check if using Windows

if has("win32") || has("win16")

Set Ubuntu Mono font with size 11

set guifont=Ubuntu\ Mono:h11

Use solarized colorscheme

colorscheme solarized

Set the background to dark color

set background=dark

Highlight the current line

set cursorline

Use letter as the print output format

set printoptions=paper:letter

I use Ubuntu font which can be download from font.ubuntu.com. To enable solarized colorscheme, download file solarized.vim from https://github.com/altercation/vim-colors-solarized/. If you want to look my personal vim configuration, you can find it here.

I use this configuration in my Linux workstation and server. I use exclusively for editing linux kernel and other open source projects. For daily programming use, you can change the value of tabstop, softtabstop and shiftwidth.
Happy Vimming!

Vim Quick Reference

For unfimiliar user, vim is a little bit confusing at first. But, after you try it several times and configure properly, you will found this text editor is very powerful.
Here I will note several subject how to use vim, because sometimes navigate to vim help is quite difficult.

Vim is modal editor which means you use different mode to edit text. Some important mode you will use very often are:

  • Normal Mode

You can enter any command using : or search using / and ?. Press Esc to enter this mode.

  • Insert Mode

Text you type is inserted into the buffer. Press i to enter this mode.

  • Visual Mode

In this mode, you can select the text we want in order to copy, cut or delete. Press v to enter this mode. The cursor position will be starting point to your selection.


You can move through the buffer with the following key:

Move left h
Move right l
Move up k
Move down j

Using this key will make your navigation faster than using arrow keys or mouse.

Move one word w
Move one word backwards b
Move to end of line $
Move to beginning of line 0
Insert text i
Insert text at the end of line A
Insert text at the beginning of line I
Insert text above line O
Insert text below line o
Replace one character r
Replace character consecutively R (enter “replace mode”)

Page navigation:

Move page down ctrl + f
Move page up ctrl + b
Move page half down ctrl + d
Move page half up ctrl + u
Move top gg
Move bottom G

Navigate through command history q: Navigate through search history q/ Then you can select command or search result with navigation key. To execute command, press Enter.

Open and Save File

Open file :e filename
Save file :w
Saveas file :w filename
Quit :q
Quit without save:q!
Save file and quit:wq

Undo and Redo

Undo u
Redo ctrl + r

Visual Selection

Use v on text you want to select. You will enter visual mode. Navigate using hjkl key. Then we can do other action such as copy, cut or delete.

Copy and Paste Text

After you select a text, you can do following action:

Copy y
Cut/Delete d or x
Copy entire line yy
Cut entire line dd
Paste p

Search and Replace Text

Find text /query
Find text upwards ?query
Navigate between search results n to move forward and N to move backwards

Find text using visually selected text, firstly add this line to vimrc file

vnoremap // y/<C-R>"<CR>

then select text in visual mode and press //

Replace text :%s/old/new/g
Replace all :%s/old/new/gc

Word Completion

You can autocomplete text with several method to get different result:

Search text before cursor ctrl + p
Search text after cursor ctrl + n
Search for filename complete with its path ctrl + x ctrl + f

Multi Window Editing

Open new window :new
Open new vertical window :vnew
Move through window ctrl + ww
Swap window position ctrl + wr

Compare Buffer

If you have two split windows containing buffers that you want to compare, then you can diff them by running :windo diffthis
You can turn diff mode off just as easily, by running :windo diffoff

That’s how I use vim in daily life. For my personal preference, I have modified my vimrc which you can find here. Thanks for reading.

Octopress Setup and Deployment

I will explain how to setup a new blog using octopress, deploy it on github and contribute from other place. Let’s check this out.

First Time Setup


  • Install Git and Node.js

On debian system, use apt-get.

$ sudo apt-get install git
$ sudo apt-get install nodejs
  • Install Ruby

We must use version 1.9.3 or higher. To ensure we fulfill this requirement, I prefer to install ruby from source. Download from Ruby official site. The installation process is quite common.

$ tar zxf ruby-2.3.1.tar.gz 
$ cd ruby-2.3.1/
$ ./configure
$ sudo make && make install
  • Install ExecJS

To run JavaScript code from Ruby.

$ sudo gem install execjs
  • Configure bundle

Another octopress dependency.

$ sudo gem install bundler

After all needed requirements fulfilled, then grab the octopress source code.

$ git clone git://github.com/imathis/octopress.git octopress
$ cd octopress

One more dependency:

$ bundle install

Then install octopress default theme.

$ rake install

Setup process is finished. We can now start to blog using rake newpost[“title”], customize _config.yml, add some pages, customize 404 not found page, using custom domain name and so on.

Deploy on Github

There are some way to deploy octopress, either using rsync or git. In this post, I will explain how to deploy octopress on Github. Create a new Github repository and name the repository with the format username.github.io, where username is your GitHub username or organization name.

Github Pages for users and organizations uses the master branch like the public directory on a web server, serving up the files at your Pages url http://username.github.io. As a result, we will to work on the source for our blog in the source branch and commit the generated content to the master branch. Octopress has a configuration task that helps us set all this up.

$ rake setup_github_pages

The rake task will ask for a URL of the Github repo. Copy the SSH or HTTPS URL from our newly created repository (e.g. [email protected]:username/username.github.io.git) and paste it in as a response.

This will:

  • Ask for and store our Github Pages repository url
  • Rename the remote pointing to imathis/octopress from ‘origin’ to ‘octopress’
  • Add our Github Pages repository as the default origin remote
  • Switch the active branch from master to source
  • Configure our blog’s url according to your repository
  • Setup a master branch in the _deploy directory for deployment

Next run:

$ rake generate
$ rake deploy

This will generate our blog, copy the generated files into _deploy/, add them to git, commit and push them up to the master branch.

Don’t forget to commit the source of our blog.

$ git add .
$ git commit -m 'our message'
$ git push origin source

With new repositories, Github sets the default branch based on the branch we push first, and it looks there for the generated site content. If we’re having trouble getting Github to publish our site, go to the admin panel for our repository and make sure that the master branch is the default branch.

Contribute from Other Place

Sometimes we need to develop our octopress site in other place than we currently in. To do that, we will use the benefit of git.
First, we need to get our site copy:

$ git clone [email protected]:username/username.github.io.git
$ cd username.github.io

Switch to source branch

$ git checkout source

Then do all change on our source, after that run “rake generate” or “rake preview” to compile our source onto public directory. Everything seems to be okay until we need to upload to github.

$ rake deploy
## Deploying branch to Github Pages 
## Pulling any updates from Github Pages 
cd _deploy
rake aborted!
Errno::ENOENT: No such file or directory @ dir_chdir - _deploy
/home/didik/octopress/Rakefile:255:in `block in <top (required)>'
/home/didik/octopress/Rakefile:227:in `block in <top (required)>'
Tasks: TOP => deploy
(See full trace by running task with --trace)

Oops, it’s look like we miss something. We have to make a new _deploy directory and add git initialization to it.

$ mkdir _deploy
$ cd _deploy
$ git init
$ git remote add origin [email protected]:username/username.github.io.git
$ git pull origin master
$ cd ..

That’s all. Now, we can upload using rake deploy as usual.
Until next time.

My Blog

As a person who use internet in daily basis, I think something personal like a domain name is essential to have. But, there is no good personal domain name available for free. Fortunately, the price to “borrow” a domain name from the registrar is fairly affordable. So, without even thinking more about price to pay, I decided that what I invested in this thing will someday get useful for everyone, in anyway.
After I “reserved” one domain name, I need to associate it with other service. The two things that important to be setting up immediately are blog and email.
Blog is like my “broadcasting center”. I store my notes, my journals there. Everyone is welcome to visit there, and I hope it can help someone to answer their question someday. Email become my virtual identity. I use it to register to many service on the internet. Especially with my own custom domain name, I can make my blog and email look more personally. Here I explain how I build my blog step by step.

Domain Name

I register my domain from a web hosting provider. I just pay for the domain name, not the hosting service.
About what provider I currently use, it can be found using a domain tool easily.


In order to build my infrastructure, I need to have a server, dedicated internet or static IP address to run the software up. But I don’t have any of them, so I just use free service from external providers. There is a lot of providers who can give us some space to host our web and email.
In early time I touch with internet, I did use some blogging framework to run my blog. I ever use Blogger, Joomla, Drupal and Wordpress. I spend a long time with Wordpress. But, due to personal favor, finally I switch to Octopress.

Why Octopress? Because that is simple. It has beautiful design, while easy to use. I can create post directly from Vim on my Linux console. It can be updated using git, so I can feel the sysadmin way to write a post. It use a simplify html-like syntax, markdown. I can host my blog together with my application repository in Github. You can check this article for more details. With this Octopress take control my way to blog, I can focus on contents that I want to share rather than have to be confused to setup and design my blog.


For security purpose, I use free ssl service from CloudFlare. The setup process is fairly easy. The requirements for its service is just a domain name with top level domain. I just need to set my DNS configuration to point CloudFlare DNS. Additionally, there is a feature so I can force my blog visitor to use https in order to see the ssl sign.


Rather than using well-known free email service, I need to host my own email because I want to use my own domain name. Fortunately, there is email provider that provide free email service using custom domain, thanks to Zoho Mail. Even with free service, I can use my own domain name.

That’s all about my blog. I hope it all will be useful. Thanks for reading.