Skip to content

Instantly share code, notes, and snippets.

View attakei's full-sized avatar

Kazuya Takei attakei

View GitHub Profile

FastAPI Middleware to forwarding hostname

Overview

FastAPI middleware to override Host header value by X-Forwarded-Host header value if it is exists.

FastAPI(Starlette) can make response used by X-Forwarded-Host header for slash-tailed redirection.

# Traial example for yandex-tank
## Usage
```bash
docker-compose run tank
```
@attakei
attakei / python_google_home_notify_ja.md
Last active November 23, 2020 13:56
Google home notifications by python

Pythonを使ってGoogle Homeに指定したテキストを喋らせる

使い方

  1. これをcloneする
  2. virtualenvを用意する
  3. pip install -r requirements.txtで依存パッケージをインストールする
  4. python server.pyでサーバーを起動する
  5. ブラウザで、サーバーにアクセスして、フォームにテキストと言語を指定して「喋る」ボタンを押す
  6. Google Homeが喋った!
@attakei
attakei / checkout_all_branches.py
Created December 30, 2017 01:17
Checkout all branches from 'origin'
#!/usr/bin/env python
"""Generated by act as 2017-12-30 09:57:20.386358
"""
import sys
import logging
from pathlib import Path
from git import Repo
Logger = logging.getLogger('checkout_all_branches')
@attakei
attakei / timer.plug
Last active September 6, 2017 10:19
Timer demo for errbot
[Core]
Name = Timer
Module = timer
[Documentation]
Description = Timer
import fire
class Calcurator(object):
def add(self, first, second):
return int(first) + int(second)
if __name__ == '__main__':
fire.Fire(Calcurator)
@attakei
attakei / kachidoki_elevator.cc
Created January 25, 2017 09:24 — forked from remore/kachidoki_elevator.cc
(1: 最適化問題) 下記パラメータのままでElevator::tick()のみを最適化して平均待ち人数を最小化する / (2: 並列化問題) 以下のプログラムをマルチスレッドで動作させると何倍早くなるか実装して検証する / (3: チューニング問題)並列化以外の方法で本プログラムの実行時間を短縮するためにどのような改修を加えるとよいか考察する
#include <iostream>
#include <iomanip>
#include <random>
#include <unistd.h>
using namespace std;
const int MAX_FLOOR = 14;
const int ELEVATOR_COUNT = 4;
const int RAISING_PROBABILITY = 10;
@attakei
attakei / once.py
Created October 25, 2016 14:10
Only once response HTTP server
#!/usr/bin/env python
from http.server import HTTPServer, SimpleHTTPRequestHandler
import signal
import sys
import os
class OnceHttpServer(HTTPServer):
def shutdown_by_signal(self, sig_num, frame):
self.server_close()
@attakei
attakei / tododemo.plug
Last active September 18, 2016 02:10
todo_demo
[Core]
Name = tododemo
Module = tododemo
[Python]
Version = 2+
[Documentation]
Description = Todo Demo
@attakei
attakei / README.md
Last active December 25, 2015 05:31
Get gitignore from github/gitignore

Fetch and merge gitignore from Github

It is tool to fetch gitignore contents from https://github.com/github/gitignore, merge fetched contents and generate local .gitignore file.

Usage

example)

$ curl https://gist.githubusercontent.com/attakei/98eb484cf013afd0d1ba/raw/f98b7ef8d87732363d2ccdb76ec9ef35151163d2/get_gitignore.py &gt; get_gitignore