Skip to content

Instantly share code, notes, and snippets.

View yubessy's full-sized avatar

Shotaro Tanaka yubessy

View GitHub Profile
@yubessy
yubessy / Python3
Last active May 14, 2019 11:34
Python3の...(Ellipsisオブジェクト)について ref: https://qiita.com/yubessy/items/cc1ca4dbc3161f84285e
>>> str(Ellipsis)
'Ellipsis'
>>> str(pass)
File "<stdin>", line 1
str(pass)
^
SyntaxError: invalid syntax
@yubessy
yubessy / Gemfile
Last active August 29, 2015 14:04
LESSやらSassやらを使わずにRailsにBootstrapを導入 ref: http://qiita.com/yubessy/items/d01a1e4ea54741331942
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git', :branch => 'bootstrap3'
@yubessy
yubessy / mywiki.py
Created June 29, 2014 03:19
MediaWIki APIを使って項目の別名を取得したりなど
#-*- encoding: utf-8 -*-
# thirdlib
import requests
BASE_URL = "http://en.wikipedia.org/w/api.php"
BLLIMIT = 250
def get_regular_name(q):
@yubessy
yubessy / myshorten.py
Created June 29, 2014 03:16
長い文字列を短く表示
# -*- coding: utf-8 -*-
def shorten(s, length=80):
u"""
長い文字列を"abraca ... tabra"のように短く表示
"""
if len(s) < length:
return s
else:
if isinstance(s, unicode):
# -*- coding: utf-8 -*-
# third-party lib
import networkx
def blank_split(text):
u"""
半角スペースによる単語分割
"""
return text.split()
@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]*?-->')
@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 / 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 / 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 / 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)"