Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""PDF にした Amazon の領収書から「注文日」「注文番号」「請求総額」を取り出すやつ
# 下準備
$ pip install pymupdf click
# 使い方
$ python amznreceipt.py -f <pdf-filepath>
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""関数の中でグローバル変数を使えなくするデコレータ"""
from typing import List
from typing import Dict
from typing import Optional
from typing import Callable
from typing import Any
>>> def wrap(f):
...     # NOTE: self は args[0] に入る
...     def _wrap(*args, **kwargs):
...         print('Before')
...         res = f(*args, **kwargs)
...         print('After')
...         return res
...     return _wrap
... 
@momijiame
momijiame / Vagrantfile
Last active November 13, 2023 07:58
Vagrantfile for Hadoop (3.3) Cluster with Hive (3.1)
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :master, primary: true do |master|
master.vm.box = "bento/centos-7"
@momijiame
momijiame / Vagrantfile
Last active November 20, 2020 00:21
Vagrantfile for Spark 2.3 on YARN with CentOS 7 and Hadoop 2.8 (3 hosts)
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :master, primary: true do |master|
master.vm.box = "bento/centos-7.4"
@momijiame
momijiame / Vagrantfile
Last active June 26, 2021 12:07
Vagrantfile for Hadoop Cluster with CentOS 7 and Hadoop 2.8.0 (3 hosts)
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.define :master, primary: true do |master|
master.vm.box = "bento/centos-7.3"
@momijiame
momijiame / eventletecho.py
Created March 28, 2017 08:08
Eventlet を使って実装したエコーサーバ
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# 標準ライブラリにモンキーパッチを当てる
# ブロッキング I/O を使った操作が裏側で全てノンブロッキング I/O を使うように書き換えられる
import eventlet
eventlet.monkey_patch()
def client_handler(clientsocket, client_address, client_port):
@momijiame
momijiame / asyncioecho.py
Created March 28, 2017 08:06
asyncio の低レイヤーな API で書いたエコーサーバ
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
import socket
# イベントループに使うオブジェクトを用意する
ev_loop = asyncio.get_event_loop()
# 接続してきたクライアントとの接続情報を格納する
connections = {}
@momijiame
momijiame / td.py
Created January 3, 2017 11:39
t 分布
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from scipy import stats
from matplotlib import pyplot as plt
def main():
x = np.arange(-4, 4.1, 0.1)
@momijiame
momijiame / gnd.py
Created January 2, 2017 19:01
正規分布を描く
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
from matplotlib import pyplot as plt
def main():
x = np.arange(-5, 5.1, 0.1)
y = np.exp(-x ** 2 / 2) / np.sqrt(2 * np.pi)