Skip to content

Instantly share code, notes, and snippets.

Sho Shimauchi shiumachi

Block or report user

Report or block shiumachi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@shiumachi
shiumachi / README.md
Last active Aug 7, 2019
Bot Saying Migrate CLI
View README.md

saying migrate CLI

Usage

  • Copy the output of saying list from the source saying command.
  • Run the following command with pasting the copied outputs
$ python saying_migrate.py --from-saying foo --to-saying bar - <<EOM
(paste the copied text here)
EOM
@shiumachi
shiumachi / bot_commands.py
Created Apr 18, 2019
pyspa-bot: phonics, lower, upper command
View bot_commands.py
# phonics
ph = {"a": "アッ", "b": "バッ", "c": "カッ", "d": "ダッ", "e": "", "f": "フッ", "g": "グッ", "h": "ハッ", "i": "", "j": "ジャ", "k": "クッ", "l": "", "m": "", "n": "", "o": "", "p": "パッ", "q": "カッ", "r": "", "s": "", "t": "", "u": "ウッ", "v": "ヴッ", "w": "ウッ", "x": "クス", "y": "ヤッ", "z": ""}
arr = []
for a,b in ph.items():
arr.append(f'rsub("{a}", "{b}",')
result = ''.join(arr) + "{@1}"" + ')' * len(arr)
result
# upper
d = {}
@shiumachi
shiumachi / csv_to_parquet.py
Last active Dec 28, 2018
日付単位に分けられた複数のCSVファイルを月単位のParquetファイルに変換する
View csv_to_parquet.py
# This script compacts daily based csv files to monthly based parquet file.
# The CSV files should be named like "YYYY-MM-DD.csv" format.
#
# このスクリプトは日付毎のcsvファイルを月毎のparquetファイルに変換します。
# CSVファイルの名前は"YYYY-MM-DD.csv"の形式にしてください。
#
import pandas as pd
import numpy as np
import pyarrow as pa
@shiumachi
shiumachi / random_pick.py
Created Nov 29, 2018
return a random item in a list, which has different probability.
View random_pick.py
# -*- coding: utf-8 -*-
# Reference: Python Cookbook 2nd Ed. p.188
import random
def random_pick(item_list, probabilities):
""" return a random item in a list, which has different probability.
View get_sorted_dict_values.py
# -*- coding: utf-8 -*-
# Reference: Python Cookbook 2 Ed. p.198
def get_sorted_dict_values(d):
keys = d.keys()
keys.sort()
return [d[key] for key in keys]
View convert_to_datetime.py
import datetime
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"
View align.py
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))
View ast_sample.py
# 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
View add_date_to_log.py
from convert_to_datetime import convert_to_datetime
def add_date_to_log(line):
""" add YYMMDDhh to the beginning of the log.
Argument:
line (hadoop log line)
"""
arr = line.rstrip().split()
date_string = ' '.join(arr[0:2])
View hipchat-bot.py
# -*- coding: utf-8 -*-
import hypchat
import ConfigParser
import time
import random
import re
import sqlite3
# 設定のロード
You can’t perform that action at this time.