Skip to content

Instantly share code, notes, and snippets.

View milescsmith's full-sized avatar

Miles Smith milescsmith

View GitHub Profile
@milescsmith
milescsmith / quoted_unquoted_argument.R
Created August 25, 2021 19:15
Handle both quoted and unquoted arguments to an R function
if (is.character(substitute(x))){
y <- rlang::sym(x)
} else {
y <- x
x <- as.character(substitute(x))
}
y <- rlang::enquo(y)
@milescsmith
milescsmith / gist:525aceea4b81198c4581d23fb3fd5695
Created December 23, 2020 03:05
Mapping Python numpy/scipy matrices to R matrices
https://github.com/theislab/anndata2ri/issues/8
wsl.exe --shutdown
cd C:\Users\smithm\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\
optimize-vhd -Path .\ext4.vhdx -Mode full
library(tidyverse)
library(lubridate)
library(ggrepel)
sars_stats <-
jsonlite::read_json(
path = "https://covidtracking.com/api/v1/us/daily.json",
simplifyVector = TRUE
) %>%
as_tibble() %>%
@milescsmith
milescsmith / fix_exfat_drive.md
Created July 14, 2020 05:17 — forked from scottopell/fix_exfat_drive.md
Fix corrupted exFAT disk macOS/OSX

exFAT support on macOS seems to have some bugs because my external drives with exFAT formatting will randomly get corrupted.

Disk Utility is unable to repair this at first, but the fix is this:

  1. Use diskutil list to find the right drive id.
  2. You want the id under the IDENTIFIER column, it should look like disk1s1
  3. Run sudo fsck_exfat -d <id from above>. eg sudo fsck_exfat -d disk1s3
  4. -d is debug so you'll see all your files output as they're processed.
  5. Answer YES if it gives you the prompt Main boot region needs to be updated. Yes/No?
@milescsmith
milescsmith / replace_format_with_f-string_style_strings.rst
Last active June 15, 2020 17:25
replace `format` with `f-string` style strings

Search

print\("([\s\S]+)\{0\}([\s\S]+)"\.format\(([\s\S]+)\),

Replacement

@milescsmith
milescsmith / fix_main_function_in_python.rst
Last active June 15, 2020 17:24
Fix the main entry point in python modules is main is implied by not defined

Search

if __name__ == "__main__":
    (from argparse import ArgumentParser[\s\S]*)$(?![\r\n])
@milescsmith
milescsmith / gist:2c4afcded739d38345f520a63d7357fa
Last active January 29, 2026 22:20
install python module from git where setup.py is in a subdirectory
pip install -e 'git://github.com/{ username }/{ reponame }.git@{ tag name }#egg={ desired egg name }&subdirectory={ subdir }'
or
pip install -e 'https://github.com/{ username }/{ reponame }.git@{ branch/tag name }#egg={ whatever }&subdirectory={ subdir }'
The key is those single quotes - without them, Bash ignores the subdirectory portion.
@milescsmith
milescsmith / brewbasictex
Created March 10, 2019 20:14 — forked from joethorley/brewbasictex
Install basictex using brew for R
brew tap caskroom/cask
brew cask install basictex
sudo tlmgr update --self
sudo tlmgr update --all
sudo tlmgr install titling framed inconsolata
docker run \
-v /home/USER:/workingdir \ # setup access to local folder inside container. Format is ABSOLUTE_LOCAL_PATH:CONTAINER_PATH
combinelab/salmon \ # maybe one does not always need to do this, but prefix with the container name
salmon alevin -lISR # run command as usual, using container paths
-1 /workingdir/LOCAL_FASTQ_SUBDIR/L00#_R1_001.fastq.gz \
-2 /workingdir/LOCAL_FASTQ_SUBDIR/L00#_R2_001.fastq.gz \
--chromium \
-i /workingdir/salmon \
-p8 \
-o /workingdir/lane# \