Skip to content

Instantly share code, notes, and snippets.

Avatar
⛩️
Enjoying Kyoto.

Shotaro Tanaka yubessy

⛩️
Enjoying Kyoto.
View GitHub Profile
@yubessy
yubessy / Python3
Last active May 14, 2019
Python3の...(Ellipsisオブジェクト)について ref: https://qiita.com/yubessy/items/cc1ca4dbc3161f84285e
View Python3
>>> str(Ellipsis)
'Ellipsis'
>>> str(pass)
File "<stdin>", line 1
str(pass)
^
SyntaxError: invalid syntax
@yubessy
yubessy / Gemfile
Last active Aug 29, 2015
LESSやらSassやらを使わずにRailsにBootstrapを導入 ref: http://qiita.com/yubessy/items/d01a1e4ea54741331942
View Gemfile
gem 'twitter-bootstrap-rails', :git => 'git://github.com/seyhunak/twitter-bootstrap-rails.git', :branch => 'bootstrap3'
@yubessy
yubessy / mywiki.py
Created Jun 29, 2014
MediaWIki APIを使って項目の別名を取得したりなど
View mywiki.py
#-*- 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 Jun 29, 2014
長い文字列を短く表示
View myshorten.py
# -*- coding: utf-8 -*-
def shorten(s, length=80):
u"""
長い文字列を"abraca ... tabra"のように短く表示
"""
if len(s) < length:
return s
else:
if isinstance(s, unicode):
View mytextrank.py
# -*- coding: utf-8 -*-
# third-party lib
import networkx
def blank_split(text):
u"""
半角スペースによる単語分割
"""
return text.split()
@yubessy
yubessy / myhtmlclean.py
Created Jun 29, 2014
HTMLをクリーンアップ
View myhtmlclean.py
# -*- 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 Jun 29, 2014
簡単なエラーメッセージ出力
View myerr.py
# -*- coding: utf-8 -*-
# stdlib
import sys
import traceback
def print_exception(func, log_file=sys.stderr):
u"""
関数実行中に発生した例外を出力
"""
@yubessy
yubessy / mydatex.py
Created Jun 29, 2014
Wikipediaの各年ページの日付をパース
View mydatex.py
# -*- coding: utf-8 -*-
# stdlib
import re
import datetime
# thirdlib
from dateutil.parser import parse
MONTHS = (
"January",
"February",
@yubessy
yubessy / mycompress.py
Last active Aug 29, 2015
Pythonのオブジェクト圧縮・展開
View mycompress.py
# -*- coding: utf-8 -*-
# stdlib
import cPickle as pickle
import zlib
PROTOCOL = pickle.HIGHEST_PROTOCOL
def save_to_str(obj):
View sql_style1.py
sql_stmt = "CREATE TABLE Test(" \
"id INTEGER PRIMARY KEY, " \
"val TEXT NOT NULL)"