Skip to content

Instantly share code, notes, and snippets.

@rweald
rweald / rspec-syntax-cheat-sheet.rb
Created August 31, 2012 18:45 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@rweald
rweald / propane-js-customization.js
Created October 18, 2012 18:16
Custom Propane JS listeners
/*
As of version 1.1.2, Propane will load and execute the contents of
~Library/Application Support/Propane/unsupported/caveatPatchor.js
immediately following the execution of its own enhancer.js file.
You can use this mechanism to add your own customizations to Campfire
in Propane.
Below you'll find two customization examples.
@rweald
rweald / running-scalatra-on-heroku.md
Created December 14, 2012 02:34
Running Scalatra on Heroku

Instructions

###You will need to add the sbt-start-script plugin.

This plugin gives you a stage action which generates a script called target/start that can be used to run your application without pulling SBT into memory.

This can be accomplished by first adding the following line to project/plugins.sbt

library(ggplot)
decay <- function (x, lambda = 5) {
return((100 * exp((-1 * lambda) * x)))
}
xs <- seq(from = 1, to = 10, by = 0.001)
ys <- sapply(xs, decay, lambda = 0.4)
@rweald
rweald / install-rserver-ubuntu.sh
Created December 17, 2012 19:13
Installing R Server on Ubuntu
#!/usr/bin/env bash
echo "Installing R"
apt-get update
apt-get install r-base-core
apt-get install r-base-dev
echo "Installing R Server dependencies"
apt-get install gdebi-core libapparmor1
@rweald
rweald / ParseJsonExampleJob.scala
Created December 19, 2012 01:37
Sample scalding job that reads a line of JSON and parses out 1 field
import com.twitter.scalding._
import scala.util.parsing.json._
class ParseJsonJob(args: Args) extends Job(args) {
TextLine(args("input"))
.map(('line) -> ('parseStatus, 'uri)) {
line: String => {
JSON.parseFull(line) match {
case Some(data: Map[String, String]) => ("success", data("uri"))
case None => ("failed", "")
@rweald
rweald / geocode-ips.rb
Last active December 10, 2015 21:38
Read IP addresses from STDIN geocode IPs and print 2-tuple (long, lat) to STDOUT
#!/usr/bin/env ruby -W0
require 'geoip'
geocity_file_location = ARGV[0] || "./GeoLiteCity.dat"
geocoder = GeoIP.new(geocity_file_location)
i = 0
STDIN.each do |ip|
STDERR.write("Processing Line: #{i}\n") if i % 1000 == 0
i += 1
library(maps)
library(geosphere)
library(plyr)
library(ggplot2)
library(sp)
airports <- read.csv("http://www.stanford.edu/~cengel/cgi-bin/anthrospace/wp-content/uploads/2012/03/airports.csv", as.is=TRUE, header=TRUE)
flights <- read.csv("http://www.stanford.edu/~cengel/cgi-bin/anthrospace/wp-content/uploads/2012/03/PEK-openflights-export-2012-03-19.csv", as.is=TRUE, header=TRUE)
# aggregate nunber of flights
@rweald
rweald / install-postgres-driver.sh
Created January 14, 2013 23:02
Installing postgres driver for apache sqoop
cd /tmp
wget "http://jdbc.postgresql.org/download/postgresql-9.2-1002.jdbc4.jar"
cp postgresql-9.2-1002.jdbc4.jar /usr/share/java/
ln -s /usr/share/java/postgresql-9.2-1002.jdbc4.jar /usr/lib/sqoop/lib/postgresql-9.2-1002.jdbc4.jar
@rweald
rweald / convert-lat-long-to-state.R
Created February 6, 2013 06:40
Convert (long,lat) pairs into state names
#Code taken from SO
#http://stackoverflow.com/questions/8751497/latitude-longitude-coordinates-to-state-code-in-r/8751965#8751965
library(sp)
library(maps)
library(maptools)
# The single argument to this function, pointsDF, is a data.frame in which:
# - column 1 contains the longitude in degrees (negative in the US)
# - column 2 contains the latitude in degrees