Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
# coding: utf-8
"""
./whitening.py ~/Downloads/xxx/
"""
from __future__ import unicode_literals
from __future__ import print_function
import argparse
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
画像がモノクロか判断
"""
from __future__ import print_function
import numpy
@ytyng
ytyng / ssl_sert_expires.py
Created December 1, 2015 01:59
get ssl cert expires as timedelta
#!/usr/bin/env python
# thanks: http://qiita.com/uemura/items/a3a0937f77494e62213c
import sys
import re
import subprocess
import datetime
@ytyng
ytyng / decorators.py
Last active November 27, 2015 01:02
Django マネジメントコマンドの重複起動防止デコレータ
def find_process_ids(pattern):
"""
pattern にマッチするプロセスIDを探して返す (自分以外)
:rtype: list
"""
self_pid = os.getpid()
try:
out = subprocess.check_output(['pgrep', '-f', pattern])
return list(filter(
lambda x: x != self_pid, map(int, out.splitlines())))
<?php
/**
* 処理結果をインスタンス変数にキャッシュする機能を提供するトレイト
* *
* python の @cached_property のように使うのを想定。
*
* 引数がある関数の場合は基本的に考慮していないが、がんばってキーを作れば機能するだろう。
*
* class HogeClass {
*
"""
キャッシュ時間計測
- ローカル:
- FileBased: 21.2
- LocMem: 0.8
- Dev:
- FileBased: 4.0
- Redis(Local): 5.4
import time
import threading
from queue import Queue
class ThreadPool(object):
def __init__(self, pool_size=10):
self.pool_size = pool_size
self.jobs = []
self.job_queue = Queue()
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import threading
try:
from django.utils.functional import cached_property
except ImportError:
cached_property = property
import json
import textwrap
import base64
from Crypto.Signature import PKCS1_v1_5
from Crypto.Hash import SHA
from Crypto.PublicKey import RSA
class GooglePlayReceiptValidator(object):
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
GPIO.setup(12, GPIO.OUT)
p = GPIO.PWM(12, 50) # channel=12 frequency=50Hz
p.start(0)