This post is about what I've being learning since I caught programming fever. The main part is written in English.
若干年前，我写过一篇文章：提高生活幸福感的方法若干 | Scarlett's Blog。虽然在现在看来，那篇文章实在是很可（幼）爱（稚），但是，现在我又要写一篇类似的文章了。。。这次的主题是solely关于tech的。
OS X: Everthing is about productivity
我在2013年开始使用Macbook Pro。在一开始，我就被OS X系统迷住了，一切都比Windows更美、更简洁、更流畅、更intuitive。但那时还是我跟它的蜜月期，之后就慢慢习惯了。但最近，因为开始学习编程，做了一些新的task，我必须得说，我重新迷上了OS X。
People! Please use Keynote and Pages instead of Powerpoint and Word! They are far more stylishly designed and better integrated with other softwares on Mac.
I first considered switching into the native Apple apps because the Microsoft Office suite runs intolerably slowly on my computer. Once I started working on the Apple alternatives, I fell in love with them. One example is the practical "Styles" option, which enables the quick and perfect formatting of texts, paragraphs, shapes, bullets and lists. It's also highly easy to arrange the size and position of objects, both by editting them with your mouse and by specifying the coordinates.
I started to frequently use the terminal a few weeks ago, and learned a few tricks that greatly increased my productivity.
The first example is creating aliases for commands. The idea is to create shortcuts for the commands so that you don't need to type them every time you use them. The example above enables you to use the command named "vim" instead of the long string "~/MacVim-snapshot-77/mvim", which of course saves great time if you are a MacVim user.# I needed this long address because my old MacVim didn't support copy/pasting into clipboard, and I couldn't replace the old one with the newly installed MacVim, so I had to create the shortcut to refer "vim" to the new address..
However, it's only a temporary alias. Once the terminal window is closed, the alias is no longer available. To create a permanent alias, you need to write the code above in a file called ".bash_profile":
1 2 3
vi ~/.bash_profile # add your code in the file, save and close the file source ~/.bash_profile # Don't forget to activate the changes you just made!
The same trick works on other commands:
1 2 3 4
alias blog="cd ~/Documents/scarlyblog" # enter the directory you want alias server="./hexo server" # start the server alias lab="ssh email@example.com" # connect via SSH to your server alias fetch="scp -r firstname.lastname@example.org:~/somefolder ~/putithere" # securely copy files from your server
Yeah! Makes the world a better place!
Another trick I use all the time is the powerful keyboard shortcuts. For example, you can search for a line in the command history with control + R, go to the start/end of the line with command + left/right, move to the adjacent to the text field with control + left/right, select the text(s) or paragraph(s) with shift + option + left/right/up/down, terminate a process with control + c, etc. The list goes on and on.
Also, don't forget your Spotlight Search: control + space!# The wildtype Spotlight Search seems to use command + space as the keyboard shortcut. I changed it years ago to cntrl and use cmd + space to switch input source instead. I completely forgot about it when I first wrote this article...
TabAre you a tab person or space person? :))
Tab is especially useful if you want to create a hierarchical structure for your notes or texts. It indents one paragraph under another. It's extremely convenient as well in the terminal (and in RStudio) to let the program autofill (tab completion) the partially typed commands.
Use the terminal!
I have already mentioned terminal before. Once you start working with the terminal, you will literally become obsessed with it because it enables you to do tasks that are otherwise at least combersome.
1 2 3 4 5 6 7
ls -a ~/directory # list the otherwise invisible files in the directory mdfind -name 'ethic' -onlyin ~/Documents/lecture # search for files in some directory rm -rf ~/Documents/lecture/*ethic* # delete the files that you have just found ls -lh ~/Documents/lecture # list the files in the directory and their sizes python # call your favorate calculator :) defaults write com.apple.screencapture location ~/Downloads # combine with the next line killall SystemUIServer # change the default directory to Downloads for screenshots
I already had some sweet experiences with my terminal where it helped me to solve annoying problems. Once in the lab, I did not properly save my script and the workspace before leaving. On the next day, I surprisingly found that I was not able to open my script any more (yeah, what a surprise!). I asked my wonderful colleague for help, and the solution in the end was to dig my file up from the hourly backups:
1 2 3 4 5 6 7 8 9
cd .zfs cd snapshot ls cd hourly-2016-06-15-15 ls cd Documents/mydirectory ls -lh less myfile cp myfile ~/Documents/mydirectory
Hmm...# The backup system in the institute is a bit wired (but makes sense): you cannot see the backup directory with ls (or ls -a, it's wiredly hidden) nor can you cd into the backups in one step. You have to know where they are located beforehand.
So, that's a bit of the things that I learned in the past few weeks. 我每天都感觉到好惊讶，原来我的电脑这么cool，能做这么多事情 :)
在下一篇文章里，我会介绍一些我学习编程的体会和感受。Yes, it's amaaaazing!