Skip to content

Instantly share code, notes, and snippets.

View KentaYamada's full-sized avatar
👻
Working from home

YamaKen KentaYamada

👻
Working from home
View GitHub Profile
@KentaYamada
KentaYamada / question.py
Created June 21, 2022 09:16
初級問題
#
# [設問]ピッチャーのデータを分析するプログラムを作成してください
# 1. ピッチャーごとの平均球速を計算する関数を作成し、結果を表示してください
# 表示例) 田中将大の平均球速は154km/hです
# 補足: 小数点以下は「切り捨て」してください
# 2. ピッチャーごとの最高球速を計算する関数を作成し、結果を表示してください
# 表示例) 田中将大の最高球速は154km/hです
# 3. 最速のピッチャーは誰か計算する関数を作成し、結果を表示してください
# 表示例) 最速ピッチャーは田中将大、最高球速は156km/hです
#
@KentaYamada
KentaYamada / main.py
Last active May 16, 2020 08:54
Sample python watchdog
import time
import subprocess
from watchdog.events import PatternMatchingEventHandler
from watchdog.observers import Observer
class TestFileWatchEventHandler(PatternMatchingEventHandler):
def __run_test(self):
subprocess.call('python3 -m unittest discover ./tests', shell=True)
@KentaYamada
KentaYamada / main.py
Created May 4, 2020 08:25
Flask-JWT-Extended basic usage sample code
from flask import jsonify, request, Flask
from flask_jwt_extended import (
jwt_required,
create_access_token,
JWTManager
)
HTTP_OK = 200
HTTP_BAD_REQUEST = 400
HTTP_UNAUTHORIZED = 401
@KentaYamada
KentaYamada / dic_2_obj.py
Created December 8, 2019 03:17
Mapping dictionary to object
class CarMaker:
def __init__(self, id=None, name=''):
self.id = id
self.name = name
dict_car_maker = {
'id': 1,
'name': 'toyota'
}
@KentaYamada
KentaYamada / object_to_json.py
Created December 5, 2019 03:55
Convert object to json string
import json
def json_dumps_handler(data):
has_dict = isinstance(data, object) and hasattr(data, '__dict__')
if not has_dict:
raise TypeError()
return data.__dict__
@KentaYamada
KentaYamada / logging-config.json
Created June 2, 2019 07:41
python logging config from json
{
"version": 1.0,
"formatters": {
"simple": {
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
@KentaYamada
KentaYamada / rsync_quickrun.rc.vim
Last active May 17, 2019 04:35
vimproc quickrun rsync config
let g:quickrun_config = get(g:, 'quickrun_config', {})
let g:quickrun_config._ = {
\ 'runner': 'vimproc',
\ 'runner/vimproc/updatetime': 40,
\ 'outputter': 'error',
\ 'outputter/error/success': 'buffer',
\ 'outputter/error/error': 'quickfix',
\ 'hook/close_quickfix/enable_exit': 1
\ }
@KentaYamada
KentaYamada / server.py
Created May 11, 2019 14:02
Python3 flask JWT authorization example
from flask import jsonify, Flask
from flask_jwt import jwt_required, current_identity, JWT
class User:
def __init__(self, id, username, password):
self.id = id
self.username = username
self.password = password
@KentaYamada
KentaYamada / first_last_date.py
Created April 21, 2019 11:18
月初、月末の日付取得
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
today = datetime.now().date()
first_date = datetime.strptime(
datetime.strftime(today, '%Y-%m-01'),
'%Y-%m-%d'
).date()
last_date = first_date + relativedelta(months=1) - timedelta(days=1)
@KentaYamada
KentaYamada / expected_response.json
Last active December 23, 2018 08:25
Verify has many association of data mapping patterns.
"car_makers": [
{
"id": 1,
"name": 'TOYOTA',
"cars": [
{
"id": 1,
"name": 'カローラ'
},
{