Skip to content

Instantly share code, notes, and snippets.

@peterhurford
peterhurford / ec2_price_discovery.py
Last active August 24, 2018 18:46
Find the best deals in AWS spot instances across all availability zones and multiple instance types
# For every AWS availability zone and instance I care about, check the spot
# price for the last ninety days and generate stats about which spot instance
# gives the best deal.
import boto
import boto.ec2
from vowpal_platypus.utils import mean
REGIONS = {'us-east-1': ['us-east-1a', 'us-east-1b', 'us-east-1c', 'us-east-1e'],
@peterhurford
peterhurford / r-pkgs.md
Created July 6, 2015 22:39
Notes on Hadley's "R Packages"

Notes from reading through R Packages by Hadley Wickham. This is meant to review, not replace, a thorough readthrough. I mainly wrote this as a personal review, since writing summaries and attempting to teach others are some of the best ways to learn things.

Introduction

  • Packages are used to organize code together so that it can be used repeatedly and shared with others.

  • A lot of work with packages is done via the devtools package.

#' Calculate a dep_var for the iris dataset based on the iris dataset.
#'
#' @param by character. \code{length} to go by \code{Petal.Length} or \code{width} to go by \code{Petal.Width}.
iris_with_dep_var <- validations::ensure(pre = list(by %in% c("length", "width")),
  function(by = "length") {
    if (identical(by, "length")) {
      plyr::ddply(iris, plyr::.(Species), summarize, dep_var = ifelse(any(Petal.Length >= 4), 1, 0))
    } else {
      plyr::ddply(iris, plyr::.(Species), summarize, dep_var = ifelse(any(Petal.Width >= 4), 1, 0))
@peterhurford
peterhurford / meat_consumption_by_country.md
Last active April 17, 2017 00:52
Meat consumption by country, kg per capita

Total kg per capita consumed of beef, veal, pork, poultry, and sheep meat by country in 2016, adapted from OECD Data on Meat Consumption. Per-animal breakdown is available as a CSV.

IND	2.944374911
BGD	3.358927799
ETH	4.449228451
NGA	6.061917778
TZA	6.986943733
MOZ	7.117845532
SSA	8.798326892
@peterhurford
peterhurford / fledgling-languages.md
Created February 16, 2016 18:06
Some highlights from the "Fledgling Languages" list

The Fledgling Languages list has almost 100 programming languages that are up-and-coming but not widely popular. I looked at them all and here are a few of my favorites:

...This language looks so much like English! http://www.availlang.org/

...This language claims to have the speed of C++, the expressiveness of Python, and tons of additional safety with first-level contracts http://cobra-language.com/

...Code that looks exactly like Ruby, but is statically type-checked and compiled into efficient native code http://crystal-lang.org/

...What it would look like if Haskell and Clojure had a baby https://github.com/LuxLang/lux

@peterhurford
peterhurford / hate.R
Created June 10, 2015 19:39
An R Function that Only Works When You Try to Debug it
# Debugging in R is much better than many languages, but sometime it can be
# frustrating. Here's a function that makes it even more frustrating --
# it only works when you try to debug it!
# The challenge:
### Write a function that, if the function has a browser in it, will execute
### every line correctly, but if it does not have a browser in it, it will
### error.
# The solution:
@peterhurford
peterhurford / functionals_need_force.md
Last active August 29, 2015 14:19
Why do R function operators need to force(f)?

While reading Hadley's Advanced R book chapter on function operators (see our work on creating a set of answers here), I came across this fact about lazy evaluation:

The function operators we’ve seen so far follow a common pattern:

funop <- function(f, otherargs) { function(...) { # maybe do something res <- f(...) # maybe do something else

@peterhurford
peterhurford / interview.md
Last active August 29, 2015 14:15
Rails Interview

1a.) Why would one use a symbol instead of a string?

1b.) Why would someone use a string instead of a symbol?

2a.) What is the difference between a lambda, a block and a proc?

2b.) What does -> (a) {p a}["Hello world"] do?

@peterhurford
peterhurford / RCoffeescript.md
Last active August 29, 2015 14:11
Rspresso: Coffeescript for R

Rspresso

(Name and initial idea from robertzk.)

Assignment

number = 42 --> RSPRESSO! --> number <- 42

Functions

@peterhurford
peterhurford / interview.md
Last active August 29, 2015 14:11
Ruby Interview Questions (No Rails, for a Prospective Junior Developer / Intern)

What does a ||= b mean?

What is the difference between a symbol and a string?

What is the difference between ' and " in Ruby?