Docopt - Command-line interface description language

When we want a user-friendly command-line interface

What we want are:

  • useful help and usage messages
  • easy to parse the arguments

Docopt helps you:

  • define interface for your command-line app
  • automatically generate parser for it

Seems other libs in python can handle this also, like: argparse, optparse, getopt, click.

But after I used all of those libs, I find docopt is the easiest way to handle this, and what your see is what your get.

Demo(naval_fate.py)

"""Naval Fate.

Usage:
  naval_fate.py ship new <name>...
  naval_fate.py ship <name> move <x> <y> [--speed=<kn>]
  naval_fate.py ship shoot <x> <y>
  naval_fate.py mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate.py -h | --help
  naval_fate.py --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.

"""
from docopt import docopt


if __name__ == '__main__':
    arguments = docopt(__doc__, version='Naval Fate 2.0')
    print(arguments)

When you want to get help and usage messages

python naval_fate.py –help

Naval Fate.
	
Usage:
  naval_fate.py ship new <name>...
  naval_fate.py ship <name> move <x> <y> [--speed=<kn>]
  naval_fate.py ship shoot <x> <y>
  naval_fate.py mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate.py -h | --help
  naval_fate.py --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.

And when we type: python naval_fate.py ship new ‘Going Merry’

The parsed arguments are:

{'--drifting': False,
 '--help': False,
 '--moored': False,
 '--speed': '10',
 '--version': False,
 '<name>': ['Going Merry'],
 '<x>': None,
 '<y>': None,
 'mine': False,
 'move': False,
 'new': True,
 'remove': False,
 'set': False,
 'ship': True,
 'shoot': False}

Write less code than others, and get all what we want, this is Docopt

Visit Homepage to get all the documents.

Read Github to know the amazing code.

Try Demo Source Code in your terminal.

(Comments)


Play with Alfred

Alfred 是一款 OSX 下的效率软件,类型系统的 Spotlight,但强大许多,默认快捷键:option + space

基础功能

能够让你快速的启动系统中所安装的应用程序,比如我输入 c,回车即可打开 chrome 浏览器,也可以上下选择不同的应用

app

能够无需打开浏览器,无需打开 google 主页,直接通过 google 搜索关键字

search

能够代替系统计算器做简单的运算

cal

可以很方便的听 iTunes 里的音乐

music

这些都是 Alfred 最基本的功能,免费版就可以使用,并且没有广告及时间限制

通过查看 Usage,发现我每天大概使用 30 次左右,主要用于打开应用

增强功能

他的强大远远不止这些,他的 powerpack 才是重点,列举几个我常用的 workflow

Adium: talk with someone with adium

adium

Datetime Format Converter: switch timestamp and datetime

datetime

Dev Doctor: docs(python, java, php, etc…)

dev

Douban: search movie, book, music in douban

douban

Weather: 查看天气情况

weather

Youdao: 有道翻译

youdao

还有非常多的 workflow,更多,速度使用吧!

REFs:

下载 alfred

下载 powerpack

借助 Alfred 2.0 的 Workflows 功能可以做哪些好玩的事情?

(Comments)


About monitoring

New Relic

New Relic is the all-in-one web application performance tool that lets you see performance from the end user experience down to the line of application code.

用于监控服务器状态,及自定义服务的负载,一个网站或应用相关的所有东西都可监控

收费并且不便宜

自己构建

对于服务异常,我们使用 django-sentry,相关文档及 client 比较完善

对于系统级监控,指标收集使用 collectd

对于自定义监控,指标收集使用 statsite

指标收集也可以看看:bucky

对于指标展示,使用 graphite,更好的 dashboard graphene dashing

对于报警,我们使用 nagios,比较灵活

REFs:

newrelic

http://blog.dccmx.com/2012/12/build-perfect-monitoring-system/

(Comments)