Skip to content

Instantly share code, notes, and snippets.

View tokibito's full-sized avatar

Shinya Okano tokibito

View GitHub Profile
@tokibito
tokibito / gist:767601
Created January 6, 2011 06:17
メール送信
# coding: utf-8
from optparse import OptionParser
import smtplib
from email.MIMEText import MIMEText
from email.Utils import formatdate
ENCODING = 'iso-2022-jp'
class GMailConnection(object):
def __init__(self, username, password):
@tokibito
tokibito / main.py
Created January 9, 2011 21:50
missing cache variable
# coding: utf-8
from google.appengine.ext.webapp import util
cachevar = None # キャッシュ用変数
def application(environ, start_response):
global cachevar
if cachevar is None:
msg = '%s'
cachevar = []
for i in range(10):
@tokibito
tokibito / gist:838472
Created February 22, 2011 10:20
MonthlyRotatingFileHandler
# coding: utf-8
import time
from datetime import datetime
from logging.handlers import TimedRotatingFileHandler
def get_next_month_first_day(now=None):
if not now:
now = datetime.now()
year = now.year
@tokibito
tokibito / basic_auth.py
Created May 25, 2011 01:00
basic auth middleware
AUTH_RESPONSE_BODY = """<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html lang="ja">
<head>
<title>401 Authorization Required</title>
</head>
<body>401 Authorization Required</body>
</html>"""
def auth_required_app(environ, start_response, relm):
start_response('401 Authorization Required', [
@tokibito
tokibito / aodag.scaffold.completion.sh
Created July 5, 2011 04:46
bash completion for aodag.scaffold
_comp_scaffold() {
local cur prev lst
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
lst=`scaffold list|xargs echo`
COMPREPLY=()
if [[ "$prev" == create* ]]; then
COMPREPLY=( $(compgen -W '${lst}' $cur) );
return 0;
fi
@tokibito
tokibito / setup-network
Created July 29, 2011 06:47
network setup script
#!/usr/bin/env python
# coding:utf8
import os
import sys
FILE_HOSTNAME = '/etc/hostname'
FILE_HOSTS = '/etc/hosts'
FILE_NETWORK = '/etc/network/interfaces'
CMD_RESTART_NETWORK = 'ifdown eth0&&ifup eth0'
import socket
def get_host_name(s):
for line in s.splitlines():
if line.startswith('Host:'):
return line[6:]
def host_to_ip(s):
return socket.getaddrinfo(s, 80)[0][4][0]
import socket
def get_host_name(s):
for line in s.splitlines():
if line.startswith('Host:'):
return line[6:]
def host_to_ip(s):
return socket.getaddrinfo(s, 80)[0][4][0]
@tokibito
tokibito / gist:1215795
Created September 14, 2011 03:27
helloworld
ほげは「真」
もし、ほげが「真」ならば
「こんちには世界」と表示
import socket
def get_host_name(s):
for line in s.splitlines():
if line.startswith('Host:'):
return line[6:]
def host_to_ip(s):
return socket.getaddrinfo(s, 80)[0][4][0]