Skip to content

Instantly share code, notes, and snippets.

View shiumachi's full-sized avatar

Sho Shimauchi shiumachi

View GitHub Profile
@shiumachi
shiumachi / hive_many_columns.py
Created September 2, 2016 02:54
create Hive table with 100K columns
COLS=100000
with open("/tmp/create_table_with_many_columns.hql", "w") as f:
f.write("CREATE TABLE many_cols_tbl (\n")
for i in xrange(COLS):
f.write("id%d INT,\n" % (i,))
f.write("last_id INT);\n")
@shiumachi
shiumachi / create_ansible_directory_layout.sh
Created September 4, 2015 02:16
Create Ansible Directory Layout Based on Ansible Document
#!/bin/bash
# Create Ansible directory layaout based on Ansible Documentation http://docs.ansible.com/ansible/playbooks_best_practices.html
#
# inventory file for production servers
touch production
# inventory file for staging environment
touch staging
@shiumachi
shiumachi / sentence_generator.py
Created June 4, 2014 15:56
簡単な文章を自動生成するWSGIサーバ
#! /usr/bin/env python3
import random
from wsgiref import simple_server
誰 = ['太郎', '二郎', '花子']
どこ = ['東京', '大阪', '名古屋']
どうした = ['泳いだ', '走った', '仕事した']
def pick(l):
@shiumachi
shiumachi / hipchatdump2csv.py
Last active February 15, 2017 19:22
convert hipchat message logs from json to csv.
# coding=utf-8
#
# hipchatdump2csv.py
#
# convert hipchat message logs from json to csv.
# csv format:
# from.name, from.user_id, date, message
#
# usage: python convert.py
#
@shiumachi
shiumachi / match_literal_text.py
Created February 3, 2014 11:55
制御文字や句読点にマッチする正規表現
import re
# ref: Regular Expression Cookbook p.26
text = """!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~
aaa
bbb
"""
@shiumachi
shiumachi / linecache_sample.py
Created January 29, 2014 01:59
テキストの任意の行を高速に読み込む
# http://docs.python.jp/2.7/library/linecache.html
import linecache
linecache.getline("test.txt", 10)
@shiumachi
shiumachi / readcsv.py
Created January 28, 2014 17:36
csvを読み込む
import csv
data_reader = csv.reader(open("./data.csv"))
for row_list in data_reader:
','.join(row_list)
@shiumachi
shiumachi / gist:8641812
Created January 27, 2014 01:19
Python3.3 で pysqlite をインストールしようとしたらうまくいかない

Python3.3 で pysqlite をインストールしようとしたらうまくいかない。 検索したけど、有効な解決策が見つからなかった。

% python -V
Python 3.3.3
% pip install pysqlite
Downloading/unpacking pysqlite
  Running setup.py egg_info for package pysqlite
@shiumachi
shiumachi / get_girls_senbatsu.py
Last active January 4, 2016 14:29
GF(仮) Wiki からセンバツボーナス一覧を取得し、標準出力に出力する。
# -*- coding: utf-8 -*-
"""
GF(仮) Wiki からセンバツボーナス一覧を取得し、標準出力に出力する。
以下のフォーマットの csv として出力する。
ガールNo, ガール名, ガールタイプ, 功セン1, 功セン2, 功セン3, 守セン1, 守セン2, 守セン3
事前準備
--------
@shiumachi
shiumachi / get_soup.py
Created January 26, 2014 14:10
指定したURLのBeautifulSoupオブジェクトを取得する(BeautifulSoup4版)
# -*- coding: utf-8 -*-
# requirement: lxml
import requests
from bs4 import BeautifulSoup
URL = "https://gist.github.com/"
def get_soup(url=URL):
""" get soup object of url.