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 / move.py
Created January 24, 2024 03:10
move.py
import os
import shutil
from datetime import datetime
def move(suffix=None):
extension = suffix or 'jpg'
file_names = [f.name for f in os.scandir() if f.name.endswith(f'.{extension}')]
for file_name in file_names:
date_data = datetime.fromtimestamp(os.stat(file_name).st_mtime)
import os
import shutil
from datetime import datetime, date, timedelta
def get_next_date(base_date):
next_month = date(base_date.year, base_date.month, 1) + timedelta(days=35)
return date(next_month.year, next_month.month, 1)
import json
dictionary = {}
json.dumps(dictionary, indent=2, separators=(',', ': '), sort_keys=True)
@itkr
itkr / url.py
Created August 13, 2019 03:06
url.py
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
try:
from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse
except ImportError:
from urllib import urlencode
from urlparse import parse_qsl, urlparse, urlunparse
@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)]
@itkr
itkr / gitco.bash
Last active March 17, 2017 01:31
`fzf`を使ってヒストリーからコマンドを実行する
gitco() {
git checkout `git branch | peco | awk '{print $NF}'`
}
@itkr
itkr / pronama.cow
Created December 8, 2016 12:00
cows
##
## プロ生ちゃん
##
##
$the_cow = <<EOC;
$thoughts
$thoughts
` ` ` ` `` ` `
` ` ` ` ` ...J&ggmQHMHHHHNgg&J... `
` `..JgMMMH9UVOOllllllllllOVVWMMMHJ,.`` `
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
from __future__ import print_function
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()))
@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)