Skip to content

Instantly share code, notes, and snippets.

@multimeric
multimeric / memory.md
Created March 14, 2024 00:24
Demonstration of odd memory usage in R whereby the resident set size (RSS) doesn't change despite allocating more memory and later clearing it
RSQLite::SQLite() |>
  DBI::dbConnect(":memory:") |>
  RSQLite::dbWriteTable("foo", data.frame(
  a = numeric(1E8)
))
invisible(gc())
ps::ps_memory_info()
@multimeric
multimeric / memory.Rmd
Last active March 13, 2024 23:15
Demonstration of odd memory usage in R whereby the resident set size (RSS) doesn't change despite allocating more memory and later clearing it
```{r}
RSQLite::SQLite() |>
DBI::dbConnect(":memory:") |>
RSQLite::dbWriteTable("foo", data.frame(
a = numeric(1E8)
))
invisible(gc())
ps::ps_memory_info()
y <- integer(1E8)
ps::ps_memory_info()
#' Installs one or more packages using the libraries inside a conda environment
#'
#' @param packages A vector of package names to install. This is the same as the
#' argument you would normally pass to `install.packages`
#' @param env The path to the conda environment that already has the dependencies installed into it
install_using_conda <- function(packages, env){
env <- normalizePath(env)
if (!"withr" %in% rownames(installed.packages())) install.packages("withr")
withr::with_envvar(
# Tell R where to find the pkgconfig
@multimeric
multimeric / install_relion.sh
Last active September 21, 2022 01:31
Installs Relion (https://github.com/3dem/relion) on MacOS
# Update this according to the GCC version you have from brew
GCC_VERSION=12
# You may update this to a later release from https://github.com/3dem/relion/releases
RELION_VERSION=3.1.3
brew install cmake gcc openmpi fltk fftw libx11 libtiff
export CXX=g++-$GCC_VERSION
export CC=gcc-$GCC_VERSION
export OMPI_CXX=g++-$GCC_VERSION
export OMPI_CC=gcc-$GCC_VERSION
require(purrr)
require(dplyr)
require(stringr)
#' Maps over the keys and values of a vector, but expects the function to return
#' a named vector with "key" and "value" entries. These will become the names
#' and values of the final vector. Think of this as like a Python dictionary
#' comprehension: it takes an iterable and produces a dictionary.
#'
#' @param l a vector to map over
#' @param func the function to apply over that vector, which must return a `list(key=?, value=?)`
@multimeric
multimeric / last_git_update.py
Created September 25, 2020 06:16
Returns the last date of update of a file in a git repo as a unix timestamp
import pathlib
from git import Repo
def last_git_update(path: pathlib.Path) -> int:
"""
Returns the last date of update as a unix timestamp, according to a git repo
"""
repo = Repo(path.parent, search_parent_directories=True)
commit = next(repo.iter_commits(paths=path))
return commit.authored_date
@multimeric
multimeric / spin.css
Created August 3, 2020 03:20
A simple CSS rule to make the entire page spin constantly in the browser
/*
Tells the body to apply the "spin" animation.
Change the `2s` to alter the speed.
Also change the selector from `body` to some other selector to target something else
*/
body {
animation: spin 2s infinite linear
}
/*
@multimeric
multimeric / discord_list_custom_emoji.js
Last active April 12, 2020 12:40
Produces a TSV (table) that lists all emoji on your server and their IDs
// Open up Sever Settings → Emoji in your browser
// Open the dev console using F12
// Paste the below script into the dev tools console
let str = "";
for (let emoj of document.querySelectorAll('div[class*=emojiRow][class*=card]')){
str += emoj.children[1].innerText;
str += '\t'
str += emoj.children[0].style['background-image'].replace('url("https://cdn.discordapp.com/emojis/', '').replace('.png?v=1")', '');
str += '\n'
}
// Open up Sever Settings → Emoji in your browser
// Open the dev console using F12
// Using the inspection tool, look for an element with the class .emojiRow-XXXX
// Edit the string ".emojiRow-zIc7ZX" below into whatever class you got from the previous script
// Paste the below script into the dev tools console
let str = "";
for (let emoj of $$('.emojiRow-zIc7ZX')){
str += emoj.children[1].innerText;
str += '\t'
str += emoj.children[0].style['background-image'].replace('url("https://cdn.discordapp.com/emojis/', '').replace('.png?v=1")', '');
// This script prints out a TCG order as a TSV (plain text spreadsheet that can be imported into Excel)
// Usage instructions:
// 1) Log in to your account and visit https://store.tcgplayer.com/myaccount/orderhistory
// 2) Type in the order number that you want printed out into the search bar
// 3) Open the dev console using F12
// 4) Click the "Console" tab in the top bar
// 5) Copy this entire script to your clipboard
// 6) Paste it into the console text box and press enter
// 7) A TSV (tab-separated value) table of your TCG Player order will be printed out