Skip to content

Instantly share code, notes, and snippets.

View tamanobi's full-sized avatar

Kohki YAMAGIWA tamanobi

View GitHub Profile
@tamanobi
tamanobi / send_file.bash
Last active January 31, 2024 03:35
他人にファイルを渡すときにめちゃくちゃ便利なやつ
#!/bin/bash
set -e
FILEPATH=$1
FILENAME=${FILEPATH##*/}
UUID=$2
# UUIDが未指定の場合、uuidgenで生成
if [ -z "$UUID" ]; then
@tamanobi
tamanobi / twitter.py
Last active November 30, 2023 14:00
Pocket API から取得した Twitter URL をもとにメディアを S3 に保存するやつ。ついでに XMP も仕込んでいる
import requests
from requests.exceptions import HTTPError
from pathlib import Path
import re
import boto3
from typing import List
import json
from libxmp import XMPFiles, XMPMeta, consts
import tempfile
@tamanobi
tamanobi / Makefile
Last active November 25, 2023 00:56
isucon
SHELL=/bin/bash
USER=$(shell whoami)
NOW:=$(shell date +%H:%M:%S)
BIN_NAME:=isuports
P_LANGUAGE=rust
SERVICE_NAME:=$(BIN_NAME).$(P_LANGUAGE).service
DB_PATH:=/etc/mysql
NGINX_PATH:=/etc/nginx
@tamanobi
tamanobi / graceful_shutdown.py
Last active December 27, 2022 02:42
Graceful shutdown on Python threading
import threading
import time
import requests
import queue
threads: list[threading.Thread] = []
stop_cue = queue.Queue(maxsize=1)
@tamanobi
tamanobi / decoder.py
Last active October 21, 2022 10:55
DTO や Entity などのクラス間をいい感じに変換する Decoder の構想
# coding: utf-8
from dataclasses import dataclass
class Result:
def __str__(self):
return f"<{self.__class__.__name__}: {self._value}>"
def is_ok(self) -> bool:
...
def ok(self):
@tamanobi
tamanobi / main.py
Last active June 15, 2022 07:27
inejctor の実験コード
from typing import Protocol
import injector
import os
class Repository(Protocol):
def get(id_: str) -> str: pass
def create(id_: str) -> str: pass
class RepoImpl(Repository):
@tamanobi
tamanobi / keybase.md
Created October 9, 2021 09:39
Keybase 認証のため

Keybase proof

I hereby claim:

  • I am tamanobi on github.
  • I am tamanobi (https://keybase.io/tamanobi) on keybase.
  • I have a public key ASCnK2TyB23ieP_TMncckI-5HcS5rqFu4z6qW_kjPqHFLQo

To claim this, I am signing this object:

@tamanobi
tamanobi / avro_cache.py
Last active September 19, 2021 17:10
DataFrame を AVRO としてキャッシュするデコレーター
# Copyright 2021 KOHKI YAMAGIWA
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
@tamanobi
tamanobi / main.js
Created April 28, 2021 00:39
Google フォームの回答時に回答コピーと、別のフォームURLを送信する機能
function getHeaders(sheet) {
var last_col = sheet.getLastColumn();
var range = sheet.getRange(1, 1, 1, last_col);
var headers = range.getValues();
return headers[0];
}
function getColumnNumByHeader(sheet, header) {
var n = getHeaders(sheet).indexOf(header);
if (n < 0) {
throw Error("ヘッダーが見つからなかった");
@tamanobi
tamanobi / register.js
Last active April 28, 2021 00:30
Google フォームに連番紹介コードを付与できる
function getHeaders(sheet) {
var last_col = sheet.getLastColumn();
var range = sheet.getRange(1, 1, 1, last_col);
var headers = range.getValues();
return headers[0];
}
function getColumnNumByHeader(sheet, header) {
var n = getHeaders(sheet).indexOf(header);
if (n < 0) {
throw Error("ヘッダーが見つからなかった");