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 f(num, max_num): | |
""" | |
num: くじを引く回数 | |
max_num: くじの総数 | |
""" | |
p = 1.0 | |
for i in xrange(num): | |
p = p * (float(max_num - i - 1) / (max_num - i)) | |
return p | |
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
[sho@demo]/opt/cloudera/parcels/CDH/share/hue% export HUE_APP_REG_DIR=/opt/cloudera/parcels/CDH/share/hue | |
[sho@demo]/opt/cloudera/parcels/CDH/share/hue% tools/app_reg/app_reg.py --list | |
Name Version Author Path | |
------------------ ------- --------------- ----------------------------------- | |
about 2.5.0 Hue ./apps/about | |
beeswax 2.5.0 Hue ./apps/beeswax | |
filebrowser 2.5.0 Hue ./apps/filebrowser | |
hbase 2.5.0 Hue ./apps/hbase | |
help 2.5.0 Hue ./apps/help | |
impala 2.5.0 Hue ./apps/impala |
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
% kaa | |
Traceback (most recent call last): | |
File "/Users/sho/.virtualenvs/py3/bin/kaa", line 9, in <module> | |
load_entry_point('kaaedit==0.26.1', 'console_scripts', 'kaa')() | |
File "/Users/sho/.virtualenvs/py3/lib/python3.3/site-packages/pkg_resources.py", line 352, in load_entry_point | |
return get_distribution(dist).load_entry_point(group, name) | |
File "/Users/sho/.virtualenvs/py3/lib/python3.3/site-packages/pkg_resources.py", line 2307, in load_entry_point | |
return ep.load() | |
File "/Users/sho/.virtualenvs/py3/lib/python3.3/site-packages/pkg_resources.py", line 2021, in load | |
entry = __import__(self.module_name, globals(),globals(), ['__name__']) |
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
# text converter | |
# source file: | |
# [string]: [string] | |
# convert to csv: | |
# [string],[string] | |
import sys | |
for line in sys.stdin: | |
name, word = line.rstrip().split(': ') |
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
# TOKEN, ROOM_NAME は適宜置き換え | |
# 事前に pip install hypchat でパッケージをインストールしておくこと | |
import hypchat | |
hc = hypchat.HypChat(TOKEN) | |
for i in hc.rooms()['items']: | |
if i['name'] == ROOM_NAME: | |
room = hc.get_room(i['id']) |
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 re | |
import sys | |
import logging | |
logging.getLogger().setLevel(logging.DEBUG) | |
d = {} | |
def count(line, word): | |
#logging.debug("line: {0}".format(line)) |
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
# sample of ast module | |
# reference: | |
# http://docs.python.jp/2.7/library/ast.html | |
# http://stackoverflow.com/questions/1515357/simple-example-of-how-to-use-ast-nodevisitor | |
import ast | |
import sys | |
import logging | |
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
date_string = "2014-01-05 22:20:50,307" | |
def convert_to_datetime(date_string): | |
""" input: %Y-%m-%d %H:%M:%S,%f | |
example: 2014-01-05 22:20:50,307 | |
return: datetime object | |
""" | |
date_format = "%Y-%m-%d %H:%M:%S,%f" | |
import datetime | |
return datetime.datetime.strptime(date_string, date_format) |
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
example = """2014-01-05 22:20:50,307 INFO org.apache.hadoop.hdfs.server.datanode.BlockPoolSliceScanner: Verification succeeded for BP-1337840909-192.168.0.1-1374311151785:blk_8462243608396789329_201176 | |
""" | |
def parse_datetime_and_level(line): | |
""" input: hadoop log | |
output: [datetime, loglevel, message] | |
""" | |
import re | |
r = re.compile("(^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}) ([A-Z]{4,5}) (.*)") | |
m = r.match(line) |
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 print_arr_right_aligned(arr): | |
""" input: string array ['a', 'ab', 'abc'] | |
output: None. print with right aligned. | |
a: | |
ab: | |
abc: | |
""" | |
len_a = max(map(lambda x: len(x), arr)) | |
for i in arr: | |
print("{0:>{1}}: ".format(i, len_a)) |