Skip to content

Instantly share code, notes, and snippets.

View itkr's full-sized avatar
:octocat:

Shota Itakura itkr

:octocat:
View GitHub Profile
@itkr
itkr / autohtmlformatter.py
Created May 25, 2015 07:23
Auto HTML Formatter
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import codecs
import sys
from bs4 import BeautifulSoup
def main(argv):
file_path = argv[1]
@itkr
itkr / ls.py
Last active August 29, 2015 14:22
python ls command
import commands
def ls(path):
return commands.getoutput('ls -m {}'.format(path)).replace('\n', '').split(', ')
ls('~')
@itkr
itkr / echo.py
Created June 11, 2015 03:39
echo.py
def echo(message, message_type=None):
colors = {
"OK": '\033[94m',
"SUCCESS": '\033[92m',
"WARNING": '\033[93m',
"FAIL": '\033[91m',
}
color = colors.get(message_type)
print "".join([color, message, '\033[0m']) if color else message
@itkr
itkr / format-python.py
Last active October 21, 2017 06:55
format-python.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import shlex
import subprocess
_env = None
@itkr
itkr / replace_csv_file.py
Created August 3, 2015 10:43
replace file
import csv
import os
def replace_csv_file(file_path, old_str, new_str):
count = 0
temp_path = '_' + file_path
with open(file_path, 'r') as read_file:
with open(temp_path, 'w') as write_file:
reader = csv.reader(read_file)
class TransformTools(object):
@staticmethod
def str_to_time(log_date_str):
DATETIME_FORMAT = '%Y/%m/%d %H:%M:%S'
return datetime.strptime(log_date_str, DATETIME_FORMAT)
@staticmethod
def datetime2epoch(target_datetime):
return int(time.mktime(target_datetime.timetuple()))
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
@itkr
itkr / pronama.cow
Created December 8, 2016 12:00
cows
##
## プロ生ちゃん
##
##
$the_cow = <<EOC;
$thoughts
$thoughts
` ` ` ` `` ` `
` ` ` ` ` ...J&ggmQHMHHHHNgg&J... `
` `..JgMMMH9UVOOllllllllllOVVWMMMHJ,.`` `
@itkr
itkr / gitco.bash
Last active March 17, 2017 01:31
`fzf`を使ってヒストリーからコマンドを実行する
gitco() {
git checkout `git branch | peco | awk '{print $NF}'`
}
@itkr
itkr / split_list.py
Last active March 21, 2019 07:17
リストを均等に分ける
import math
from typing import List
def split_list(_list, n) -> List[list]:
"""リストを均等に分ける"""
sp = [0] + [math.ceil(len(_list) / n * (i + 1)) for i in range(n)]
return [_list[sp[i]: sp[i + 1]] for i in range(n)]