This blog has officially migrated to http://sampsonchen.com/blog/!
Huzzah, new domain!
This blog has officially migrated to http://sampsonchen.com/blog/!
Huzzah, new domain!
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=^[\ endif if &term == "screen" || &term == "xterm" set title endif
(Modified from the example at http://vim.wikia.com/wiki/Automatically_set_screen_title – To create ^[, which is escape, you need to enter CTRL+V <Esc>)
This gives you the full path in the title bar:
/home/sampson-chen/src/reviewboard/reviewboard/reviews/ui
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”:
base.py (~/src/reviewboard/reviewboard/reviews/ui) - VIM
TL;DR – add “set title” to your ~/.vimrc
Google search result derped grammar just now.
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.
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:
Alternatively, you can download these study decks from QuizLet.com with iOS apps, just search for “CS 458 UWaterloo”, I found it helpful to quiz myself during commute / in between classes:
http://itunes.apple.com/us/app/flashcards*/id403199818?mt=8
http://itunes.apple.com/us/app/flashcards+/id408490162?mt=8
===== CS 458 – Computer Security and Privacy =====
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:)
http://quizlet.com/12736879/cs-446-lecture-notes-4-5-flash-cards/
http://quizlet.com/12994648/cs-446-lecture-notes-6-software-design-patterns-part-1-flash-cards/
http://quizlet.com/12995256/cs-446-lecture-notes-7-software-design-patterns-part-2-flash-cards/
http://quizlet.com/12997661/cs-446-lecture-notes-8-refactoring-detailed-design-flash-cards/
http://quizlet.com/12994479/cs-446-lecture-notes-9-software-design-metrics-flash-cards/
(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 ====
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
~/sf:
#!/bin/bash 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 slc@linux:~$
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$ slc@linux:~/SmileForward/smileforward-backend/sfsite/smileforward$ cd slc@linux:~$ source sf slc@linux:~/SmileForward/smileforward-backend/sfsite/smileforward$
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
~/.bashrc
export sf=~/SmileForward/smileforward-backend/sfsite/smileforward slc@linux:~$ cd $sf slc@linux:~/SmileForward/smileforward-backend/sfsite/smileforward$
3. Make an alias for the cd script (best solution)
slc@linux:~$ vim ~/.bashrc
~/.bashrc
# run the command closed by single quotes when sf is encountered alias sf='cd ~/SmileForward/smileforward-backend/sfsite/smileforward' slc@linux:~$ sf slc@linux:~/SmileForward/smileforward-backend/sfsite/smileforward$
Alternatively, the alias can be:
~/.bashrc
# Run the sf script from option 1 alias sf='. ~/sf'
~/.bashrc
# 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 (https://github.com/rupa/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)
Moved! This post has “officially” migrated to a new place.
Skip the bloated installs of software for downloading embedded videos (or their equivalency in outdated scripts and chrome extensions). After 30 minutes of Googling for a way to download flash videos from websites and finding no good solutions for Linux specifically*, I hacked for a more direct route:
1. Open a new tab and go to chrome://cache/ in Chrome
2. Open another tab and go to the video page (e.g. http://vimeo.com/47875656)
3. Press the Play button on the embedded video player
4. Once the video begins playing, return to the chrome cache tab and refresh the page
5. Usually the 1st URL (or near the very top) will be something that resembles a static resource URI (often with session keys). e.g., in my case now for the above Terry Crews video it’s the following:
http://av.vimeo.com/60205/750/113468584.mp4?aksessionid=1dc997a818e526595efa4434bb621ece&token=1346991143_843b2008a3b05ff62e53b7da504cb4bf |
6. Copy that URL.
7. Go to terminal and do:
$ wget "paste_url_from_step_5_here" video_name_here_01
(Be sure to enclose the URL with quotes.)
Notes:
– * There were a number of solutions still working for Windows, such as real player extension, orbit, etc. Alas, as far as I could tell there is no recent apps for Linux. (Let me know if you find a stable one or faster method)
– There were a few chrome extensions, but all terribly outdated. There were also a few greasemonkey scripts for Firefox that I didn’t get to test.
– Chrome used to store all temp files directly in /tmp/, then it moved to home/[user_name]/.cache/…, and now it stores cached files with SQLite. (If you know a quick solution to pull cached files out of that DB, do share.)
Starting a new blog here at WordPress to jot down new things I learn in software development, technology, and science.
Hopefully I’ll update it more than my personal blog: http://slchen-life-in-general.blogspot.ca/