Skip to content

Instantly share code, notes, and snippets.

View atsuoishimoto's full-sized avatar

Atsuo Ishimoto atsuoishimoto

View GitHub Profile
@atsuoishimoto
atsuoishimoto / load_djangoapp.py
Created October 31, 2023 13:02
manage.pyを使わずにdjangoアプリをロード
import sys, os, django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api_gateway.settings")
django.setup()
import pprint
import redis
def get_key(db, key):
type = db.type(key)
if type == 'list':
return db.lrange(key, 0, -1)
elif type == 'hash':
return db.hgetall(key)
elif type == 'set':
@atsuoishimoto
atsuoishimoto / timelog.py
Created July 23, 2019 04:57
measure time
import inspect, builtins, threading, time
import itertools
class _Section:
def __init__(self, log, ref, funcname, filename, lineno):
self._log = log
self._ref = ref
self._funcname = funcname
self._filename = filename
self._lineno = lineno
export $(cat .env | xargs)
@atsuoishimoto
atsuoishimoto / httpsv.py
Created April 24, 2019 10:46
the simplest http server
import http.server as h
class H(h.BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
self.wfile.write(b'hello')
h.test(H, port=8000)
@atsuoishimoto
atsuoishimoto / home-ishimoto-host.mount
Created January 16, 2019 01:39
systemd mount unit for virtualbox shared folder
# systemd-escape -p --suffix=mount /home/ishimoto/host
[Unit]
Description=VBox share
[Mount]
What=host
Where=/home/ishimoto/host
Type=vboxsf
[Install]
@atsuoishimoto
atsuoishimoto / caps2ctrl.py
Last active July 9, 2020 14:47
Map capslock to control
import winreg
key = 'System\\CurrentControlSet\\Control\\Keyboard Layout'
scancodemap = (b'\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00'
b'\x00\x00\x1d\x00:\x00\x00\x00\x00\x00')
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, key, access=winreg.KEY_WRITE) as h:
winreg.SetValueEx(h, 'Scancode Map', 0, winreg.REG_BINARY, scancodemap)
print('Registry updated. Reboot now.')
import logging
logger = logging.getLogger('xxx')
logging.lastResort.setLevel(logging.DEBUG) # <<<<<< コレ!
for lvl in (logging.DEBUG, logging.INFO,
logging.WARNING, logging.ERROR, logging.CRITICAL):
logger.setLevel(lvl)
print(logger.level)
@atsuoishimoto
atsuoishimoto / detect_globals.py
Created May 30, 2018 07:03
detect when global variable used
import types
class gdict(dict):
def __getitem__(self, key):
print(f'referring {key}')
return eval(key, globals())
def check(f):
return types.FunctionType(f.__code__, gdict())
@atsuoishimoto
atsuoishimoto / checkglobal.py
Created May 30, 2018 06:44
check if global variable used
import dis, builtins
def checkglobal(f):
for op in dis.Bytecode(f):
if op.opname == 'LOAD_GLOBAL':
if not hasattr(builtins, op.argval):
print(f"Referring global variable {op.argval}")
return f
@checkglobal