Skip to content

Instantly share code, notes, and snippets.

@William-Hill
William-Hill / clone_no_ssl.sh
Created January 9, 2020 23:25
Disable SSL for single Git clone
git -c http.sslVerify=false clone https://example.com/path/to/git
@William-Hill
William-Hill / delete_branches.sh
Created October 14, 2018 16:46
Delete multiple branches in git
git branch -d `git branch --list '$1'`
@William-Hill
William-Hill / Dockerfile
Last active August 5, 2018 04:56
Dockerfile for creating a CentOS6 image bootstrapped for ESGF
# Use an official CentOS image
FROM centos:6
# Set the working directory to /home/hill119
WORKDIR /home/hill119
USER root
# Copy the current directory contents into the container at /home/hill119
ADD . /home/hill119
@William-Hill
William-Hill / dump_pylint_settings.sh
Created July 26, 2018 16:20
Change pylint settings
pylint --generate-rcfile > .pylintrc
@William-Hill
William-Hill / self_signed_cert.py
Created July 2, 2018 17:11
Create a self-signed cert using PyOpenSSL
def create_self_signed_cert(cert_dir):
"""
If datacard.crt and datacard.key don't exist in cert_dir, create a new
self-signed cert and keypair and write them into that directory.
Source: https://skippylovesmalorie.wordpress.com/2010/02/12/how-to-generate-a-self-signed-certificate-using-pyopenssl/
"""
CERT_FILE = "hostcert.pem"
KEY_FILE = "hostkey.pem"
@William-Hill
William-Hill / insert_dll.py
Created April 28, 2018 21:11
Insert into a sorted doubly linked list
def insert_between_nodes(current_node, new_node):
new_node.next = current_node.next
new_node.prev = current_node
current_node.next.prev = new_node
current_node.next = new_node
def SortedInsert(head, data):
new_node = Node(data)
current_node = head
@William-Hill
William-Hill / x509_subject_string.py
Created April 19, 2018 22:34
Get X509 subject name as string using Pyopenssl
import OpenSSL
def get_x509_subject_string(cert_name):
x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM, open(cert_name).read())
subject_components = x509.get_subject().get_components()
subject_string = ""
for component in subject_components:
subject_string = subject_string + "/" + component[0] + "=" + component[1]
@William-Hill
William-Hill / styles.css
Created February 11, 2018 16:54
Responsive background image
html{
width: 100vw; height: 100vh;
}
body {
width: 100vw;
height: 100vh;
/*Replace with some_image with image url/path*/
background: url("some_image.png");
background-repeat: no-repeat;
@William-Hill
William-Hill / styles.css
Created February 11, 2018 16:49
Responsively center text horizontally and vertically
/* source: https://stackoverflow.com/a/45275695/2154867 */
#text_container {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100vh; }
#text_container p {
margin: 0;
color: white;
@William-Hill
William-Hill / logging_setup.py
Created February 9, 2018 20:12
Python logging setup
'''My preferred logging setup to log the filename, line number, function name, and time in messages'''
import logging
logger = logging.getLogger('metrics_logger')
logger.setLevel(logging.DEBUG)
# create formatter
formatter = logging.Formatter("%(levelname)s - %(filename)s - %(lineno)s - %(funcName)s - %(asctime)s - %(message)s", datefmt='%m/%d/%Y %I:%M:%S %p')
# create console handler with a higher log level
console_handler = logging.StreamHandler()
console_handler.setFormatter(formatter)