Skip to content

Instantly share code, notes, and snippets.

View klmr's full-sized avatar
📦
Making your R code easier to reuse

Konrad Rudolph klmr

📦
Making your R code easier to reuse
View GitHub Profile
@wllmsash
wllmsash / assigning-static-ip-addresses-in-wsl2.md
Last active April 18, 2024 23:19
Assigning Static IP Addresses in WSL2

Assigning Static IP Addresses in WSL2

WSL2 uses Hyper-V for networking. The WSL2 network settings are ephemeral and configured on demand when any WSL2 instance is first started in a Windows session. The configuration is reset on each Windows restart and the IP addresses change each time. The Windows host creates a hidden switch named "WSL" and a network adapter named "WSL" (appears as "vEthernet (WSL)" in the "Network Connections" panel). The Ubuntu instance creates a corresponding network interface named "eth0".

Assigning static IP addresses to the network interfaces on the Windows host or the WSL2 Ubuntu instance enables support for the following scenarios:

@andy-thomason
andy-thomason / Genomics_A_Programmers_Guide.md
Created May 14, 2019 13:32
Genomics a programmers introduction

Genomics - A programmer's guide.

Andy Thomason is a Senior Programmer at Genomics PLC. He has been witing graphics systems, games and compilers since the '70s and specialises in code performance.

https://www.genomicsplc.com

@klmr
klmr / fib.py
Last active September 14, 2022 08:39
Efficient, tail recursive fibonacci implementation for R and Python (but since they doesn’t do TCO it’s still using O(n) space)
def fib(n: int) -> int:
def f(n, a, b):
if n == 0: return a
if n == 1: return b
return f(n - 1, b, a + b)
return f(n, 0, 1)
@Glorfindel83
Glorfindel83 / broken-image-repairer.md
Last active August 19, 2023 14:08
Broken Image Repairer

Broken Image Repairer

What is the problem?

A long time ago, it was possible to inline images from all kinds of external sources. Since the switch from HTTP to HTTPS, this is no longer possible; only HTTPS sources are allowed. This leads to ugly blurbs like

alt text http://example.com/image.png

instead of a nicely formatted page with images. Sometimes, the links don't even work anymore, even with HTTPS images, which will show like this: ... Luckily, we have the Wayback Machine which is able to rescue some of the lost images. Since a picture often says more than a thousand words, it's important to bring back the post into its original state; important enough to justify the occasional bump of an old post (see below).

@dylanmckay
dylanmckay / facebook-contact-info-summary.rb
Last active March 12, 2024 22:46
A Ruby script for collecting phone record statistics from a Facebook user data dump
#! /usr/bin/env ruby
# NOTE: Requires Ruby 2.1 or greater.
# This script can be used to parse and dump the information from
# the 'html/contact_info.htm' file in a Facebook user data ZIP download.
#
# It prints all cell phone call + SMS message + MMS records, plus a summary of each.
#
# It also dumps all of the records into CSV files inside a 'CSV' folder, that is created
@klmr
klmr / README.md
Last active April 27, 2017 14:28
Debug which functions access .Random.seed

Who is touching the .Random.seed?

Inspired by a Stack Overflow question, here’s a way of tracking what’s been modifying the .Random.seed.

Since R makes static analysis impossible in general, the following is a runtime tracer that injects itself into the .Random.seed variable via an active binding:

debug_random_seed()
sample(10)
@klmr
klmr / r-launcher.sh
Last active March 31, 2017 16:02
R launcher for Nvim-R on an LSF cluster
#!/usr/bin/env bash
while getopts ":n:c:q:" option; do
case "$option" in
n)
cores="$OPTARG"
;;
m)
mem="$OPTARG"
;;
@klmr
klmr / pillows.r
Created February 23, 2017 12:20
Ordering pillows online
library(dplyr)
library(tidyr)
library(ggplot2)
stages = c('Ordered', '?', 'In transit', 'Arrived', 'Returned')
make_stages = function (status)
factor(status, levels = stages, ordered = TRUE)
pillows = tibble::tribble(
@klmr
klmr / mutate_when.r
Last active November 21, 2017 19:47
Missing `mutate_when` function for dplyr
modules::import_package('rlang', attach = TRUE)
mutate_when = function (.data, .filter, ...) {
dots = dots_definitions(...)$dots
rows = eval_tidy(enquo(.filter), .data)
.data[rows, names(dots)] =
lapply(dots, eval_tidy, data = .data[rows, , drop = FALSE])
.data
}
@klmr
klmr / curry.md
Last active February 14, 2017 14:57
Currying explained

In the following, let’s define sum as

sum = function (a, b, c) a + b +c

Because base::sum’s definition involves ..., which would make the following explanation unnecessarily complex.