Skip to content

Instantly share code, notes, and snippets.

View gh640's full-sized avatar

Goto Hayato gh640

View GitHub Profile
@gh640
gh640 / Dockerfile
Last active May 5, 2021 06:29
Sample: Install Poetry in Dockerfile
FROM python:3.9-slim
ARG POETRY_VERSION="1.1.6"
# Install `poetry`.
ADD https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py /tmp/get-poetry.py
RUN python /tmp/get-poetry.py --version "${POETRY_VERSION}"
@gh640
gh640 / git_add_and_commit_directories.py
Last active March 24, 2021 04:05
サンプル: Git でサブディレクトリを個別にコミットする
import subprocess
DIRECTORIES = [
'dir_a',
'dir_b',
'dir_c',
]
@gh640
gh640 / useElementSize.js
Last active September 3, 2024 15:36
React hook to get size of an element
import { useState, useEffect, useRef } from 'react'
function useElementSize() {
const ref = useRef(null)
const [size, setSize] = useState({
width: 0,
height: 0,
})
useEffect(() => {
@gh640
gh640 / useWindowSize.js
Created March 15, 2021 11:34
React hook to get the reactive window size
import { useState, useEffect } from 'react'
function useWindowSize() {
const [windowSize, setWindowSize] = useState({
width: null,
height: null,
})
useEffect(() => {
const updateSize = () => {
@gh640
gh640 / simple-https-server.py
Created March 7, 2021 01:43
Sample: A simple https server with Python for development (Python 3.9+).
"""Simple https server for development."""
import ssl
from http.server import HTTPServer, SimpleHTTPRequestHandler
CERTFILE = './localhost.pem'
def main():
https_server(certfile=CERTFILE)
@gh640
gh640 / use_mysqltuner_in_mariadb_container.sh
Last active February 20, 2025 09:31
Sample: Use MySQLTuner in `mariadb` Docker container
# MySQLTuner: https://github.com/major/MySQLTuner-perl
# Open Bash with the container.
docker exec [mariadb_or_mysql] bash
# Change the working directory to `/tmp`.
cd /tmp
# Install wget.
apt-get update
@gh640
gh640 / list_all_database_sizes.sql
Last active December 4, 2021 08:20
List up large database tables in MySQL / MariaDB
-- All databases.
SELECT
table_schema AS `Database`,
ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS `Size in MB`
FROM information_schema.tables
GROUP BY `Database`
ORDER BY `Size in MB` DESC;
@gh640
gh640 / run_http_server.py
Last active February 10, 2021 01:45
Sample: Script to run a web server with a specified directory
#!python3
"""A script to run a web server with a specified directory and port."""
import socketserver
from functools import partial
from http.server import SimpleHTTPRequestHandler
from pathlib import Path
DIRECTORY = ...
PORT = 8001
@gh640
gh640 / generate_ssh_keys.sh
Created November 7, 2020 08:17
サンプルコード: SSH 鍵の生成
# SSH キーの生成
# See: https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
ssh-keygen -t ed25519 -C "your_email@example.com"
@gh640
gh640 / firestore2csv.py
Last active May 30, 2024 08:00
Sample: Script to export Firestore collection as CSV
"""Script to export Firestore collection as CSV."""
import csv
import sys
from pathlib import Path
from firebase_admin import credentials, firestore, initialize_app
CRED_FILE = Path(__file__).resolve().parent / 'firebase-privateKey.json'
COLLECTION_NAME = 'XXX'