Skip to content

Instantly share code, notes, and snippets.

Avatar

Ching-Hwa Yu chinghwayu

View GitHub Profile
@chinghwayu
chinghwayu / register_plugin.py
Created Nov 23, 2021
Registers a stevedore plugin dynamically without needing to install as a package
View register_plugin.py
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 Nov 14, 2019
Generating data from INI configuration files
View generate_from_config.py
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 Jan 21, 2019
Simple python REPL command line application with objects, list comprehension, zip, f-strings, and exceptions
View repl_cmdline_with_exceptions.py
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 Jan 15, 2019
Simple python REPL command line application with objects, list comprehension, zip, and f-strings
View repl_cmdline_app.py
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:
View jenkins-trigger.vbs
' 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: