Use Docker Machine to setup Docker environments

Docker Machine is a command-line tool to help you create Docker environments on your computers or cloud providers.


Installatino on Mac

$ curl -L > /usr/local/bin/docker-machine
$ chmod +x /usr/local/bin/docker-machine


$ docker-machine ls

$ docker-machine create --driver virtualbox dev

# list arguments for creating a VirtualBox VM
$ docker-machine create -d virtualbox

# see how to connect Docker to this machine
$ docker-machine env dev

# run this command to configure your shell
$ eval "$(docker-machine env dev)"

# then
$ docker info


Error response from daemon: client and server don't have same version (client : 1.19, server: 1.18)

$ docker-machine upgrade dev
Slack: Build a chat bot with Hubot in JavaScript

Slack: Build a chat bot with Hubot in JavaScript

Hubot is an scriptable chat bot framework created by GitHub. The newer version supports JavaScript (ES6+), no more CoffeeScript!



$ npm install -g yo generator-hubot

$ mkdir codetengu-bot
$ cd codetengu-bot
$ yo hubot --adapter=slack

You could find all available adapters here:

Slack Token

The next thing you need is a Slack Bot Token (API Token) which looks like xoxb-xxx for your chat bot app. You could create a Hubot app in your Slack workspace to request a token, for instance

Otherwise, you could also create an universal Slack app, install it to your workspace. In your app settings, under "Install App" section, you are able to find OAuth Tokens for your chat bot. See



./bin/hubot --adapter slack

I fork a script named hubot-reload-scripts to help you reload your scripts when developing them.

Hear And Respond Messages

Writing your own script

// scripts/your_script.js
// Description
//   Do your shit
// Author:
//   Vinta Chen
// Commands:
//   * `restart <service>`* - Restart the service
const _ = require('lodash');

module.exports = (robot) => {
  robot.hear(/restart ([a-z0-9_\-]+)/i, (res) => {
    robot.logger.debug(`Received message: ${res.message.rawText}`);
    const [ serviceName ] = res.match.slice(1);
    res.send(`Restarting ${serviceName}`);

Call Slack APIs{'channel':})
  .then(apiRes => {
    const purpose =;
    const topic =;
    res.send(`purpose: ${purpose}`);
    res.send(`topic: ${topic`);
  .catch(apiErr => {
    robot.logger.error('apiErr', apiErr);


Computer names for Sci-Fi maniac developers

Computer names for Sci-Fi maniac developers

The list is collected from books I read, movies I watched, and video games I played.

  • ADA (from Zone of the Enders: The 2nd Runner)
  • Albedo (from Hyperion) --> used for one of my code projects
  • Asurada (from Future GPX Cyber Formula)
  • BrainPal (from Old Man's War)
  • ctOS (from Watch Dogs)
  • Deep Thought (from The Hitchhiker's Guide to the Galaxy)
  • Eddie (from The Hitchhiker's Guide to the Galaxy)
  • EDI (from Mass Effect) --> used for one of my code projects
  • EVA-00 (from Neon Genesis Evangelion)
  • EVA-01 (from Neon Genesis Evangelion)
  • EVA-02 (from Neon Genesis Evangelion)
  • Fine Till You Came Along (from Culture: Look to Windward)
  • GERTY 3000 (from Moon)
  • GLaDOS (from Portal)
  • HAL 9000 (from 2001: A Space Odyssey) --> used for one of my code projects
  • Jane (from Ender's Game: Speaker for the Dead) --> used for My AirPods
  • JARVIS (from Iron Man)
  • KOS-MOS (from Xenosaga)
  • Limiting Factor (from The Culture: The Player of Games)
  • MAGI (from Neon Genesis Evangelion) --> used for my iPad
  • Melchizedek (from Gunnm Last Order)
  • Mike (from The Moon Is a Harsh Mistress)
  • Of Course I Still Love You (from The Culture: The Player of Games)
  • Pip-Boy 3000 (from Fallout) --> used for my iPhone
  • Project 2501 (from Ghost in the Shell)
  • Samantha (from Her)
  • Skynet (from The Terminator)
  • SAL-9000 (2010: The Year We Make Contact)
  • Sol-9000 (from Xenogears)
  • Sophon (from The Three-Body Problem)
  • Tachikoma (from Ghost in the Shell)
  • TARS (from Interstellar)
  • TechnoCore (from Hyperion) --> used for my Macbook Pro
  • Ummon (from Hyperion) --> used for one of my code projects
  • VIKI (from I, Robot)
  • Wheatley (from Portal)


The templatetag {% include %} in Django

Loads a template and renders it with the current context.

# 會把 template context 也帶進去
{% include 'new_style/_bottom_action_btns' %}

{% for repost in recommend_creatives %}
    # 會把 repost 這個參數也帶進去!
    {% include 'new_style/creative_small.html' %}
{% endfor %}

# 但是你也可以額外指定要傳進去的 context
{% include 'new_style/_bottom_action_btns' with item=item repost=None %}

# 或是用 only 來限制只傳「顯式地指定的參數」進去
{% include 'new_style/_bottom_action_btns' with item=item only %}


Python with Excel: xlrd, xlsxwriter and xlutils


xlsxwriter 的文件寫得比較好



row 是橫排
column 是直排

Default format

import xlsxwriter

workbook = xlsxwriter.Workbook('label_copy.xlsx')

# default cell format
workbook.formats[0].set_text_wrap() # 要加上這個才能正常顯示多行


Multiple lines

lines_format = workbook.add_format({
    'align': 'left',
    'font_size': 12,
    'text_wrap': True,
    'valign': 'vcenter',

# 或是用 """多行"""
content = 'first line\nsecond line'
worksheet.write(0, 0, content, lines_format)

重點是要加上 text_wrap


Write to existing excel files

from xlutils.copy import copy as xlutils_copy
import xlrd

rb = xlrd.open_workbook('your_file.xls', formatting_info=True)
wb = xlutils_copy(rb)
ws = wb.get_sheet(0)
ws.write(0, 0, 'Hello World')