Skip to content

Instantly share code, notes, and snippets.

View amane-katagiri's full-sized avatar

Amane Katagiri amane-katagiri

View GitHub Profile
@amane-katagiri
amane-katagiri / SlackHandler.py
Last active March 15, 2017 03:39
Slack handler for the logging package for Python.
"""Slack handler for the logging package for Python."""
import json
from logging import DEBUG
from logging import Formatter
from logging import getLogger
from logging.handlers import HTTPHandler
class SlackHandler(HTTPHandler):
@amane-katagiri
amane-katagiri / email-protection.py
Created March 13, 2017 06:53
Implementation of "https?://some.domain.under.cdn.cloudflare.example.com/cdn-cgi/l/email-protection#{encoded_email_address}".
def protect_email(key: int, data: bytes) -> bytes:
return bytes([x ^ (key % 256) for x in b"\x00" + data])
def deprotect_email(data: bytes) -> bytes:
return bytes([x ^ data[0] for x in data[1:]])
def main():
import argparse
@amane-katagiri
amane-katagiri / ahaha.py
Last active August 9, 2017 13:18
"あは ぎょうざ あはは" one-liner.
print(" ".join(["あはは" + "は" * __import__("random").randint(0, 3) for x in range(int(abs(__import__("random").normalvariate(0, 2)) * 10 + 1))]), "あは ぎょうざ あはは")
@amane-katagiri
amane-katagiri / run.sh
Last active August 9, 2017 13:17
foregroundize script (useful in docker)
#!/bin/sh
trap 'echo "reload command"' HUP
trap 'echo "stop command"' EXIT
trap 'echo "stop command"; trap EXIT; exit 0' TERM INT
echo "start command which launches a background service and returns immediately"
while true; do sleep 3600 & wait; done

Keybase proof

I hereby claim:

  • I am amane-katagiri on github.
  • I am amane (https://keybase.io/amane) on keybase.
  • I have a public key whose fingerprint is 75CB B604 4ABF 0EA0 C15C 38E8 5642 D37E E532 097E

To claim this, I am signing this object:

@amane-katagiri
amane-katagiri / scrape.fish
Created May 27, 2017 06:16
pixiv scraping tool
#!/usr/bin/fish
function init_cookie
set LOGIN_URL "https://accounts.pixiv.net/login"
set TMP1 (mktemp)
set TMP2 (mktemp)
set TMP3 (mktemp)
if [ (count $argv) -ge 1 ]
set COOKIE $argv[1]
else
@amane-katagiri
amane-katagiri / lgtm.sh
Created June 5, 2017 07:08
LGTM movie maker
ffmpeg -i input.mp4 -filter_complex "drawtext=fontfile=/usr/share/fonts/truetype/mplus/mplus-1p-bold.ttf:text=LGTM:x=(w-text_w)/2:y=(h-text_h-line_h)/2:fontcolor=white:fontsize=200" output.mp4
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
r"""
Generate emoji list json file for mdx_unimoji(https://github.com/kernc/mdx_unimoji).
You can convert emoji_strategy.json on emojione (https://github.com/emojione/emojione) into
`{"ENTITY1": ["NAME1"], "ENTITY2": ["NAME2", "ALTERNAME2", ...], ...}`.
Usage:
$ ./emoji_generator.py https://raw.githubusercontent.com/Ranks/emojione/master/emoji_strategy.json
@amane-katagiri
amane-katagiri / cmake.sh
Last active August 9, 2017 13:15
Cmake flags for opencv and python3
mkdir release
cd release
cmake -DCMAKE_BUILD_TYPE=RELEASE -DWITH_TBB=YES -DWITH_EIGEN=YES -DBUILD_NEW_PYTHON_SUPPORT=ON -DBUILD_opencv_python3=ON \
-DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules \
-DCMAKE_INSTALL_PREFIX=~/usr/software/opencv_build \
-DPYTHON_EXECUTABLE=~/.pyenv/versions/mlc/bin/python3 \
-DPYTHON_LIBRARY=~/.pyenv/versions/3.5-dev/lib/libpython3.so ..
make -j8
make install
@amane-katagiri
amane-katagiri / twdel.py
Created September 5, 2017 16:12
Delete tweets.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from requests_oauthlib import OAuth1Session
CK = "CONSUMER_KEY"
CS = "CONSUMER_SECRET"
AT = "ACCESS_TOKEN"
AS = "ACCESS_SECRET"