Skip to content

Instantly share code, notes, and snippets.

View chinghwayu's full-sized avatar

Ching-Hwa Yu chinghwayu

View GitHub Profile
@chinghwayu
chinghwayu / register_plugin.py
Created November 23, 2021 22:00
Registers a stevedore plugin dynamically without needing to install as a package
try:
# For python 3.8 and later
import importlib.metadata as importlib_metadata
except ImportError:
# For everyone else
import importlib_metadata
from stevedore import ExtensionManager
@chinghwayu
chinghwayu / generate_from_config.py
Last active November 14, 2019 22:20
Generating data from INI configuration files
from configparser import ConfigParser
def generate_data(filename, name):
"""This function read parameters from an ini file and generates data depending on the 'dtype' option."""
config = ConfigParser()
config.read(filename)
mode = config.get(name, "mode", fallback="discrete")
dtype = config.get(name, "dtype", fallback="string")
if mode == "discrete":
if dtype == "int":
@chinghwayu
chinghwayu / repl_cmdline_with_exceptions.py
Created January 21, 2019 19:30
Simple python REPL command line application with objects, list comprehension, zip, f-strings, and exceptions
class ConvertFunctions():
def f2c(self):
strtemps = input("Please enter your fahrenheit temperature(s): ")
ftemps = [float(ftemp) for ftemp in strtemps.split()]
ctemps = [(ftemp-32) * 5/9 for ftemp in ftemps]
for (ftemp, ctemp) in zip(ftemps, ctemps):
print(f"F:{ftemp:.2f} = C:{ctemp:.2f}")
def m2cm(self):
strm = input("Please enter the meters: ")
@chinghwayu
chinghwayu / repl_cmdline_app.py
Last active January 15, 2019 16:56
Simple python REPL command line application with objects, list comprehension, zip, and f-strings
class ConvertFunctions():
def f2c(self, ftemps):
return [(ftemp-32) * 5/9 for ftemp in ftemps]
def m2cm(self, lmeters):
return [meters*100 for meters in lmeters]
def main():
convert = ConvertFunctions()
while True:
' Perforce Jenkins Trigger Script
'
' This script is meant to be called from a Perforce trigger.
' It should be placed on the Perforce Server machine.
' See usage information below for more details.
'
' Adapted from swarm-trigger.vbs
'
'
' Prerequisites: