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.

ref:
https://docs.docker.com/machine/

Installatino on Mac

$ curl -L https://github.com/docker/machine/releases/download/v0.3.0/docker-machine_darwin-amd64 > /usr/local/bin/docker-machine
$ chmod +x /usr/local/bin/docker-machine

Usage

$ 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

Issues

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.

ref:
https://hubot.github.com/

Installation

$ npm install -g yo generator-hubot

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

a list of adapters
https://hubot.github.com/docs/adapters/

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

Local Development

Writing your own script
https://hubot.github.com/docs/scripting/

./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.
https://github.com/vinta/hubot-reload-scripts

Debugging

Debugging Hubot Scripts using Node Inspector
https://gist.github.com/ejhayes/2879225
https://github.com/github/hubot/issues/648

$ 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 http://192.168.59.103:8123/?port=5858

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)

ref:
https://www.wikiwand.com/en/List_of_fictional_computers
https://www.wikiwand.com/en/Artificial_intelligence_in_fiction

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 %}

ref:
https://docs.djangoproject.com/en/dev/ref/templates/builtins/#std:templatetag-include

Python with Excel: xlrd, xlsxwriter and xlutils

Libraries

xlsxwriter 的文件寫得比較好

ref:
http://www.python-excel.org/
https://xlsxwriter.readthedocs.org/en/latest/
http://openpyxl.readthedocs.org/en/latest/

Usage

row 是橫排
column 是直排

Default format

import xlsxwriter

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

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

ref:
https://xlsxwriter.readthedocs.org/en/latest/format.html

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

ref:
http://stackoverflow.com/questions/15370432/writing-multi-line-strings-into-cells-using-openpyxl

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')

ref:
http://stackoverflow.com/questions/2725852/writing-to-existing-workbook-using-xlwt

Examples

https://xlsxwriter.readthedocs.org/en/latest/examples.html
http://www.crifan.com/python_append_new_data_into_existing_excel_xls_file/