This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html = ''' | |
<html> | |
<body> | |
Hello world | |
</body> | |
</html> | |
''' | |
for i in html.split('\n'): | |
if i.find('bo') > 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os.path import getsize | |
from os import rename | |
from datetime import datetime | |
srcnames = ['./logfile1', './logfile2'] | |
kb = 1024 | |
mb = kb * 1024 | |
def log_rotate(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
debug = True | |
print('debug1') if debug else '' | |
debug = False | |
print('debug2') if debug else '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twitter import Twitter, OAuth, TwitterHTTPError | |
# If you have twitter account, | |
# Register your app on https://dev.twitter.com so that you can get these information. | |
OAUTH_TOKEN = 'xxxx' | |
OAUTH_SECRET = 'xxxx' | |
CONSUMER_KEY = 'xxxx' | |
CONSUMER_SECRET = 'xxxx' | |
api = Twitter(auth = OAuth(OAUTH_TOKEN, OAUTH_SECRET, CONSUMER_KEY, CONSUMER_SECRET)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sqlite3 | |
conn = sqlite3.connect("sqlite3.db") | |
sql = "drop table test" | |
conn.execute(sql) | |
sql = """create table test ( | |
key int, | |
value varchar(20) | |
)""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import os | |
def main(args): | |
directory = args[1] | |
if len(args) > 2: | |
keyword = args[2] | |
else: | |
keyword = '' | |
file_list = os.listdir(directory) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cmd import Cmd | |
from sys import argv | |
import sqlite3 | |
import traceback | |
class SqliteCmd(Cmd): | |
dml = ['SELECT', 'INSERT', 'UPDATE', 'DELETE'] | |
def __init__(self, dbfile): | |
super().__init__() | |
self.conn = sqlite3.connect(dbfile) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import datetime | |
import os | |
# Get arguments without file name. | |
args = sys.argv[1:] | |
# Get current date time. | |
now = datetime.date.today() | |
for i in args: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat ltsv.log | |
host:127.0.0.1 user:- time:[08/Feb/2013:14:17:53 +0900] req:GET / HTTP/1.1 status:200 size:6 referer:- ua:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17 taken:41 | |
host:127.0.0.1 user:- time:[08/Feb/2013:14:17:53 +0900] req:GET /favicon.ico HTTP/1.1 status:404 size:6 referer:- ua:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17 taken:36 | |
$ awk -F \t '{print "---";for(i=1;i<=NF;i++) {match($i,":");print substr($i,0,RSTART-1) "\t", substr($i,RSTART+1);}}' ltsv.log | |
$ awk -F \t '/status:404/ {print "---";for(i=1;i<=NF;i++) {match($i,":");print substr($i,0,RSTART-1) "\t", substr($i,RSTART+1);}}' ltsv.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from sys import argv | |
f = open(argv[1], 'r') | |
table_name = f.readline().strip() | |
col_names = map(lambda x: x.strip(), f.readline().split(',')) | |
types = map(lambda x: x.strip(), f.readline().split(',')) | |
def func(t): | |
if t[1] == 's': | |
return (t[0], "'" + t[2] + "'") |
OlderNewer