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
def three_times(num): | |
""" | |
>>> three_times(-1) | |
-3 | |
>>> three_times(0) | |
0 | |
>>> three_times(1) | |
3 | |
>>> three_times(3) | |
9 |
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
<?xml version="1.0" ?> | |
<project default="main" basedir="/path/to"> | |
<target name="main" depends="begin, A0001, B0001, C0001, end"> | |
</target> | |
<target name="begin"> | |
<echo> | |
Begin execute jobnet. | |
</echo> | |
</target> |
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 subprocess import * | |
import sys, re | |
keyword = sys.argv[1] | |
(stdo, stde) = Popen(['ps'], stdout=PIPE).communicate() | |
lines = [j for i,j in enumerate(stdo.decode().split('\n')) if i > 0] | |
r = re.compile(r'\s+') | |
print('keyword', keyword) | |
for line in lines: | |
l = r.split(line.strip()) | |
if len(l) > 1 and l[3].find(keyword) >= 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
# 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] + "'") |
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
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
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 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
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
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)) |