Skip to content

Instantly share code, notes, and snippets.

View csgillespie's full-sized avatar

Colin Gillespie csgillespie

View GitHub Profile
@jboner
jboner / latency.txt
Last active April 24, 2024 00:20
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@dsparks
dsparks / Visually-weighted regression.R
Created September 12, 2012 19:52
Visually-weighted regression plot, including simulation from a model
# A simple approach to visually-weighted regression plots
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("ggplot2", "reshape2", "MASS")
if(doInstall){install.packages(toInstall, repos = "http://cran.us.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Generate some data:
nn <- 1000
myData <- data.frame(X = rnorm(nn),
@stephenturner
stephenturner / .Rprofile.r
Last active July 19, 2021 22:05
My .Rprofile
## See http://gettinggeneticsdone.blogspot.com/2013/06/customize-rprofile.html
## Load packages
library(BiocInstaller)
## Don't show those silly significanct stars
options(show.signif.stars=FALSE)
## Do you want to automatically convert strings to factor variables in a data.frame?
## WARNING!!! This makes your code less portable/reproducible.
@killercup
killercup / pandoc.css
Created July 3, 2013 11:31
Add this to your Pandoc HTML documents using `--css pandoc.css` to make them look more awesome. (Tested with Markdown and LaTeX.)
/*
* I add this to html files generated with pandoc.
*/
html {
font-size: 100%;
overflow-y: scroll;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
next_letter <- local({
i <- 0
function() {
i <<- i + 1
paste0("x_", c(letters, LETTERS))[i]
}
})
f <- function() {
new_arg <- alist(x = )
a <- 1
b <- 2
ftw <- function()
{
vars <- ls(envir = .GlobalEnv)
rm(list = vars, envir = .GlobalEnv)
}
ftw()
@leeper
leeper / plotthemes.R
Last active October 28, 2016 15:23
Experimenting with themes in base graphics
#' The goals here are to:
#' (1) play around with themes to make base graphics less ugly
#' (2) atomically specify multiple plot aspects (data, axes, grid, title) in a single call
#' (3) Recycle last plot theme to easily duplicate its appearance in the next plot
#' The idea is to create a set of customizable functions like `theme()`, which return a list of graphics arguments
#' These can then be passed to `splot`, which will cleanly handle them by passing some to `par` and some to `plot`
#' Different `theme()` functions can then be used to modify color palettes, axes, etc.
merge.list <-
function (x, y) {
@daattali
daattali / beepr_error.R
Created May 11, 2015 01:58
beepr_error
# rasmusab/beepr package is great for telling you when your R code finishes running.
# But if the code throws an error, the beep will never come, and you won't know that
# it finished running until you visually check.
# Solution: change the error handler to a failure beep.
# Example
foo <- function(success = TRUE) {
if (!success) {
stop("Error!")
}
@gaborcsardi
gaborcsardi / cran-over-time.R
Last active July 18, 2020 19:21
Size of the CRAN R package repository over time
library(jsonlite)
## Download
pkgs <- fromJSON("http://crandb.r-pkg.org/-/events")
## Filter
na_pkgs <- unique(pkgs$name[ is.na(pkgs$date) ])
events <- pkgs[ ! pkgs$name %in% na_pkgs, c("date", "name", "event")]
# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat
# Originally seen at http://spatial.ly/2014/08/population-lines/
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess,
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line.
# The result of the code below can be seen at http://imgur.com/ob8c8ph
library(tidyverse)