Blog Moved!

This blog has officially migrated to!

Huzzah, new domain!


Vim Tip: Setting File Name in the Title Bar (Not the Status Bar)

When I first started using Vim in Ubuntu, I noticed that while editing a file, title bar of the terminal window would display something like this:

sampson-chen@ubuntu: ~/src/reviewboard/reviewboard/reviews/ui

which falls just short of being helpful because it omits the most important part: which file exactly is being edited. It is not realistic (and indeed wasteful of mental resources) to keep track of this information especially when often several files are open simultaneously across 5-6 terminal sessions. The problem is yet more pronounced when these files happen to reside in the same directory.

After a bit of digging, I found a solution. Add the following to your ~/.vimrc:

let &titlestring = expand("%:p")
if &term == "screen"
  set t_ts=^[k
  set t_fs=^[\
if &term == "screen" || &term == "xterm"
  set title

(Modified from the example at – To create ^[, which is escape, you need to enter CTRL+V <Esc>)

This gives you the full path in the title bar:


which worked well enough for about a week, until I came across a simpler (and better) solution. Add the following to your ~/.vimrc instead:

set title

And it will give you the file name first, then the prefixing path, and then “VIM”: (~/src/reviewboard/reviewboard/reviews/ui) - VIM

TL;DR – add “set title” to your ~/.vimrc

Misconceptions: Serialization vs. Serializability

I recently uncovered a blunder of mine: conflating serialization with serializability in common CS usage.

In short:

Serialization is the process of converting data structures / objects (e.g. in memory) into a format suitable for storage or transmission, such that it can be reconstructed later (e.g. Converting each node from a doubly-linked list in memory into JSON, where each serialized object has URI pointers identifying who its neighbours are, or where it belongs in the sequence.)

Serializability has to do with DBMS concurrency control: whether a series of concurrent transactions can be ordered and executed in parallel such that the end result is guaranteed to be the same as if they were executed in sequence.

Also, the definition of Serialize in common English usage:

1. Publish or broadcast (a story or play) in regular installments.

2. Arrange (something) in a series

The idea of serialization wasn’t new to me, but it’s good to finally put a name to it.

Sampson’s Notes, Flashcards, and other Academia Stuff from CS at UWaterloo

This post will be a mix of links to notes and flashcards, among other things. I’ll add new links to here periodically as I find and backdate through archives, or as I make new ones.

===== Flashcards =====

I find self / peer-quizzing with flash cards & doing sample exams to be the most effective ways to study. Memory retrieval exercises work much better than just reading material over and over (not much retention that way).

How to study the decks on QuizLet:

  1. Uncheck “Both Sides”
  2. Check “Term First”
  3. Click to flip the card
  4. Use left / right arrow keys to move between cards

Alternatively, you can download these study decks from with iOS apps, just search for “CS 458 UWaterloo”, I found it helpful to quiz myself during commute / in between classes:*/id403199818?mt=8

===== CS 458 – Computer Security and Privacy =====

CS 458 – Up to Midterm

CS 458 – After Midterm to Final Exam

===== CS 349 – User Interface ===== 

CS 349 – Midterm to Final Exam

===== CS 446 – Software Design & Architecture ====

(These are arranged by slide numbers, but the course content vary from prof to prof:)

(If you really wanted the flashcards for slides #1-3: the online version got deleted – I can upload a local copy, just ask)

===== PHIL 215 – Professional and Business Ethics ====

Link to all of the lecture notes on Google Docs

Flashcards – Midterm

Three Shortcuts to Quickly Change Directories in Linux

While working on projects in Linux, I often have to navigate through long directory paths with cd to arrive at the working directory where the most-accessed files are kept. For example:

slc@linux:~$ cd SmileForward/smileforward-backend/sfsite/smileforward/

Smart auto-complete with tab helps, but it’s still rather inefficient, especially when you have to repeat this sequence across multiple terminals (and again every time you restart the OS).

My initial reaction was to write a script with a short name:

slc@linux:~$ vim sf


cd SmileForward/smileforward-backend/sfsite/smileforward/

But this apparently doesn’t work, as the shell stays at the same directory after executing the script:

slc@linux:~$ chmod +x sf
slc@linux:~$ ./sf

After a bit of digging, I discover the problem:

Each time a script is run with dot slash “./”, a brand-new subshell is spawned from the current shell to run whatever is in the script, and then it terminates without affecting the parent shell. So the new shell does change to the specified directory, but then it terminates and control is returned to the parent shell.

To remedy this, here are three different shortcuts:

1. Run the script with . or source:

slc@linux:~$ . sf
slc@linux:~/SmileForward/smileforward-backend/sfsite/smileforward$ cd
slc@linux:~$ source sf

Running a script with . or source executes it within the current shell (without spawning a subshell).

2. Name the shortcut as an environment variable and save it in ~/.bashrc (so bash shell loads it every time a new bash shell spawns):

slc@linux:~$ vim ~/.bashrc


export sf=~/SmileForward/smileforward-backend/sfsite/smileforward
slc@linux:~$ cd $sf

3. Make an alias for the cd script (best solution)

slc@linux:~$ vim ~/.bashrc


# run the command closed by single quotes when sf is encountered
alias sf='cd ~/SmileForward/smileforward-backend/sfsite/smileforward' 
slc@linux:~$ sf

Alternatively, the alias can be:


# Run the sf script from option 1
alias sf='. ~/sf'


# cd to the sf environment variable from option 2
alias sf='cd $sf'

Hopefully this saves you some time when navigating between commonly visited directories in Linux.

Another very popular solution for changing directories is z ( I’m new to z, so it’s left up to the reader to explore.

(P.S. you can also symlink to the directory: ~/SmileForward/smileforward-backend/sfsite/smileforward/, but this leads to a less versatile result as there’s no easy way to move up to a parent directory)