Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View yubessy's full-sized avatar

Shotaro Tanaka yubessy

View GitHub Profile
@yubessy
yubessy / file0.txt
Last active August 29, 2015 14:00
Python2のstr/unicodeとencode/decode ref: http://qiita.com/yubessy/items/9e13af05a295bbb59c25
>>> 'あいう'
'\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86'
@yubessy
yubessy / corenlp_example.py
Last active August 29, 2015 14:00
Stanford CoreNLPをPythonから使う ref: http://qiita.com/yubessy/items/1869ac2c66f4e76cd6c5
import pprint
import json
import corenlp
# パーサの生成
corenlp_dir = "/usr/local/lib/stanford-corenlp-full-2013-06-20/"
parser = corenlp.StanfordCoreNLP(corenlp_path=corenlp_dir)
# パースして結果をpretty print
result_json = json.loads(parser.parse("I am Alice."))
@yubessy
yubessy / file0.txt
Last active August 29, 2015 14:00
PythonでExcelファイルを作成 + similarity matrix ref: http://qiita.com/yubessy/items/a39a565cdc2c5872cce9
$ pip install xlsxwriter
@yubessy
yubessy / Default (OSX).sublime-keymap
Last active August 29, 2015 14:01
Sublime Text 2でコマンドパレットのコマンドにショートカットキーを割り当てる ref: http://qiita.com/yubessy/items/546fc167e6c6c248415b
[
{
"keys": ["command+_"],
"command": "run_emmet_action",
"args": {
"action": "merge_lines"
}
}
]
@yubessy
yubessy / file1.txt
Last active August 29, 2015 14:01
PythonのbottleでBASIC認証 ref: http://qiita.com/yubessy/items/33789eccb35b659b0b4e
$ python hello.py
@yubessy
yubessy / sql_style1.py
Created June 3, 2014 03:20
Pythonコードの中に複数行SQLを書く ref: http://qiita.com/yubessy/items/86032d332ac86c1abe67
sql_stmt = "CREATE TABLE Test(" \
"id INTEGER PRIMARY KEY, " \
"val TEXT NOT NULL)"
@yubessy
yubessy / mycompress.py
Last active August 29, 2015 14:03
Pythonのオブジェクト圧縮・展開
# -*- coding: utf-8 -*-
# stdlib
import cPickle as pickle
import zlib
PROTOCOL = pickle.HIGHEST_PROTOCOL
def save_to_str(obj):
@yubessy
yubessy / mydatex.py
Created June 29, 2014 02:33
Wikipediaの各年ページの日付をパース
# -*- coding: utf-8 -*-
# stdlib
import re
import datetime
# thirdlib
from dateutil.parser import parse
MONTHS = (
"January",
"February",
@yubessy
yubessy / myerr.py
Created June 29, 2014 02:35
簡単なエラーメッセージ出力
# -*- coding: utf-8 -*-
# stdlib
import sys
import traceback
def print_exception(func, log_file=sys.stderr):
u"""
関数実行中に発生した例外を出力
"""
@yubessy
yubessy / myhtmlclean.py
Created June 29, 2014 03:03
HTMLをクリーンアップ
# -*- coding: utf-8 -*-
# stdlib
import re
LEFT_SPACES = re.compile(r'\s+<')
RIGHT_SPACES = re.compile(r'>\s+')
SCRIPT_TAG = re.compile(r'<script[^>]*>.*?</script>')
COMMENT = re.compile(r'<!--[\s\S]*?-->')