Skip to content

Instantly share code, notes, and snippets.

@after-the-sunrise
after-the-sunrise / leveled_formatter.py
Created April 21, 2018 14:36
Python logging formatter with multiple formatters per logging level.
from logging import getLogger, Formatter, StreamHandler, DEBUG, ERROR
class LeveledFormatter(Formatter):
_formats = {}
def __init__(self, *args, **kwargs):
super(LeveledFormatter, self).__init__(*args, **kwargs)
def set_formatter(self, level, formatter):
@after-the-sunrise
after-the-sunrise / JKS to PEM
Last active March 1, 2023 15:34
Python SSL socket with PEM from JKS
# Check the alias
keytool -list -keystore ${MYKEY}.jks
# Export to PKCS12
keytool -importkeystore -srckeystore ${MYKEY}.jks -destkeystore ${MYKEY}.pkcs -srcstoretype JKS -deststoretype PKCS12 -alias ${MYALIAS}
# Convert to PEM
openssl pkcs12 -in ${MYKEY}.pkcs -out ${MYKEY}.pem
import logging
import time
import socket
from os import linesep
from queue import Empty, Queue
from socket import AF_INET, SOCK_STREAM
from threading import Thread, Lock
class socket_handler(object):
@after-the-sunrise
after-the-sunrise / replace.vbs
Created February 2, 2013 03:57
Script to replace specified property value. Usage : replace.vbs ${filename} ${key} ${value}
Option Explicit
Dim targetFile, propName, propValue
targetFile = WScript.Arguments(0)
propName = WScript.Arguments(1)
propValue = WScript.Arguments(2)
Dim objFS
Set objFS = CreateObject("Scripting.FileSystemObject")