Skip to content

Instantly share code, notes, and snippets.

@polikeiji
polikeiji / selenium_middleware.py
Last active February 24, 2016 03:27
PythonでJavaScriptを使ったWebサイトをスクレイピングする ref: http://qiita.com/polikeiji/items/94062c1d9ef2f86a0c27
# -*- coding: utf-8 -*-
import os.path
from urlparse import urlparse
import arrow
from scrapy.http import HtmlResponse
from selenium.webdriver import Firefox
@polikeiji
polikeiji / check_db_connection_decorator.py
Created October 14, 2015 03:59
Bottlepy用のPeeweeのコネクションをチェックするデコレーター
# Decorator
@decorator
def check_db_connection(func, *args, **kwargs):
try:
db.get_conn().ping(True)
except:
logging.error(traceback.format_exc())
return func(*args, **kwargs)
@polikeiji
polikeiji / short_url_util.py
Last active September 30, 2015 04:01
10進数を短めの文字列に変換するPythonスクリプト
# -*- coding: utf-8 -*-
"""
convert_tableは、文字のリスト。
このリストを使って基数変換する。
リストの長さが62だったら、62進数に変換する感じ。
intは、10進数で入れる。
"""
import math
@polikeiji
polikeiji / search_ipod.applescript
Created July 29, 2015 03:18
自分のiTunesの曲を検索する。iTunes Match、Apple Script上の曲は、13行目が動かない。
on search(keyword)
tell application "iTunes"
set p to first library playlist
set sr to (search p for keyword)
return sr
end tell
end search
set sr to search("曲名")
@polikeiji
polikeiji / gist:a00455c83fdbcdb8f110
Last active August 29, 2015 14:23
エクセルをJSONに直すPythonスクリプト
import xlrd
from collections import OrderedDict
import simplejson as json
excel_path = raw_input('input path> ')
json_path = raw_input('output json path> ')
wb = xlrd.open_workbook(excel_path)
sheets = OrderedDict()
@polikeiji
polikeiji / override_print.py
Last active August 29, 2015 14:09
コンソールに上書き出力するPython用関数。
def override_print(message, line_length = 100):
if len(message) > line_length:
message = message[:line_length - 3] + "..."
sys.stdout.write((u"\r{0:<" + str(line_length) + "}").format(message))
sys.stdout.flush()
@polikeiji
polikeiji / gist:f0f5b2b80610accb9665
Created August 27, 2014 03:58
knockout.jsでdropzone.jsを使う為のカスタムバインディング。
ko.bindingHandlers.dropzone =
init: (element, value_accessor) ->
passed_value = ko.unwrap value_accessor()
send_data = passed_value.data
$target = $(element).dropzone
url: passed_value.url
sending: (file, xhr, form_data) ->
for name, value of send_data
if typeof(value) == "function"
form_data.append name, value()
@polikeiji
polikeiji / gist:2b6056610d6fc0bc55a7
Created July 28, 2014 08:23
gunicornのリバースプロキシ付きのnginx.conf
user www;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
@polikeiji
polikeiji / gist:dc39630eebf169333026
Created July 28, 2014 08:21
gunicorn起動用のupstartのinitスクリプト
description "[APP NAME] API Server"
start on runlevel [2345]
stop on runlevel [016]
respawn
script
su - www
source /home/www/[APP NAME]/virtualenv/bin/activate
@polikeiji
polikeiji / gist:92b9b99a5263c73c7874
Created July 12, 2014 19:37
Twitterのフォロワー一覧のプロフ画像の解像度をあげるブックマークレット
javascript: $(".ProfileCard-avatarImage").each(function() { $avatarImg = $(this); $avatarImg.attr("src", $avatarImg.attr("src").replace("_bigger", "_400x400")); });