Pages

[JS] Use object instead of swictch case

If you find yourself writing switch-case or long if-else clauses based on string comparision condition, consider switching it to use object instead. Object in Javascript can be dynamically updated which makes it very flexible. It works as a map so lookup is quick. For example, if you have some code like below.

[NodeJS] Pushing posts to Blogger from commandline

I was trying to write some small cli to push my posts to Blogger from the commandline. There are some tools out there, including googlecl and blogger-cli but no nodejs tool as far as I know. So, I registered to use Blogger API. Unfortunately, you'll have to wait 5 days just to get approval and instruction from Google, and that process is handled by only one man, Brett. So, while waiting for the API, here's my work around.

Install Powerline for Mac OS X

Powerline is a shell prompt and statusline plugin for vim, written in Python. It makes working with terminal much more fun and colorful. Here is an example of how the prompt looks like with Powerline.

As you can see from the screenshot, powerline gives you a colorful and visual attractive prompt. If you are in a git repository, it also tells you which branch you are currently working on. It also tells you the exit code of previous process (the number in the last red tab), etc. In this post, I'll show you how to install and setup powerline for Mac OS X bash shell and vim.

How to insert code snippets to Blogger blogs

This is my third day, i.e. roughly more than 2 hours, playing with Blogger. So, this post reflects my minimal knowledge of the system. If you have better solutions, please drop me a comment below. So far, I really like Blogger for its simplicity. However, I didn't find a nice and efficient way to put code snippets into my blog posts. A quick google search reveals that many people have struggled with this problem before. The most popular solution I found is SyntaxHighlighter, written by Alex Gorbatchev.

Git aliases with autocompletion

If you are using git on daily basis, you probably want to create some shorthands, aka. aliases, to save time. The very first option that is documented in tutorials and books about git is through git configuration.

$ vi ~/.gitconig

[alias]
st = status
co = checkout
br = branch
up = rebase
ci = commit

Lodash merge without overwriting

In many cases, you want to combine small objects into a big object. Lodash gives you _.merge() method to do so. (For more usages of _.merge(), see the lodash's docs).


let name = {name: 'Joe'},
    age = {age: 18},
    user = _.merge(name, age); // user = {name: 'Joe', age: 18}     

But what if you want to merge more than 2 objects together? Say, an array of objects? Well, remember apply method?

Update bash shell for Mac OS X

Apple releases software update quite often but, unfortunately, bash shell is never updated. The version of bash shell that comes with Max OS is quite old and lacks many features such as globing, exclude-dir when grepping, etc. If you need these features, you will need to update bash shell. First, check the version of your bash.


$ echo $BASH_VERSION
3.2.53(1)-release

$ which bash
/bin/bash