Random Bits

Technical Log from Didik Setiawan

Preparing GSoC

GSoC (Google Summer of Code), a program where university students spend their 3 month summer break coding on an open source project.

That time finally comes. After almost one year I have been lurking, day dreaming, it’s time to decide whether I will participate or not. It’s not easy to find organization who fit with who I am. But anyway, this year, I will try.
Despite administrative prerequisite, such as proof of enrollment, there are some technical stuff involving coding activities we need to do, which is fun. This is a list of what I’ve done so far in order to be considered as good candidate:

Pick a project with programming language that I passionate about

There is a word “code” in Google Summer of Code, meaning programming will be my main activity in this program. So, I must find which project that has programming language, that I familiar with. This is to avoid, I will stuck about the tasks that will assigned to me as a program applicant.
Actually, it can be done even long ago before the program being announced. I can look at the GSoC archive. But, sometimes term will change as the organization announced. Some organization will participate again, while others not. So, for me it better to prepare after the program announced officially.
From there, I can see which project fit with my programming language, one that I love. So, after some effort of filtering and analyzing, then I choose an appropriate project, I will not find a big technical barrier to pass this program.

Pick a project that fit with my knowledge

This means, I must look at the project task. With given time frame, which about just 3 month, does it sound realistic that I will finish my task? That it’s, be realistic is the key. Measure the difficulty of the task. When I face something very unfamiliar and need more time to learn, I prefer to skip this. Because I don’t want to spend my time in things that I less understand.
For example, this year, I choose project from GNU Wget that use C as their programming language base, which currently I am familiar with. And for the task, I pick idea of “Improvement of test suite using Libmicrohttpd”.

Get enganged with community

After I found the project that I want to apply, I must introduce myself to the community. This is important step I must do. Because without it, mentor cannot help me when I face difficulty.
Find the place where they collaborate. There are some choice like mailing list, slack, gitter, irc, etc. GNU Wget use mailing list as they medium to communicate between developer. I send welcome message there, and replied kindly by other members. Follow their rules. Basically, there are some rules to be obeyed: - Use plain English. GSoC is global program and use English as it language for communication. So, I need to use English in my conversation. - Not to send message directly to the mentor or other person in the community. This is considered to be rude. Instead, I will use mailing list if I need to send a message. - Avoid top post when I reply an email.

Learn their environment, workflow and code base

After I “Say Hi!” to the organization, now it’s time to dive into their code. Find the repository. In Wget, their main repositories are hosted in Savannah, Github and Gitlab. So, I clone the repo and then build the software from source.
I have successfully built Wget from source. Then I try to trace what the program do using gdb, to take a look what is going on inside its process.
I familiarize my self with git, because Wget use git as its version control system. Also the project uses Github to consolidate patches, open issue, write wiki, etc. I try to hanging around on there. It fancy design keep me comfort with environment and workflow of the project.

Submit a patch, event with a trivial one

This patching section required quite technical skill. For newcomer like me, I feel a bit confuse about what patch I can submit. Then, with guide from my mentor, I was given an idea what simple task can be submitted. I pick an easy one. A testing unit. Because, he mention, that Wget unit testing is still far from perfect. I will take it for my chance. I try to add a function to reach more coverage in the project unit test.
In order to merged into upstream, I need to make pull request on that project. To be honest, it is my first time pull request in a real open source project. Of course my patch will not merged automatically to the upstream. Mentor and the community members will review first before it can be accepted. And after several step, edit code, re-push commit with guide from my mentor and other contributors that help me, finally my patch get merged on the upstream. It’s a nice feeling for a rookie developer can have.

Write a good proposal

After all, to be accepted in the GSoC program itself, I need to upload a proposal. The proposal must be good enough to be considered accepted as GSoC candidate. I pick the idea from list project that mentioned in project website. I create a draft from this and share to other members. I receive a lot of feedback. Thanks for who was concerned, so I can make improvements to my proposal. After I feel it ready, I upload my final proposal to GSoC official.

That was my short list for what I do in this GSoC. And because the time between the date of proposal submit and the announcement of accepted applicant is a month long, I will use it to get more familiar with project code base.

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.

Navigation

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

Prerequisite:

  • 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.