Skip to content

Instantly share code, notes, and snippets.

View axiaoxin's full-sized avatar
🌙
不忙着圆缺 春天不走远

axiaoxin axiaoxin

🌙
不忙着圆缺 春天不走远
View GitHub Profile
@axiaoxin
axiaoxin / bom
Created December 31, 2013 03:41
def has_bom(fn):
with open(fn, 'rb') as f:
sample = f.read(4)
return sample[:3] == b'\xef\xbb\xbf' or \
sample.startswith(codecs.BOM_UTF16_LE) or \
sample.startswith(codecs.BOM_UTF16_BE)
<script type="text/javascript">
window.onbeforeunload = function(){
$.get('/accounts/logout')
return "close";
}
</script>
(Anum + 1e-6) / (Bnum + 1e-6)
find . -type f -name "*.py" | xargs autopep8 -i --aggressive
def find_zero_sum(arr):
sums = [0] * len(arr)
for i, x in enumerate(arr):
for j in range(0, i + 1):
sums[j] += arr[i]
if sums[j] == 0:
return (j, i)
arr = [8, 1, 2, 7, -4, -6]
zero_sum_index = find_zero_sum(arr)
#-*- coding:utf-8 -*-
def get_f1(standard_answer, user_answer):
s_user_answer = set(user_answer)
s_standard_answer = set(standard_answer)
correct_results_len = len(s_user_answer & s_standard_answer)
if correct_results_len > 0:
precision = float(correct_results_len) / len(user_answer)
recall = float(correct_results_len) / len(standard_answer)
f1 = 2 * precision * recall / (precision + recall)
@axiaoxin
axiaoxin / gist:5ac3ddf0207c0543f7ea
Last active August 29, 2015 14:06
__parse_dict_depth
def __parse_dict_depth(self, d, depth=0):
if not isinstance(d, dict) or not d:
return depth
return max(self.__parse_dict_depth(v, depth+1) for k, v in d.iteritems())
@axiaoxin
axiaoxin / regions.json
Created December 26, 2014 06:28
regions.json
{"name":"北京市","zip":"100000","alias":"北京","pinyin":"BeiJing","level":"1","parent_id":"","abbr":"BJ","id":"110000"}
{"name":"东城区","zip":"100010","alias":"东城区","pinyin":"DongChengQu","level":"2","parent_id":"110000","abbr":"DCQ","id":"110101"}
{"name":"西城区","zip":"100032","alias":"西城区","pinyin":"XiChengQu","level":"2","parent_id":"110000","abbr":"XCQ","id":"110102"}
{"name":"朝阳区","zip":"100011","alias":"朝阳区","pinyin":"ChaoYangQu","level":"2","parent_id":"110000","abbr":"CYQ","id":"110105"}
{"name":"丰台区","zip":"100071","alias":"丰台区","pinyin":"FengTaiQu","level":"2","parent_id":"110000","abbr":"FTQ","id":"110106"}
{"name":"石景山区","zip":"100071","alias":"石景山区","pinyin":"ShiJingShanQu","level":"2","parent_id":"110000","abbr":"SJSQ","id":"110107"}
{"name":"海淀区","zip":"100091","alias":"海淀区","pinyin":"HaiDianQu","level":"2","parent_id":"110000","abbr":"HDQ","id":"110108"}
{"name":"门头沟区","zip":"102300","alias":"门头沟区","pinyin":"MenTouGouQu","level":"2","parent_id":"110000","abbr":"MTGQ","id":"110109"}
{"name":"房山区","zip"
jq -c 'select(.series|startswith("启辰D50"))' 8.1-12.31_all.json |jq -c 'select(.published_at|startswith("2014-09"))' |wc -l

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application: