Skip to content

Instantly share code, notes, and snippets.

@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 / 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
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 / 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

@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 / 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 / simple-linear-regression.rb
Created August 29, 2012 19:13
Simple Linear Regression in Ruby
class SimpleLinearRegression
def initialize(xs, ys)
@xs, @ys = xs, ys
if @xs.length != @ys.length
raise "Unbalanced data. xs need to be same length as ys"
end
end
def y_intercept
mean(@ys) - (slope * mean(@xs))
@rweald
rweald / sample-video-view-data.csv
Created August 29, 2012 18:00
Simple Linear Regression Using Ruby Blog Post DataSet
Days Online Number of Views
1 5500.0
2 45000.0
3 27500.0
4 38000.0
5 38500.0
6 17000.0
7 37500.0
8 55000.0
9 63500.0
@rweald
rweald / denominator-snippet.rb
Created August 29, 2012 17:50
Code Snippets for Simple Linear Regression Using Ruby Blog Post
denominator = @xs.reduce(0) do |sum, x|
sum + ((x - x_mean) ** 2)
end
@rweald
rweald / spoof_mac_address.rb
Created August 27, 2012 17:20
Little Ruby script to spoof a mac address
#!/usr/bin/env ruby
puts "Please Enter Your MAC Address: "
mac = gets
mac = mac.strip
`sudo /bin/bash -lc "sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -z && sudo ifconfig en0 ether #{mac}"`
puts "Congratulations you now have #{mac} as your MAC address"