Skip to content

Instantly share code, notes, and snippets.

@rhoboro
rhoboro / yaml
Created May 3, 2024 02:41
multipass-docker.yaml
# Based on https://github.com/canonical/multipass-blueprints/blob/ae90147b811a79eaf4508f4776390141e0195fe7/v1/docker.yaml
apt:
sources:
docker:
source: |
deb https://download.docker.com/linux/ubuntu $RELEASE stable
key: |
-----BEGIN PGP PUBLIC KEY BLOCK-----
mQINBFit2ioBEADhWpZ8/wvZ6hUTiXOwQHXMAlaFHcPH9hAtr4F1y2+OYdbtMuth
@rhoboro
rhoboro / main.py
Last active December 18, 2023 09:15
Translate callback style API to async/await style API
import asyncio
from udp import DatagramReader, DatagramWriter, create_udp_client
async def listen_forever(writer: DatagramWriter, reader: DatagramReader) -> None:
while not writer.is_closing():
data = await reader.recv(2048)
print("Received:", data.decode())
@rhoboro
rhoboro / gistpy.py
Created October 25, 2020 06:08
gistpy is a sample module for trying to install from gist.
def func():
print("Success!!")
#! /bin/bash
if [ "$1" = "upgrade" ]; then
echo "updating..."
docker pull colorfulboard/bq_profile:latest --quiet > /dev/null
echo "done"
elif [ "$1" = "local" ]; then
docker run -it --rm -v ~/.config/gcloud:/root/.config/gcloud -v $(pwd):/usr/src/app colorfulboard/bq_profile:latest "${@:2:($#-1)}"
else
docker run -it --rm -v $(pwd):/usr/src/app colorfulboard/bq_profile:latest "$@"
@rhoboro
rhoboro / Dockerfile
Created August 17, 2019 12:40
Dockerfile for textlint
# 下記を参考にして作成したtextlint
# https://efcl.info/2015/09/10/introduce-textlint/
# docker run -it --rm -v $(pwd):/tmp -w /tmp textlint:0.1 *.md
FROM node:8-jessie
RUN npm i -g textlint
RUN npm i -g textlint-rule-max-ten textlint-rule-spellcheck-tech-word textlint-rule-no-mix-dearu-desumasu
ENTRYPOINT ["textlint", "--rule", "no-mix-dearu-desumasu", "--rule", "max-ten", "--rule", "spellcheck-tech-word"]
@rhoboro
rhoboro / extract_outline.py
Last active July 15, 2019 09:24
Markdownのアウトラインの抽出を行う
import sys
import unicodedata
MAX_LENGTH = 60
CHECK_ONLY_OUTPUT = False
def check_line(line):
if line.startswith('#'):
print(line, end='')
@rhoboro
rhoboro / create_doctestfile.py
Created June 12, 2019 11:51
Markdownのpythonコードブロックからdoctest実行用ファイルを作成する
"""
# 下記を実行するとコードブロックからdoctestファイル ham_doctest.py、egg_doctest.py を作成する
$ python3 create_doctestfile.py ham.md egg.md
# doctestは下記で実行可能
$ python3 ham_doctest.py
"""
import sys
@rhoboro
rhoboro / check.py
Created June 5, 2019 09:57
Markdownのコードブロック内の各行の長さがMAX_LENGTHを超えている場合のみその行を出力する
"""
$ python3 check.py xxx.md yyy.md
Markdownのコードブロック内の各行の長さがMAX_LENGTHを超えている場合のみその行を出力する
"""
import sys
import unicodedata
MAX_LENGTH = 60
CHECK_ONLY_OUTPUT = False
@rhoboro
rhoboro / Dockerfile
Last active March 16, 2019 03:08
リストとジェネレータのメモリ効率を比較
FROM python:3.7
WORKDIR /usr/src/app
RUN pip install psutil memory-profiler
COPY . .
RUN ./mkdummy.sh
ENTRYPOINT ["python", "-m", "memory_profiler", "copy_file.py"]
@rhoboro
rhoboro / delete_instance.py
Last active March 8, 2019 01:24
Stackdriverを使ってGCEインスタンスの長時間起動を抑制する
"""
Cloud Function: DeleteInstance
google-api-python-client==1.7.8
Environment Variable
AUTO_TOKEN: a value which is set in Stackdriver Notification WebHook
"""
import json
import os