Skip to content

Instantly share code, notes, and snippets.

View ShenZhouHong's full-sized avatar
📚
Reading interesting things

Shen Zhou Hong ShenZhouHong

📚
Reading interesting things
View GitHub Profile
@ShenZhouHong
ShenZhouHong / add-includes.sh
Last active December 30, 2023 08:53
Cronjob bash script that adds custom include directives to the nginx configuration of Cloudron apps.
#!/bin/bash
#
# Copyright (c) 2024 Shen Zhou Hong
# This code is released under the MIT License. https://mit-license.org/
#
# This Bash script checks if the line defined in $include_line is present
# in the Nginx configuration file at $nginx_config_file. If the line is not
# found, it appends the line before the last closing bracket and tests the
# configuration using 'nginx -t'. If the test succeeds, it reloads Nginx with
# 'systemctl reload nginx'.
@ShenZhouHong
ShenZhouHong / install-r-dependencies.sh
Created April 11, 2023 14:05
Bash script to install R, and R package dependencies on Ubuntu 22.04.
#!/usr/bin/env bash
#
# This bash script contains the minimal proceedure required to install a base R
# environment on Ubuntu 22.04. It is used as a part of the Vagrantfile
# provisioning process for a brand-new, Ubuntu 22.04 virtual machine. This
# script may also be ran as a part of a standalone process to download R on any
# Ubuntu or Debian operating system.
set -o errexit # abort on nonzero exitstatus
set -o nounset # abort on unbound variable
@ShenZhouHong
ShenZhouHong / pairwise-grid.py
Last active March 15, 2023 19:35
Utility function which graphs a pairwise comparison grid from pd.DataFrame inputs.
import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
def pairplot(
df: pd.DataFrame,
target: pd.Series,
names : Union[None, list[str]] = None,
size : Union[None, tuple[int, int]] = None,
cmap : mpl.colors.LinearSegmentedColormap = plt.cm.coolwarm,
@ShenZhouHong
ShenZhouHong / extract-img-from-pdf.sh
Created March 6, 2023 12:59
Bash script that extracts image files from PDFs in a directory
#!/bin/bash
# set the exit status to non-zero (failure) if any commands fail
set -e
# set the exit status to non-zero (failure) if any variable is referenced before being set
set -u
# set the shell to be more strict
set -o pipefail
function show_usage {
@ShenZhouHong
ShenZhouHong / file-download.py
Created March 6, 2023 12:59
Example file download routine for radiographs in the METRC PAIN study.
import os # To handle directory paths in a platform independent way
import requests.exceptions # To handle exceptions on download
import xml.etree.ElementTree as ET # To get additional information from request error
column_to_view: dict[str, str] = {
"cfu_xrayupload" : "antpr", # Anterio-posterior
"cfu_xrayuploadlat": "later", # Lateral-medial
"cfu_xrayuploadobl": "obliq", # Oblique
"cfu_xrayuploadaxi": "axial" # Axial
}
@ShenZhouHong
ShenZhouHong / greek-text.py
Created November 8, 2022 12:29
Python object representing a Perseids Treebank text
import xml.etree.ElementTree as ET
class Text:
"""
Object representation of a Ancient Greek text formatted in the Perseids XML schema.
See GAGDT (Guidelines for the Ancient Greek Dependecy Treebank) 2.0 for schema
information and additional metadata.
"""
def __init__(self, path: str) -> None:
self.path: str = path