Skip to content

Instantly share code, notes, and snippets.

View rdinnager's full-sized avatar

Russell Dinnage rdinnager

View GitHub Profile
@rdinnager
rdinnager / magrittr_challenge.md
Last active October 13, 2022 07:21
magrittr Challenge accepted!

magrittr Challenge!

A picture suitable for a fancy pipe enthusiast

My good friend Andrew recently posted this gist, purporting

@rdinnager
rdinnager / gist:da324a55c6c5bb7703fd
Last active August 29, 2015 14:02
Function to select colours from a palette by maximizing Mean Perceptual Distance (MPD)
require(picante)
require(colorspace)
#' Select colours from a palette to maximize perceptual distance between the colours
#'
#' This function takes a palette as a character vector of hexidecimal colours, and returns a smaller palette,
#' attempting to maximize the mean perceptual distance (MPD) between the colours in the new palette. It uses CIELAB
#' colorspace to map colour to a perceptually meaningful scale before maximizing distances
#'
#' @param pal A palette as a character vector containing hexidecimal coded colours
#' @param sat.thresh Minimum saturation of colours in resulting palette (between 0 and 1)

Is there an easy way to convert a named list into a dataframe, preserving the elements of the list in a "list-column"?

library(dplyr)
library(magrittr)

## make a random matrix
rand_mat <- function() {
  Nrow <- sample(2:15,1)

Ncol <- sample(2:15,1)

@rdinnager
rdinnager / ALF.R
Created July 22, 2014 04:16
Code to run simple ALF simulation from R
## Generate ALF simulations
library(whisker)
ALF_template <- function() {
" webRequest := false;
uuid := '4e4937bd-70e5-4caf-8521-f4340a4b7e09';
# name of simulation - you may want to change this
mname := {{{simname}}};
# directories for file storage - you may want to change these
@rdinnager
rdinnager / @midnight_freq_players.csv
Created September 12, 2015 00:16
Data on number of wins for comedians who frequently appear on @midnight panel show
player Gender hits first second third total simple.points image image_ht image_wd
Kumail Nanjiani M 404000 4 2 0 6 0.833333333333333 https://duckduckgo.com/i/b7d0c4ff.jpg 200 164
Andy Daly M 182000 2 3 1 6 0.583333333333333 https://duckduckgo.com/i/ff655da8.jpg 200 133
Kyle Kinane M 190000 7 1 2 10 0.75 https://duckduckgo.com/i/cb420bdf.jpg 200 300
Kristen Schaal F 512000 2 1 1 4 0.625 https://duckduckgo.com/i/0cf592c2.jpg 200 150
Patton Oswalt M 747000 1 2 0 3 0.666666666666667 https://duckduckgo.com/i/bbfa97b3.jpg 200 168
Matt Besser M 167000 3 3 1 7 0.642857142857143 https://duckduckgo.com/i/804ac973.jpg 200 100
Moshe Kasher M 107000 5 3 1 9 0.722222222222222 https://duckduckgo.com/i/122b4834.jpg 200 200
Jonah Ray M 160000 3 5 2 10 0.55 https://duckduckgo.com/i/09b947a3.jpg 200 310
Ron Funches M 154000 11 2 0 13 0.923076923076923 https://duckduckgo.com/i/d6db36c0.jpg 200 143
@rdinnager
rdinnager / @midnight_freq_players.csv
Created September 14, 2015 00:44
Testing SVG and CSV loading in D3
player Gender hits first second third total simple.points image image_ht image_wd
Kumail Nanjiani M 404000 4 2 0 6 0.833333333333333 https://duckduckgo.com/i/b7d0c4ff.jpg 200 164
Andy Daly M 182000 2 3 1 6 0.583333333333333 https://duckduckgo.com/i/ff655da8.jpg 200 133
Kyle Kinane M 190000 7 1 2 10 0.75 https://duckduckgo.com/i/cb420bdf.jpg 200 300
Kristen Schaal F 512000 2 1 1 4 0.625 https://duckduckgo.com/i/0cf592c2.jpg 200 150
Patton Oswalt M 747000 1 2 0 3 0.666666666666667 https://duckduckgo.com/i/bbfa97b3.jpg 200 168
Matt Besser M 167000 3 3 1 7 0.642857142857143 https://duckduckgo.com/i/804ac973.jpg 200 100
Moshe Kasher M 107000 5 3 1 9 0.722222222222222 https://duckduckgo.com/i/122b4834.jpg 200 200
Jonah Ray M 160000 3 5 2 10 0.55 https://duckduckgo.com/i/09b947a3.jpg 200 310
Ron Funches M 154000 11 2 0 13 0.923076923076923 https://duckduckgo.com/i/d6db36c0.jpg 200 143
@rdinnager
rdinnager / @midnight_freq_players.csv
Created September 14, 2015 02:34
Testing out basic bar charts in D3 using @midnight data
Kumail Nanjiani M 404000 4 2 0 6 0.833333333333333 https://duckduckgo.com/i/b7d0c4ff.jpg 200 164
Andy Daly M 182000 2 3 1 6 0.583333333333333 https://duckduckgo.com/i/ff655da8.jpg 200 133
Kyle Kinane M 190000 7 1 2 10 0.75 https://duckduckgo.com/i/cb420bdf.jpg 200 300
Kristen Schaal F 512000 2 1 1 4 0.625 https://duckduckgo.com/i/0cf592c2.jpg 200 150
Patton Oswalt M 747000 1 2 0 3 0.666666666666667 https://duckduckgo.com/i/bbfa97b3.jpg 200 168
Matt Besser M 167000 3 3 1 7 0.642857142857143 https://duckduckgo.com/i/804ac973.jpg 200 100
Moshe Kasher M 107000 5 3 1 9 0.722222222222222 https://duckduckgo.com/i/122b4834.jpg 200 200
Jonah Ray M 160000 3 5 2 10 0.55 https://duckduckgo.com/i/09b947a3.jpg 200 310
Ron Funches M 154000 11 2 0 13 0.923076923076923 https://duckduckgo.com/i/d6db36c0.jpg 200 143
@rdinnager
rdinnager / @midnight_freq_players.csv
Last active September 14, 2015 05:21
Dynamic d3 barchart of @midnight contestants
Kumail Nanjiani M 404000 4 2 0 6 0.833333333333333 https://duckduckgo.com/i/b7d0c4ff.jpg 200 164
Andy Daly M 182000 2 3 1 6 0.583333333333333 https://duckduckgo.com/i/ff655da8.jpg 200 133
Kyle Kinane M 190000 7 1 2 10 0.75 https://duckduckgo.com/i/cb420bdf.jpg 200 300
Kristen Schaal F 512000 2 1 1 4 0.625 https://duckduckgo.com/i/0cf592c2.jpg 200 150
Patton Oswalt M 747000 1 2 0 3 0.666666666666667 https://duckduckgo.com/i/bbfa97b3.jpg 200 168
Matt Besser M 167000 3 3 1 7 0.642857142857143 https://duckduckgo.com/i/804ac973.jpg 200 100
Moshe Kasher M 107000 5 3 1 9 0.722222222222222 https://duckduckgo.com/i/122b4834.jpg 200 200
Jonah Ray M 160000 3 5 2 10 0.55 https://duckduckgo.com/i/09b947a3.jpg 200 310
Ron Funches M 154000 11 2 0 13 0.923076923076923 https://duckduckgo.com/i/d6db36c0.jpg 200 143
## This code makes this poster
make_poster <- function() {
library(ggplot2);library(imager);library(dplyr)
library(tidyr); library(colorspace); library(
sysfonts); library(showtext); if( !file.exists(
"this_poster_is_made.png" ) ) { download.file(
"https://www.r-project.org/logo/Rlogo.png",
"Rlogo.png", mode = "wb"); font_add_google(
"Finger Paint");R_logo<-load.image("Rlogo.png")
;poster_text <-capture.output(print(make_poster