Skip to content

Instantly share code, notes, and snippets.

View sakurai-youhei's full-sized avatar

Youhei Sakurai sakurai-youhei

  • Kobe, Japan
View GitHub Profile
@sakurai-youhei
sakurai-youhei / pip_prog.py
Last active April 27, 2017 09:56
Run pip programmatically
from contextlib import contextmanager
from contextlib import redirect_stdout as r_stdout
from contextlib import redirect_stderr as r_stderr
from io import StringIO
import pip
def pip_exec(*args):
with StringIO() as stdout, StringIO() as stderr:
@sakurai-youhei
sakurai-youhei / export_pkey.py
Created June 12, 2017 04:40
Export private key from *.pfx file (PKCS12) into PEM format using pyOpenSSL
from OpenSSL import crypto
with open("path/to/cert.pfx", "rb") as pfx:
cert = crypto.load_pkcs12(pfx.read())
pkey = cert.get_privatekey()
with open("path/to/pkey.pem", "wb") as pem:
pem.write(crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey))
@sakurai-youhei
sakurai-youhei / pylpr.py
Created June 28, 2017 08:39
LPR client written in Python
"""\
License: MIT
See also:
- RFC 1179 - Line Printer Daemon Protocol
http://www.ietf.org/rfc/rfc1179.txt
- David Boddie's lpr.py (Thanks!)
http://www.boddie.org.uk/david/Projects/Python/lptools/lpr.py
"""
'''
License: GPL
https://www.ietf.org/rfc/rfc1759.txt
'''
from argparse import ArgumentParser
from collections import namedtuple
from enum import IntEnum
from functools import partial
@sakurai-youhei
sakurai-youhei / objview.py
Last active January 22, 2018 01:26
memoryview-like Python object view
from ctypes import c_ubyte
from ctypes import cast
from ctypes import POINTER
from sys import getsizeof
def objview(obj):
return cast(id(obj), POINTER(c_ubyte * getsizeof(obj))).contents
@sakurai-youhei
sakurai-youhei / build.py
Created June 28, 2018 08:55
WIP: Build MSI package deploying Windows service written in Python
from io import BytesIO
from msilib import add_tables
from msilib import init_database
from msilib import schema
from msilib import sequence
from os.path import abspath
from os.path import dirname
from os.path import normpath
from shutil import rmtree
from subprocess import check_call
@sakurai-youhei
sakurai-youhei / xte.py
Last active October 26, 2018 23:19
Python wrapper for xte command
"""
xte v1.09
Generates fake input using the XTest extension, more reliable than xse
Author: Steve Slaven - http://hoopajoo.net
usage: xte [-h] [-i xinputid] [-x display] [arg ..]
-h this help
-i XInput2 device to use. List devices with 'xinput list'
-x send commands to remote X server. Note that some commands
@sakurai-youhei
sakurai-youhei / sexy_barchart.py
Created October 26, 2018 22:55
Render HTML on the fly with QWebEngineView
from sys import argv
from sys import exit
from pygal import Bar
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QApplication
app = QApplication(argv)
view = QWebEngineView()
view.setHtml(Bar()(1, 3, 3, 7)(1, 6, 6, 4).render(True))
@sakurai-youhei
sakurai-youhei / screenshot.py
Created November 21, 2018 10:48
Taking screenshot of web page using QWebEngineView
from os.path import basename
from os.path import dirname
from os.path import join
import sys
from PyQt5.QtCore import Qt
from PyQt5.QtCore import QUrl
from PyQt5.QtCore import QTimer
from PyQt5.QtGui import QPixmap
from PyQt5.QtWebEngineWidgets import QWebEngineView
@sakurai-youhei
sakurai-youhei / problem-solving.md
Last active March 22, 2022 14:50
My principles in problem-solving

My principles in problem-solving

  • 50+% is done when understanding the problem well.
  • Every problem-solving SHOULD be a one-way journey.

Application to troubleshooting

  • 50+% is done when understanding the trouble well.
  • Every troubleshooting SHOULD be a one-way journey to identify what to be corrected.