Want to create a Gist from your editor, the command line, or the Services menu? Here's how.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def thrice | |
| yield | |
| yield | |
| yield | |
| end | |
| x = 5 | |
| puts "value of x before: #{x}" # 5 | |
| thrice { x += 1 } | |
| puts "value of x after: #{x}" # |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| git filter-branch --env-filter ' | |
| an="$GIT_AUTHOR_NAME" | |
| am="$GIT_AUTHOR_EMAIL" | |
| cn="$GIT_COMMITTER_NAME" | |
| cm="$GIT_COMMITTER_EMAIL" | |
| if [ "$GIT_COMMITTER_EMAIL" = "[email protected]" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SCOPE = 'douban_basic_common,shuo_basic_r,shuo_basic_w,community_advanced_doumail_r' | |
| client = DoubanClient(API_KEY, API_SECRET, CALLBACK, SCOPE) | |
| print 'Go to the following link in your browser:' | |
| print client.authorize_url | |
| code = raw_input('Enter the verification code:') | |
| access_token = client.auth_with_code(code) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'date' | |
| author = "fenbi" | |
| email = "[email protected]" | |
| date = Date.new(2012, 7, 30) | |
| l = %w{ | |
| . . . . . . . | |
| . . o . . . . | |
| . . o . . . . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| passenger-install-apache2-module --auto --apxs2-path=/usr/local/apache2/bin/apxs --apr-config-path=/usr/local/apache2/bin/apr-1-config |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 基本定制型 | |
| C.__init__(self[, arg1, ...]) 构造器(带一些可选的参数) | |
| C.__new__(self[, arg1, ...]) 构造器(带一些可选的参数);通常用在设置不变数据类型的子类。 | |
| C.__del__(self) 解构器 | |
| C.__str__(self) 可打印的字符输出;内建str()及print 语句 | |
| C.__repr__(self) 运行时的字符串输出;内建repr() 和‘‘ 操作符 | |
| C.__unicode__(self)b Unicode 字符串输出;内建unicode() | |
| C.__call__(self, *args) 表示可调用的实例 | |
| C.__nonzero__(self) 为object 定义False 值;内建bool() (从2.2 版开始) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from collections import namedtuple | |
| def json2object(data): | |
| """ | |
| >>> json2object("a") | |
| 'a' | |
| >>> data = {"a": 100, "b": 200} | |
| >>> obj = json2object(data) | |
| >>> obj.a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| def pp(msg): | |
| sys.stdout.write("\r") | |
| sys.stdout.write(msg) | |
| sys.stdout.flush() |