Skip to content

Instantly share code, notes, and snippets.

View shabbychef's full-sized avatar
tcb

Steven Pav shabbychef

tcb
View GitHub Profile
library(dplyr)
library(ggplot2)
library(grid)
geom_cloud <- function(mapping = NULL, data = NULL, ...,
na.rm = FALSE,
steps = 5, se_mult=1, max_alpha=1,
inherit.aes = TRUE) {
@shabbychef
shabbychef / Dockerfile
Created July 18, 2017 05:38
soundcloud sync a user with Docker
#
# docker build --rm -t shabbychef/sc .
#
# docker run -it --rm -v $(pwd)/muzak:/srv:rw shabbychef/sc "-u" "shabbychef" "-o" "/srv" "-c" "THIS IS YOUR API KEY THINGY AA43"
#
# Created: 2016.03.07
# Copyright: Steven E. Pav, 2016
# Author: Steven E. Pav
# Comments: Steven E. Pav
@shabbychef
shabbychef / compare_rolls.R
Created May 31, 2017 05:35
Compare Rolls Again
options(width=160)
suppressMessages({
library(fromo)
library(roll)
library(RcppRoll)
library(microbenchmark)
library(RollingWindow)
})
show(sessionInfo())
@shabbychef
shabbychef / compare_rolls.R
Last active May 15, 2017 07:00
compare rolling mean functions
suppressMessages({
library(fromo)
library(roll)
library(RcppRoll)
library(microbenchmark)
library(RollingWindow)
})
set.seed(1234)
df <- data.frame(Adjusted=rnorm(10000))
@shabbychef
shabbychef / coins.R
Created May 26, 2016 03:28
Divide a target sum into coins.
# compute the different ways can you express tgt as the sum of a bunch of coins
# no greater than maxcoin. assume coins sorted in descending order,
# probably does not work great if there is no penny, or negative coins,
# or negative tgt.
coinrep <- function(tgt,coins=c(25,10,5,1),maxcoin=coins[1]) {
stopifnot(tgt >= 0)
stopifnot(all(diff(coins) < 0)) # reverse sorted.
freecoins <- (coins <= min(maxcoin,tgt))
basev <- rep(0,length(coins))
if (! any(freecoins)) {
@shabbychef
shabbychef / minesweeper.R
Created May 1, 2016 04:43
minesweeper implemented in R
# /usr/bin/r
#
# Created: 2016.04.26
# Copyright: Steven E. Pav, 2016
# Author: Steven E. Pav <shabbychef@gmail.com>
# Comments: Steven E. Pav
# generate a new state of the board
generate_one <- function(nrow,ncol=nrow,nbombs = 10) {
stopifnot(nbombs <= nrow*ncol)
@shabbychef
shabbychef / shiny_edgeworth.R
Created April 16, 2016 05:19
shiny app to give Edgeworth approximation to the density based on input raw cumulants.
library(mpoly)
# blinnikov and moessner's ADVANCE function
advance <- function(kms) {
current <- kms$current
mold <- kms$mold
n <- length(current)
ords <- 1:(length(current))
stopifnot(n == sum(current * ords))
@shabbychef
shabbychef / yunoparallel.R
Last active March 25, 2016 18:18
y u no work, RcppParallel?
library(Rcpp)
source('yunoparallel.cpp')
x <- rnorm(1e5)
dumbCount_int(x)
dumbCount_int(x)
# fine, right? no.
replicate(10,dumbCount_int(x))
sd(replicate(100,dumbCount_int(x)))
@shabbychef
shabbychef / yunoparallel.R
Last active March 25, 2016 18:15
y u no work, RcppParallel?
library(Rcpp)
source('yunoparallel.cpp')
x <- rnorm(1e5)
dumbCount_int(x)
dumbCount_int(x)
# seems fine, except ...
replicate(10,dumbCount_int(x))
sd(replicate(100,dumbCount_int(x)))
#!/bin/bash -e
#
# Created: 2016.02.05
# Copyright: Steven E. Pav, 2016
# Author: Steven E. Pav
# Comments: Steven E. Pav
function finish() {
echo doing cleanup here
}