Skip to content

Instantly share code, notes, and snippets.

@aoshiman
aoshiman / tweet_archive.bas
Last active December 16, 2015 02:19
twitterのアーカイブ(tweet.zip)に入っているtweets.csvをExcelに展開するvba
Option Explicit
Dim wkFile, wkPrompt As String
Dim wkFileName As Variant
Dim strFileName As String
Dim objStream As Object
Dim objRegExp As Object
Dim ii As Long
# -*- coding: utf-8 -*-
from datetime import datetime
def timesince(dt, default=u"記事が投稿されました"):
"""
timesince filter
http://flask.pocoo.org/snippets/33/
を日本語ローカライズしflashに対応させたもの
"""
@aoshiman
aoshiman / decorator_auth.py
Created June 13, 2013 09:33
FlaskでBASIC認証をかけるデコレータ
from functools import wraps
from flask import request, Response
from setting import USERNAME, PASSWORD
def check_auth(username, password):
"""This function is called to check if a username /
password combination is valid.
"""
return username == USERNAME and password == PASSWORD
@aoshiman
aoshiman / monitor.py
Created June 28, 2013 07:25
pyinotify
# Notifier example from tutorial
#
# See: http://github.com/seb-m/pyinotify/wiki/Tutorial
#
import pyinotify
wm = pyinotify.WatchManager() # Watch Manager
mask = pyinotify.IN_DELETE | pyinotify.IN_CREATE # watched events
class EventHandler(pyinotify.ProcessEvent):
@aoshiman
aoshiman / twpost.py
Created June 28, 2013 12:33
Tweet via CUI
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tweepy import API, OAuthHandler
from pit import Pit
def main(post):
"""Function for OAuth Setting and Tweet"""
cconf = Pit.get('oauth_conf')
auth = OAuthHandler(cconf['consumer_key'], cconf['consumer_secret'])
@aoshiman
aoshiman / pp.py
Created August 26, 2013 08:19
Pythonでコマンドライン時のListやDictを整形して表示させる
# -*- coding: utf-8 -*-
import re, pprint
def pp(obj):
"""
PrettyPrint for Python list and Dict
Usage
>>> data = {u"spam" : u"スパム", u"ham" : u"ハム", u"eggs" : u"エッグス"}
>>> print pp(data)
@aoshiman
aoshiman / generate_totp.py
Last active December 28, 2015 06:59
sample script about totp
# -*- coding: utf-8 -*-
"""
This Script base on https://github.com/nathforge/pyotp
and http://yamatamemo.blogspot.jp/2011/06/oath-3.html
and http://stackoverflow.com/questions/8529265/ \
google-authenticator-implementation-in-python
サンプルで記載しているsecretはHexspeakの一種と認識
Dartでも使っていた
@aoshiman
aoshiman / conv2822to8601.py
Last active August 29, 2015 13:56
convert datetime format rfc2822 to iso8601
# -*- coding: utf-8 -*-
import sys
from email.utils import parsedate_tz, mktime_tz
from datetime import datetime
def conv_2822_to_8601(s):
time_tuple = parsedate_tz(s)
time_stamp = mktime_tz(time_tuple)
return datetime.fromtimestamp(time_stamp)
@aoshiman
aoshiman / twipost34.py
Last active August 29, 2015 14:06
Tweet via Twython(Python3.4)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from twython import Twython, TwythonError
from pit import Pit
def main(post):
"""Function for OAuth Setting and Tweet"""
oauth_conf = Pit.get('oauth_conf')
@aoshiman
aoshiman / threading_sample.py
Created October 2, 2014 08:26
threading モジュールを使ったサンプルスクリプト
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from time import time
from threading import Thread
"""
http://gihyo.jp/dev/serial/01/pythonhacks/0005
Python3 threading モジュールを使ったサンプル
"""