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

Setup Hubot with Slack

Hubot is an extensible chat bot written in CoffeeScript.



$ npm install -g yo generator-hubot

$ mkdir codebaku-hubot
$ cd codebaku-hubot
$ yo hubot

a list of adapters

You need to create a Hubot integration on your Slack to request an API token.

Local Development

Writing your own script

./bin/hubot --name hubot

# or

HUBOT_SLACK_TOKEN=YOUR_SLACK_TOKEN ./bin/hubot --adapter slack

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


Debugging Hubot Scripts using Node Inspector

$ npm install -g node-inspector coffee-script

$ node-inspector --no-preload --web-port 8123

# generate source map
$ coffee -m scripts/*.coffee
$ coffee --nodejs --debug node_modules/.bin/hubot --name hubot
$ coffee --nodejs --debug node_modules/.bin/hubot --adapter slack

$ boot2docker ip
$ open

Computer names for Sci-Fi maniac developers

科幻迷的 hostname 列表

  • ADA (Anubis Zone of the Enders)
  • Asurada (Future GPX Cyber Formula)
  • Deep Thought (The Hitchhiker's Guide to the Galaxy)
  • EDI (Mass Effect)
  • EVA-00 (Neon Genesis Evangelion)
  • EVA-01 (Neon Genesis Evangelion)
  • EVA-02 (Neon Genesis Evangelion)
  • GERTY (Moon)
  • GLaDOS (Portal)
  • HAL 9000 (2001: A Space Odyssey)
  • Jane (Ender's Game)
  • JARVIS (Iron Man)
  • KOS-MOS (Xenosaga)
  • MAGI (Neon Genesis Evangelion)
  • Melchizedek (Gunnm Last Order)
  • Mike (The Moon Is a Harsh Mistress)
  • Pip-Boy 3000 (Fallout)
  • Project 2501 (Ghost in the Shell)
  • Skynet (The Terminator)
  • Tachikoma (Ghost in the Shell)
  • TARS (Interstellar)
  • TechnoCore (Hyperion)
  • VIKI (I, Robot)
  • Wheatley (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')