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 / 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 / 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 / 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 / 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 / timetuple.py
Created April 16, 2015 07:19
timetuple
from datetime import datetime
import time
a = datetime.now()
# datetime.datetime(2015, 4, 16, 16, 15, 47, 92560)
b = int(time.mktime(a.timetuple()))
# 1429168547
datetime.fromtimestamp(b)
@itkr
itkr / template.html
Last active August 29, 2015 14:16
django template 日付
{{datetime_object|date:'n月j日 H:i'}}
@itkr
itkr / gist:4ca1d1070a6fa87ba6c7
Created January 23, 2015 15:19
cached_property
def cached_property(func):
@property
def f(self):
name = "_{}_cache".format(func.__name__)
if not hasattr(self, name):
setattr(self, name, func(self))
return getattr(self, name)
return f
alias fd='find ./ -type f -print | xargs grep'
@itkr
itkr / get3days.sql
Created August 18, 2014 06:38
日本時間を考慮して過去三日分のデータを取得する
select
id,
updated_at
from
foo_table
where
date(updated_at + interval 9 hour) between (current_date() - interval 3 day) and (current_date() - interval 1 day)
;
git log --no-merges --date=short --pretty='format:%h %cd %an%d %s' master...HEAD | cat