Skip to content

Instantly share code, notes, and snippets.

View markdouthwaite's full-sized avatar

Mark Douthwaite markdouthwaite

View GitHub Profile
"""
The MIT License
Copyright (c) 2020 Mark Douthwaite
"""
import time
import multiprocessing as mp
from tqdm import tqdm
@markdouthwaite
markdouthwaite / send_email.py
Created July 7, 2020 17:22
Send an email using GMail to one or more recipients.
"""
MIT License
Copyright (c) 2018-2020 Mark Douthwaite
Send Email Snippet
------------------
Send an email from a given account to a target set of recipients.
@markdouthwaite
markdouthwaite / container_cpu_count.py
Last active July 16, 2020 11:09
Count the number of CPUs available to a process. In the case of containers (e.g. Docker) this will detect resources available to the container -- not the host machine.
"""
The MIT License
Copyright (c) 2020 Mark Douthwaite
Count the number of available CPUs to a process. In the case of containers (e.g. Docker)
this will detect resources available to the container -- not the host machine.
Note: in cases where _fractional_ CPU values are detected, this will _round up_ to the
nearest integer value.
@markdouthwaite
markdouthwaite / load_dotenv.sh
Created September 2, 2020 06:40 — forked from mihow/load_dotenv.sh
Load environment variables from dotenv / .env file in Bash
if [ ! -f .env ]
then
export $(cat .env | xargs)
fi
@markdouthwaite
markdouthwaite / load_dotenv.sh
Created September 2, 2020 06:40
A simple little `bash` script for loading environment variables from dotenv files. Based on [this](https://gist.github.com/mihow/9c7f559807069a03e302605691f85572)
if [ -f .env ]
then
export $(cat .env | sed 's/#.*//g' | xargs)
fi
@markdouthwaite
markdouthwaite / vectorized_sample_index.py
Last active October 11, 2020 10:49
Sample a single index for each unique element in a _sorted_ array of integers. See docstring for more detail.
def sample_index(arr: ndarray) -> ndarray:
"""
Given an *ordered* array of non-negative integers, randomly select one index for
each unique element.
Parameters
----------
arr : ndarray
An ordered array of integers.
@markdouthwaite
markdouthwaite / read_hdf5_array.go
Last active October 27, 2020 22:02
A simple Go module for reading a single array of 64 bit floating point numbers from a HDF5 formatted file.
package main
import (
"gonum.org/v1/hdf5"
)
// load a scalar-valued variable of type int from an attribute of the given name on the given dataset.
func getIntScalarAttr(dataset *hdf5.Dataset, attrName string) int {
var value int
@markdouthwaite
markdouthwaite / write_hdf5_array.go
Last active November 5, 2020 11:00
A simple Go module for writing a single array of 64 bit floating point numbers to a HDF5 formatted file (with attributes).
package main
import (
"fmt"
"gonum.org/v1/hdf5"
"math/rand"
"time"
)