Skip to content

Instantly share code, notes, and snippets.

View jansim's full-sized avatar
🚀

Jan Simson jansim

🚀
View GitHub Profile
@jansim
jansim / embedFontsInDir.R
Created April 24, 2024 09:00
R Script to embed fonts in PDFs
# Set the directory containing the PDF files
pdf_directory <- "path/to/dir/with/pdfs"
# Get a list of all PDF files in the directory
pdf_files <- list.files(path = pdf_directory, pattern = "\\.pdf$", full.names = TRUE)
# Iterate through each PDF file and embed fonts
for (pdf_file in pdf_files) {
print(paste("Embedding fonts in:", pdf_file))
@jansim
jansim / update-reverse-dependencies.md
Created July 3, 2023 15:23
Updating all reverse dependencies of an R package at once

I recently received the following error when rendering the vignettes for an R package I'm developing as part of R CMD CHECK.

The function xfun::isFALSE() will be deprecated in the future. Please consider using base::isFALSE(x) or identical(x, FALSE) instead.

As it wasn't clear which package exactly was calling the offending function (xfun::isFALSE), I just wanted an easy way of upgrading all packages that may be using it. The following snippet does just that.

# This is the function itself
pwr.t2n.ratio <- function(n_ratio = 1, d, sig.level, power, alternative) {
if (power >= 1) {
return(Inf)
}
fn <- Vectorize(function(n1) {
effN <- n1 * n_ratio / (1 + n_ratio)
df <- n1 * (1 + n_ratio) - 2
ncp <- sqrt(effN) * d
if (alternative == "two.sided") {
@jansim
jansim / coords2country.R
Last active August 21, 2020 10:52
🌐 Get country information (name, iso3, continent) from geospatial coordinates (latitude and longitude) in R without contacting an external API
library(sp)
library(rworldmap)
#' Get country from coordinates
#' based on: https://stackoverflow.com/questions/14334970/convert-latitude-and-longitude-coordinates-to-country-name-in-r/14342127#14342127
#'
#' @param lng Contains the longitude in degrees
#' @param lat Contains the latitude in degrees
#' @param export What to return, options: 'name' => country name (default), 'iso3' => ISO3 country code, 'continent6' => continent (6 continent model), 'continent7' => continent (7 continent model), 'raw' => whole spatial indices object
#'
@jansim
jansim / vulgar_fractions.js
Last active May 4, 2022 02:33
Unicode Vulgar Fractions in JavaScript / JSON
// Vulgar fractions are Unicode characters for specific fractions i.e. ½
// List of fractions from: https://stackoverflow.com/questions/35012491/parse-%C2%BD-as-0-5-in-python-2-7
// See also: http://unicodefractions.com/
// Calculate fractions on-the-fly
const vulgar_fractions = {
'\u2189': 0/3,
'\u2152': 1/10,
'\u2151': 1/9,
@jansim
jansim / cmd.sh
Created January 13, 2020 14:03
Restart audio driver on macOS
sudo kill -9 `ps ax|grep 'coreaudio[a-z]' | awk '{print $1}'`
@jansim
jansim / event.js
Last active November 8, 2019 16:34 — forked from wildlyinaccurate/event.js
Really simple Javascript custom event system (slightly extended to keep listeners and allow whether stuff should be called immediately)
var Event = function () {
var self = this
self.queue = {}
self.fired = []
return {
fire: function (event) {
var queue = self.queue[event]
@jansim
jansim / reminder.js
Created October 18, 2019 02:31
Add reminders to the macOS Reminders.App from the command line
#!/usr/bin/env osascript -l JavaScript
// Add reminders to the macOS Reminders.App from the command line
const RemindersApp = Application('Reminders');
// - Examples -
// Add a new item:
// ./reminder.js add "My cool new reminder"
// Show all available lists: