This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, os, django | |
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "api_gateway.settings") | |
django.setup() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export $(cat .env | xargs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# systemd-escape -p --suffix=mount /home/ishimoto/host | |
[Unit] | |
Description=VBox share | |
[Mount] | |
What=host | |
Where=/home/ishimoto/host | |
Type=vboxsf | |
[Install] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder