最近のホットな話題
class C:
def self.method( arg ):
self.value = arg
return self.value
というシンタックスシュガーを3.1で入れようかっていう話題。
self.method = lambda arg: foo(arg)
に似てていいじゃんってな意見もある。
ただ、そこから、Rubyチックにしろとかみんながすき放題言いまくって大盛況。
とりあえず、現時点ではまとめ人おつ。
class C:
def self.method( arg ):
self.value = arg
return self.value
self.method = lambda arg: foo(arg)
tailf log|iconv -feucjp -tutf8
tailf log|nkf -wu
tailf log|perl -MEncode -pe'$_=decode('eucjp',$_)'
tailf log|while read LINE;do echo $LINE|iconv -feucjp -tutf8;done
import sys
import urllib
def _reporthook(blocknum, bs, size):
sys.stdout.write("%4d%%\r"%(blocknum*bs*100/size))
sys.stdout.flush()
if __name__ == "__main__":
uri = sys.argv[1]
dest = uri[uri.rfind('/')+1:]
urllib.urlretrieve(uri, dest, _reporthook)
class Command(BaseCommand):
def handle(self, *args, **options):
daemon_kwargs = {}
daemon_kwargs['out_log'] = options.get('outlog', 'smtp_out.log')
daemon_kwargs['err_log'] = options.get('errlog', 'smtp_err.log')
from django.utils.daemonize import become_daemon
become_daemon(**daemon_kwargs)
foo = MySMTPServer((settings.EMAIL_HOST, settings.EMAIL_PORT),
(settings.PARENT_SMTP_HOST, settings.PARENT_SMTP_PORT))
try:
asyncore.loop()
except KeyboardInterrupt:
pass
class MySMTPServer(smtpd.SMTPServer):
def process_message(self, peer, mailfrom, rcpttos, data):
""" なんか素敵なことをする """
# SandS SpaceをShiftとして使う。押しっぱなしで取り消し
mod shift += !!space
key R-*Space = &Ignore
# 数字を記号と入れ替え
key _1 = $EXCLAMATION_MARK
key _2 = $QUOTATION_MARK
key _3 = $NUMBER_SIGN
key _4 = $DOLLAR_SIGN
key _5 = $PERCENT_SIGN
key _6 = $AMPERSAND
key _7 = $APOSTROPHE
key _8 = $LEFT_PARENTHESIS
key _9 = $RIGHT_PARENTHESIS
key _0 = BackSpace
key S-*_1 = _1
key S-*_2 = _2
key S-*_3 = _3
key S-*_4 = _4
key S-*_5 = _5
key S-*_6 = _6
key S-*_7 = _7
key S-*_8 = _8
key S-*_9 = _9
key S-*_0 = _0
# via t.masui
key semicolon = Enter
# 右下の\をセミコロンに
key BackSlash = semicolon
def ip_valid(addr):
for s in IP_RANGE:
t = s.split('/')
if len(t) == 1:
ip = t[0]
mask = '32'
else:
ip = t[0]
mask = t[1]
mask = int(mask)
n = ip2num(ip)
if ip2num(addr) & 2**32-(1<<32-mask) == n:
return True
return False
def ip2num(ip):
n = 0
for i in ip.split('.'):
n <<= 8
n += int(i)
return n
IP_RANGE = [
'210.153.84.0/24',
'123.108.237.9',
'202.179.204.0/24',
'61.202.3.0/24',
]