Skip to content

Instantly share code, notes, and snippets.

View dmyersturnbull's full-sized avatar

Douglas Myers-Turnbull dmyersturnbull

  • Stanford University
  • Stanford, CA
View GitHub Profile
@dmyersturnbull
dmyersturnbull / groupyby_parallel.py
Last active February 6, 2024 00:43
Performs a Pandas groupby operation in parallel
import pandas as pd
import itertools
import time
import multiprocessing
from typing import Callable, Tuple, Union
def groupby_parallel(
groupby_df: pd.core.groupby.DataFrameGroupBy,
func: Callable[[Tuple[str, pd.DataFrame]], Union[pd.DataFrame, pd.Series]],
num_cpus: int = multiprocessing.cpu_count() - 1,
@dmyersturnbull
dmyersturnbull / ExitStatus.java
Created January 26, 2024 22:02
Recommended Linux exit codes as Java constants
/**
* Recommended exit codes from {@code /usr/include/sysexits.h}.
*/
public final class ExitStatus {
public static final int OK = 0;
public static final int GENERIC_ERROR = 1;
public static final int BASE = 64;
public static final int USAGE = 64;
public static final int NO_DATA = 65;
public static final int NO_INPUT = 66;
@dmyersturnbull
dmyersturnbull / .gitignore
Created October 25, 2023 23:48 — forked from braindevices/#btrfs benchmark for daily used desktop OS
which file sytem to use for daily work? should we turn on btrfs compression?
*.backup
/data
[metadata]
description-file = "README.md"
[build-system]
requires = ["poetry>=1.0", "coverage[toml]"]
build-backend = "poetry.masonry.api"
#########################################################################################
# Poetry metadata
@dmyersturnbull
dmyersturnbull / fancy_cmaps.py
Created May 5, 2020 01:28
Nice extra colormaps for matplotlib.
class FancyCmaps:
"""
Useful colormaps for matplotlib. Most importantly:
- white_red
- white_blue
- blue_white
- white_black
The built-in matplotlib ones don't actually go between pure color values!!
For ex, 'Greys' doesn't go from pure white to pure black!
So colormaps to consider avoiding include Greys, Blues, Greens, (etc), bwr, and seismic.
@dmyersturnbull
dmyersturnbull / paperpile_latex.py
Created May 20, 2020 19:52
Converts PaperPile's parenthetical citations to LaTeX \autocite calls.
import argparse, sys, re, logging
from pathlib import Path
from typing import Mapping, Any, Sequence, Collection
from typing import Tuple as Tup
logger = logging.getLogger('paperpile-latex')
class Paperpiler:
@dmyersturnbull
dmyersturnbull / http_status_codes.json
Created May 20, 2020 19:50
JSON file of HTTP status codes, with code, phrase, description, spec, and href.
[
{
"code": "100",
"phrase": "Continue",
"description": "The initial part of a request has been received and has not yet been rejected by the server.",
"spec_title": "RFC7231#6.2.1",
"spec_href": "https://tools.ietf.org/html/rfc7231#section-6.2.1"
},
{
"code": "101",
@dmyersturnbull
dmyersturnbull / format_bibfile.py
Created May 20, 2020 19:48
Make my BibTeX file a little less stupid. Fix UTF, don't break in weird places, and don't list DOIs as URLs.
import sys
import re
from pathlib import Path
def fix(path: Path, accent_file: Path, output_path: Path) -> None:
"""
Reformat my bib file.
* Remove PMC and DOI URLs because they're listed as IDs anyway.
* Replace accent-like escape characters with their UTF equivalents. I mean, it's 2020.
@dmyersturnbull
dmyersturnbull / Rfc3986Escaper.java
Created May 19, 2020 21:30
Escape Rfc3986 or an arbitrary set of characters with arbitrary rules.
See https://github.com/dmyersturnbull/genomics-io/tree/master/core/src/main/java/org/pharmgkb/parsers/escape
package org.pharmgkb.parsers.escape;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.NotThreadSafe;
import javax.annotation.concurrent.ThreadSafe;
@dmyersturnbull
dmyersturnbull / HttpHeadResponse.java
Created May 19, 2020 21:27
Elegant wrapper around an HTTP HEAD response in Java. Parse dates correctly.
// copied from https://github.com/dmyersturnbull/genomics-io/blob/master/core/src/main/java/org/pharmgkb/parsers/utils/HttpHeadResponse.java
package org.pharmgkb.parsers.utils;
import com.google.common.collect.ImmutableMap;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.Immutable;
import java.io.IOException;
import java.net.HttpURLConnection;