Skip to content

Instantly share code, notes, and snippets.

import math
import numpy as np
from matplotlib import pyplot as plt
def webMercatorToLngLat(mx: float, my: float) -> tuple[float, float]:
lng = (mx * 2 - 1) * 180.0
lat = (my * 2 - 1) * 180.0
lat = (
-180
@ciscorn
ciscorn / plot_ses_send_stats.py
Created October 24, 2021 12:25
Plot Amazon SES Send Statistics
import boto3
from datetime import datetime, timedelta
import zoneinfo
import pandas
from matplotlib.dates import DateFormatter
import matplotlib.pyplot as plt
JST = zoneinfo.ZoneInfo("Asia/Tokyo")
@ciscorn
ciscorn / unicode_normalization.md
Last active September 27, 2021 21:25
Normalizing Unicode strings in Python / Go / Rust

Normalizing Unicode strings in Python / Go / Rust

NFC, NFD, NFKC, NFKD

input:

it’säå(1−2)ドブロク㍿

result:

@ciscorn
ciscorn / go-tour-web-crawler-without-mutex.go
Last active September 25, 2021 06:53
A Tour of Go: Exercise: Web Crawler without Mutex (https://tour.golang.org/concurrency/10)
package main
import (
"fmt"
)
type Fetcher interface {
Fetch(url string) (body string, urls []string, err error)
}
@ciscorn
ciscorn / circuitpython_compression.py
Last active June 27, 2023 19:21
[PoC] A more effective compression algorithm for CircuitPython's i18n strings. (merged)
from collections import Counter
import re
import huffman
class TextSplitter:
def __init__(self, words):
words.sort(key=lambda x: len(x), reverse=True)
self.words = set(words)
@ciscorn
ciscorn / matplotlib_animation_wave.py
Last active December 12, 2022 04:07
matplotlib animation:: 1-d & 2-d wave equation
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.pylab import plt
from matplotlib import animation, cm
import numpy as np
from scipy.signal import convolve, convolve2d
class Wave1D:
K = np.array([1, -2, 1])
@ciscorn
ciscorn / epub_pagertl.py
Created September 22, 2018 03:01
EPUBの見開き方向を right-to-left (縦書き用) に変える
import sys
from zipfile import ZipFile
import lxml.etree as et
for path in sys.argv[1:]:
zf = ZipFile(path, mode='a')
with zf.open('OEBPS/content.opf', mode='r') as f:
doc = et.parse(f)
@ciscorn
ciscorn / install_pillow_simd.sh
Created May 4, 2018 07:50
Install pillow-simd on Ubuntu
#!/bin/env bash
pip3 uninstall pillow
apt install \
libjpeg-turbo8-dev \
zlib1g-dev \
libtiff5-dev \
liblcms2-dev \
libfreetype6-dev \
@ciscorn
ciscorn / rewrite_rp.py
Last active May 7, 2017 00:30
Edit the ReplicaReplacement value of Seaweedfs's dat file.
import sys
import mmap
# usage:
# $ python3 rewrite_rp.py 1.dat 001
with open(sys.argv[1], 'rb+') as f:
with mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_WRITE) as m:
(curr_rp, new_rp) = (m[1], int(sys.argv[2]))
print("{0:03d} -> {1:03d}".format(curr_rp, new_rp))
@ciscorn
ciscorn / joetsu_merger.dot
Created March 23, 2016 06:58
上越市合併の変遷(仮)
digraph joetsu_merge {
graph [rankdir = LR];
"下ノ郷村" -> "金谷村";
"北大崎村" -> "金谷村";
"金谷村" -> "高田市\n(1954)";
"新道村" -> "高田市\n(1954)";
"高田町" -> "高田町\n(1908)";
"高城村" -> "高田町\n(1908)";