Skip to content

Instantly share code, notes, and snippets.

View jhrcook's full-sized avatar
🦖
Exploring!

Josh Cook jhrcook

🦖
Exploring!
View GitHub Profile
@jhrcook
jhrcook / app.sh
Created January 26, 2024 20:41
Remove all libraries installed in a Python environment
pip freeze | xargs pip uninstall -y
@jhrcook
jhrcook / shebangs.md
Created January 14, 2024 15:48
Shebangs

Python: #!/usr/bin/env python3

@jhrcook
jhrcook / dirichlet-regression-pymc.ipynb
Last active November 9, 2022 22:56
Dirichlet regression in PyMC
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python3
# How to get Typer to behave like it has a default command.
# source: https://github.com/tiangolo/typer/issues/18#issuecomment-617089716
import typer
app = typer.Typer()
@jhrcook
jhrcook / parsing_ounces.R
Created May 26, 2020 11:43
A function for parsing ounces into a numeric value.
# Parse a string given in "# #/# oz" into a decimal value.
parse_ounces <- function(val) {
if (val == "For glass") { return(1) }
if (str_detect(val, "or")) {
val <- str_remove(val, "or.+$")
}
val_pieces <- str_remove_all(val, "oz|slices|tsp|dash") %>%
str_trim() %>%
@jhrcook
jhrcook / EXAMPLE_CODE_FOR_BEN.ipynb
Last active January 27, 2020 01:51
A Jupyter Notbook showing an example for how to bootstrap a confidence interval.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jhrcook
jhrcook / boxplots_for_B.R
Last active December 12, 2019 16:45
Pivot a wide data frame and plot with facets.
library(tidyverse)
#### MAKING MOCK DATA ####
# Some parameters for amount of data.
n_metabs <- 5
n_tissues <- 10
tissues <- purrr::map_chr(1:n_tissues, ~ paste0(sample(letters, 3), collapse=""))
# Make a wide table of data, adding on columns per metabolite
# An empty directory.
mkdir empty-dir
# A directory with files to delete.
mkdir bar
touch bar/someFile.txt
# Delete files in "bar/"
rsync -a --delete empty-dir/ bar/
@jhrcook
jhrcook / integer_breaks_ggplot2.R
Created November 9, 2019 00:26
This is how to make the x or y axes only show integer values in a programmatic and scalable fashion.
# A function factory for getting integer y-axis values.
integer_breaks <- function(n = 5, ...) {
fxn <- function(x) {
breaks <- floor(pretty(x, n, ...))
names(breaks) <- attr(breaks, "labels")
breaks
}
return(fxn)
}

Here is how you can link to [a post]({{< ref "/post/some_post.md" >}}) in Academic Kickstarter for Hugo.