Skip to content

Instantly share code, notes, and snippets.

View gh640's full-sized avatar

Goto Hayato gh640

View GitHub Profile
@gh640
gh640 / gcp_block_country.py
Created September 12, 2020 03:12
サンプルコード: Google Cloud Platform で特定の国からのアクセスをブロックするルールを作成するためのスクリプト
import argparse
import subprocess
CHUNK_SIZE = 256
# サポート対象の国の一覧
# キー: 国コード / バリュー: ルールのプリフィックス
COUNTRIES = {
'cn': 'block-china-',
'ru': 'block-russia-',
@gh640
gh640 / extract_sjis_zip.py
Created August 2, 2020 05:04
サンプルコード: Windows 等の SJIS 環境で作られた zip ファイルを文字化け無しで展開するサンプル
# For more information, see https://www.lifewithpython.com/2020/08/python-sjis-zip.html .
import zipfile
from pathlib import Path
from typing import List
SRC_ZIP = '日本語のファイル名を含む.zip'
DEST_DIR = 'out'
@gh640
gh640 / update-phpunit.md
Last active March 7, 2021 12:59
PHPUnit アップデート対応表

PHPUnit 5.x / 6.x → 9.x の場合:

変更前 変更後 コメント
assertInternalType(something, $actual) assertIsXXX($actual)
assertContains($needle, $heystack) assertStringContainsString($needle, $heystack) 文字列の場合
assertFileNotExists() assertFileDoesNotExist()
@expectedException class expectException(targetclass::class) 変更前はアノテーションコメント
@gh640
gh640 / aoiro.md
Created July 26, 2020 01:08
青色申告専従者給与 納期特例分 登録方法
  1. e-Tax ( WEB 版)にログイン
  2. "申告・申請・納税" を選択
  3. "新規作成" を選択
  4. "給与所得・退職所得等の所得税徴収高計算書(納期特例分)" を選択
  5. フォームに入力して送信
@gh640
gh640 / common.css
Last active July 31, 2020 04:29
プロジェクト共通の汎用 CSS テンプレート
html,
body {
color: '';
font-family: '';
font-size: 16px;
font-weight: '';
letter-spacing: '';
line-height: '';
}
@gh640
gh640 / extract_blogger_data_from_xml.py
Created July 7, 2020 05:08
サンプルコード: Blogger からエクスポートした XML からデータを抽出して Markdown に変換して保存するスクリプト
import asyncio
import re
from pathlib import Path
from typing import Dict, Generator, Iterable, List
from urllib.parse import urlparse
import aiofiles
import aiohttp
import html2markdown
from bs4 import BeautifulSoup
@gh640
gh640 / proxy.js
Created June 2, 2020 01:02
プロキシサーバーを走らせる
// プロキシサーバーを走らせる
//
// - 80 ポートへのリクエストを 8000 に流す例
// - `npm i http-proxy` を実行後にこのスクリプトを実行する
//
// See: https://github.com/http-party/node-http-proxy
var httpProxy = require('http-proxy');
console.log('Runninng on port 80...');
@gh640
gh640 / render_chart.py
Created June 1, 2020 09:26
サンプルコード: matplotlib.pyplot で出力するグラフのサイズを指定する
"""サンプルコード: matplotlib.pyplot で出力するグラフのサイズを指定する
次の 2 ステップでできる:
1. `fig.set_size_inches()` で DPI で割ったサイズを指定しておく
2. `pyplot.savefig()` で DPI を指定して出力する
"""
import matplotlib.pyplot as plt
import pandas as pd
@gh640
gh640 / renamer.py
Created May 23, 2020 08:59
特定のディレクトリの下の `png` ファイルのファイル名を一括で変更するスクリプト
"""特定のディレクトリの下の `png` ファイルのファイル名を一括で変更するスクリプト"""
from pathlib import Path
PARENT_DIR = Path(__file__).parent / 'rename'
STR_SRC = '.'
STR_DST = '_'
def main():
for file in png_files():
@gh640
gh640 / download_with_ftps.py
Created April 9, 2020 05:43
サンプルコード: FTPS で特定のディレクトリ以下のファイルを一式ダウンロードするスクリプト
"""FTPS で production サーバーのファイルをダウンロードするスクリプトのサンプル"""
from contextlib import contextmanager
from ftplib import FTP_TLS
from pathlib import Path
REMOTE_ROOT = 'xxx'
LOCAL_ROOT = Path('xxx')
ENCODING = 'utf-8'
FTP_CONFIG = {'host': 'xxx', 'user': 'xxx', 'passwd': 'xxx'}