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 / 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 / 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 / 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 / k.cmd
Last active June 23, 2020 06:28
K alias to kubectl command on Windows Command Prompt
@echo off
kubectl %*
exit /b %ERRORLEVEL%
@sakurai-youhei
sakurai-youhei / deviceready-brython.js
Last active July 3, 2020 10:58
Brython with Cordova
document.addEventListener('deviceready', brython, false);
@sakurai-youhei
sakurai-youhei / alldays_weekdays.py
Created December 3, 2020 06:52
All days & weekdays in Pandas
import pandas as pd
period = ("2020-01-01", "2020-12-31")
alldays = pd.date_range(*period, freq="D") # 期間中の毎日
weekdays = pd.date_range(*period, freq="B") # 期間中の月~金