Use ‘optipng’ to optimize/re-compress your png images losslessly!

OptiPNG is a useful tool to compress png images without loss its quality, it really help reduce the bandwidth, diskspace and the loading/response time for website. I used it to re-compress all the png images on cdnjs and successfully made 206857 images smaller(see cdnjs/cdnjs@e936c87e9044fd2b123).

It’s easy to use, you can install it via apt-get, or download and build it from source :
$ sudo apt-get install optipng

Usage:
$ optipng example.png

The default compress level is 2, the range is 0~7 (may depends on the version you are using), I will always use the highest and slowest level:
$ optipng -o7 example.png

Find all the png images to compress:
$ find path -name "*.png" -exec optipng -o7 {} \;

In fact, optipng can convert BMP, GIF, PNM and TIFF format image to optimized optimized png, and also performs PNG integrity checks and corrections, very nice.

Use ‘nvm’ to manage/install nodejs with multiple versions!

NVM stands for Node Version Manager, just like its name, it’ll help us manage nodejs environment in a easy way.

NVM didn’t support Windows officially, but on Mac and Linux.

If you want to compile nodejs from sure(not requried), you should have c++ compiler, on Ubuntu(I’m using Ubuntu 14.01.2 LTS), try:
$ sudo apt-get install libssl-dev build-essential

Use the install script to install nvm is the easiest way(should have bash, if not, try manual install):
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.3/install.sh | bash

NVM will be installed in few seconds:

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7149 100 7149 0 0 6475 0 0:00:01 0:00:01 –:–:– 6481
=> Downloading nvm as script to ‘/home/peter/.nvm’

=> Appending source string to /home/peter/.bashrc
=> You currently have modules installed globally with npm. These will no
=> longer be linked to the active version of Node when you install a new node
=> with nvm; and they may (depending on how you construct your $PATH)
=> override the binaries of modules installed with nvm:

/usr/lib
├── bower@1.3.12
├── carto@0.14.0
├── cdnjs-importer@1.1.0
├── gh-contributions@1.1.1
├── ghcal@1.1.0
├── git-stats@1.4.0
├── grunt-cli@0.1.13
├── npm-check@3.2.10
├── npm-check-updates@1.5.1
└── stackvis@0.2.0

=> If you wish to uninstall them at a later point (or re-install them under your
=> nvm Nodes), you can remove them from the system Node as follows:

$ nvm use system
$ npm uninstall -g a_module

=> Close and reopen your terminal to start using nvm

That’s all … should reload your shell’s rc file or re-login, and try nvm now:

How to use a specified version of nodejs?

Install it by nvm(for the first time, add parameter -s if you want to install from source):
$ nvm install 0.11

Should be done in few secs:

######################################################################## 100.0%
Now using node v0.11.16 (npm v2.3.0)

And you can use nvm use to change to the version you want, like this:
$ nvm use 0.12

Now using node v0.12.3 (npm v2.9.1)

How to know current nodejs versions?
$ nvm current

v0.10.38

How to list installed nodejs versions?
$ nvm ls

-> v0.10.38
v0.11.16
v0.12.3
system

How to list the nodejs versions available?
$ nvm ls-remote
It’ll give a very long version list like above but longer and longer ….

run nvm without parameter will print you the usage, very easy to understand like this:

Node Version Manager

Usage:
nvm help Show this message
nvm –version Print out the latest released version of nvm
nvm install [-s] Download and install a , [-s] from source. Uses .nvmrc if available
nvm uninstall Uninstall a version
nvm use Modify PATH to use . Uses .nvmrc if available
nvm run [] Run with as arguments. Uses .nvmrc if available for
nvm current Display currently activated version
nvm ls List installed versions
nvm ls List versions matching a given description
nvm ls-remote List remote versions available for install
nvm deactivate Undo effects of nvm on current shell
nvm alias [] Show all aliases beginning with nvm alias Set an alias named pointing to
nvm unalias Deletes the alias named
nvm reinstall-packages Reinstall global npm packages contained in to current version
nvm unload Unload nvm from shell
nvm which [] Display path to installed node version. Uses .nvmrc if available

Example:
nvm install v0.10.32 Install a specific version number
nvm use 0.10 Use the latest available 0.10.x release
nvm run 0.10.32 app.js Run app.js using node v0.10.32
nvm exec 0.10.32 node app.js Run node app.js with the PATH pointing to node v0.10.32
nvm alias default 0.10.32 Set default node version on a shell

Note:
to remove, delete, or uninstall nvm – just remove ~/.nvm, ~/.npm, and ~/.bower folders

Read the readme file for more details:
https://github.com/creationix/nvm/blob/master/README.markdown

vim 視窗分割

vim-split-window雖說tmux很好用,不過vim本身內建視窗切割功能了,好像沒必要因此開多個shell跟vim浪費記憶體,還是記一下vim常用的分割視窗指令:

開新水平視窗:
:new
開新垂直視窗:
:vnew

水平切割後開起現有或指定檔案:
<code>:sp</code> (split)
垂直切割後開起現有或指定檔案:
<code>:vsp</code> (vsplit)
這兩個命令後面接檔名(記得前面要一個空格)會直接打開對應的檔案~

另外vim的分割視窗操作預設hot key是Ctrl + w, 也可以用熱鍵來操作:

水平切割視窗:
<Hot key> s
垂直切割視窗:
<Hot key> v

在分割視窗之間切換/移動焦點:
<Hot key> k  或  <Hot key> ↑
<Hot key> j  或  <Hot key> ↓
<Hot key> h  或  <Hot key> ←
<Hot key> l  或  <Hot key> →
(把英文字母改成大寫則可移動到最上最下最左最右)

把目前的分割視窗加大:
<Hot key> +
把目前的分割視窗縮小:
<Hot key> –
把目前同一行/列的分割視窗高/寬平均:
<Hot key> =
把目前的分割視窗放到最大(寬or高):
<Hot key> _
<Hot key> |
把目前的分割視窗用一個新的分頁(tab)開啟:
<Hot key> T

要強迫自己習慣一下~