Skip to content

Instantly share code, notes, and snippets.

View jonocarroll's full-sized avatar
👨‍💻
Learning all the languages

Jonathan Carroll jonocarroll

👨‍💻
Learning all the languages
View GitHub Profile
@jonocarroll
jonocarroll / simplystats_thanksgiving.R
Last active December 1, 2015 05:48
SimplyStats thanksgiving Rubik's Cube solution
## transform the input to the output using rubiks-cube transformations and dplyr
require(dplyr)
## provided input
input <- data.frame(matrix(c("h","a","t","t","i","v","i","g","k","s","g","n","n","g","n","i"),
4,
4,
byrow=TRUE,
dimnames=list(NULL,paste0("col",1:4))),
stringsAsFactors=FALSE)
@jonocarroll
jonocarroll / population.R
Last active March 11, 2016 12:24
I, too, made a map
## libraries used to create these maps
library(maps) ## world.cities data
library(dplyr) ## group_by(), summarise(), and imported %>%
library(ggplot2) ## plotting
## the raw data
## `citation("maps")`
data("world.cities")
## limit the data to the latitude, lonitude, and population
setwd("WORKINGDIRECTORY")
library(png) ## split .png into component matrices
library(RSAGA) ## grid.to.xyz, load before dplyr
library(dplyr) ## group_by(), summarise(), %>%
library(ggplot2) ## plotting
library(ggExtra) ## ggMarginal
## load the .png file
img <- png::readPNG("file10a566a2b4dc3.png")
@jonocarroll
jonocarroll / coffee.R
Last active April 1, 2016 06:15
Coffee near #auunconf 2016
# myAPIkey <- "PlAcEyOuRkEyHeRe"
library(ggplot2)
library(ggmap)
library(ggthemes)
library(png)
library(grid)
library(RCurl)
findXnearY <- function(X = "coffee", # default: coffee
@jonocarroll
jonocarroll / jonocarroll_2016-14.R
Last active April 10, 2016 22:27
52vis Challenge Week 2
## 52vis challenges, week 2
## originally seen at
## https://rud.is/b/2016/04/06/52vis-week-2-2016-week-14-honing-in-on-the-homeless/
## this version blogged @ http://jcarroll.com.au/2016/04/10/52vis-week-2-challenge/
## github: github.com/jonocarroll/2016-14
## This script produces a choropleth for the USA homeless population
## as a per mille proportion of each state's population, with the
## colorscale set to white at the national median, blue at the
## lowest value, and capped at 3x the national median in red.
@jonocarroll
jonocarroll / jonocarroll_2016-14_AUSversion.R
Last active April 11, 2016 23:37
Australian version of the 52Vis Week 2 Challenge
## 52vis challenges, week 2 -- adapted for Australian statistics
## otherwise follows procedures found at
## github.com/jonocarroll/2016-14
## http://jcarroll.com.au/2016/04/10/52vis-week-2-challenge/
## this version blogged @ http://jcarroll.com.au/2016/04/12/australian-homeless/
## This script produces a chloropleth for the Australian homeless population
## as a per mille proportion of each state's population, with the
## colorscale set to the same as the USA homeless graph (white at the national
## median, blue at the lowest value, and capped at 3x the national median in red).
## Inspired by http://www.milanor.net/blog/how-to-sort-a-list-of-dataframes-in-r/
## as seen on R-bloggers http://www.r-bloggers.com/how-to-sort-a-list-of-dataframes/
##
## Blogged @ http://jcarroll.com.au/2016/04/14/simpler-isnt-always-faster/
##
## input data.frame
df_list_in <- list (
df_1 = data.frame(x = 1:5, y = 5:1),
df_2 = data.frame(x = 6:10, y = 10:6),
@jonocarroll
jonocarroll / slackrs.R
Last active April 14, 2016 13:32
Plot the #auunconf slack users' timezones on a map
## Create a world timezone map of the #auunconf slack users' timezones
## data extracted via hrbrmstr/slackr
## Timezone shapefile: http://efele.net/maps/tz/world/
##
## Blogged @ http://jcarroll.com.au/2016/04/14/slack-timezones/
## load relevant packages
pacman::p_load(rgdal, maptools, ggplot2)
pacman::p_load(ggthemes, albersusa, ggalt)
pacman::p_load(extrafont)
## Optimising an expression subject to inequality constriaints
## as seen on
## http://fivethirtyeight.com/features/you-have-1-billion-to-win-a-space-race-go/
## https://xianblog.wordpress.com/2016/04/21/an-integer-programming-riddle/
## http://www.r-bloggers.com/an-integer-programming-riddle/
## Blogged @ http://jcarroll.com.au/2016/04/27/solving-inequality-the-math-kind/
## The expression to optimise:
## 200a + 100b + 50c + 25d
##
@jonocarroll
jonocarroll / portmap.R
Last active May 21, 2016 14:21
Port map lookup from Wikipedia
# Bob Rudis
# @hrbrmstr
# Lazy cyber tweet: what prod/dev has this port combo?
# 110,111,143,21,22,23,25,3389,389,443,465,587,5900,8080,8081,8443,8888,9100,990,993,995
# install.packages("rvest")
library(rvest)
html <- read_html("https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers")
ports1 <- html_table(html_nodes(html, "table")[5])[[1]]