Tuesday, July 29, 2014



ARGV: Argument Vector
c(): combine ? not sure

Wednesday, July 9, 2014

Useful Mac Terminal Commands

Here are some terminal commands which I wish I knew earlier.

pushd and popd are used to store and change directories.
A trick is by using pushd without any parameter, you can
move back and forth between two folders.

a short example
pushd ~/data
pushd ~/analysis
pushd # now the directory is changed to ~/data
pushd # now the directory is changed to ~/analysis

2.clean the screen
This is same as clear command but I prefer to type 2 keystrokes vs 6 keystrokes
In addition, it also works in the console of Rstudio where clear does not.

control + L 

3.screen for ssh connection
When executing a program in a remote computer by ssh,
if the connection lost, the execution will be aborted,
screen command can solve this perfectly.

4.alias for frequently used commands
alias ep="nano ~/.bash_profile"
alias sp="source ~/.bash_profile"
alias cdr="cd ~/Documents/repo/"
alias cdd="cd ~/Dropbox/"
alias ll="ls -Gl"
alias play="~/apps/spotify play"
alias pause="~/apps/spotify pause"
alias n="~/apps/spotify next"
alias p="~/apps/spotify prev"

5.move to the beginning or the end of the line
Control + a # to the beginning
Control + e # to the end 

6.Execute last command as root - sudo !!
A short example - forget to add sudo when install ruby gem
$ gem install gnuplot
Fetching: gnuplot-2.6.2.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
        You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

Use sudo !! as a shortcut for sudo gem install gnuplot

$ sudo !!
sudo gem install gnuplot
Fetching: gnuplot-2.6.2.gem (100%)
Successfully installed gnuplot-2.6.2
Parsing documentation for gnuplot-2.6.2
Installing ri documentation for gnuplot-2.6.2

6.Open current directory in Finder from command line

open .

7.Edit bash_profile to enhance the functionality of shell

# change the style and color of the prompt 
PS1='\e[0;32m\u: \e[0;31m\w \e[0;30m'

# add autocomplete for git
if [ -f ~/.git-completion.bash ]; then
   source ~/.git-completion.bash

8.Name the tab

# add a function to bash_profile 
# nt for nametab
function nt {
        echo -ne "\033]1;$1\007"

Monday, July 7, 2014


Personal Blogs

TextMate Shortcuts

It is super handy to deal with some routine yet trivial tasks with a few TextMate tricks.
Here I list some shortcuts which I found most useful.

  • Column wise selection
    Option + Left Drag with mouse
    This allows selection and direct editing on vertical columns.

  • Auto completion of the code
    In many IDEs, Tab is used for auto completion, similarly you can use Esc key to do this.

  • Find and Replace in Project Folder
    Command + Shift + F
    This allows quick replace in a bunch of files inside the same project folder.

  • Selection of whole line
    Control + Command + left Arrow or Right Arrow
    Shift + Command + L

  • Change Indent
    Command + [ or ]
    This is very useful for Python when there is a block of code need to be indented.

  • Comment current line
    Command + /
    If you do Command + / two times, it will uncomment the line. You can also first selected the code block and then comment all together.

  • clip board history viewer
    Control + Option + Command + v

  • Duplicate current line
    Control + Shift + d

  • Insert Comment Banner
    Control + Shift + b

  • Open Home directory in sidebar
    Shift + Command + h

  • Insert Burdle Item
    Control + Command + t

  • I did a google search during the writing and found a number of great posts and resources:
    Essential TextMate Shortcuts, Tips and Techniques
    TextMate shortcuts you should be using
    PDF version of the TextMate cheat Sheet.