Skip to content

Instantly share code, notes, and snippets.

View gavinwhyte's full-sized avatar

Gavin Whyte gavinwhyte

View GitHub Profile
@gavinwhyte
gavinwhyte / gist:7023ccf7a272179bdaab
Last active September 7, 2015 05:52
Pearson Correlation Coefficient.
-- Create a new file, which we will call Main.hs
main :: IO ()
main = do
let d1 = [3,3,3,4,4,4,5,5,5]
let d2 = [1,1,2,2,3,4,4,5,5]
let r = pearson d1 d2
print r
pearson xs ys = (n * sumXY - sumX * sumY) /
@gavinwhyte
gavinwhyte / mesosvagrant
Last active August 29, 2015 14:23
Mesos
$ mkdir vm-install
$ cd vm-install
$ vagrant init chef/centos-7.0
Edit the Vagrantfile to uncomment the line with
$ config.vm.network "private_network", ip: "192.168.33.10"
and add the line
$ config.vm.hostname = "node1"
$ config.vm.provider "virtualbox" do |vb|
# # Display the VirtualBox GUI when booting the machine
@gavinwhyte
gavinwhyte / fastfail.scala
Last active August 29, 2015 14:23
fast fail
import scalaz.\/
import scalaz.syntax.either._
object Example2 {
// This example simulates error handling for a simple three tier web application
//
// The tiers are:
// - the HTTP service
// - a user authentication layer
// - a database layer
@gavinwhyte
gavinwhyte / ExecutionAppSample.scala
Last active August 29, 2015 14:23
ExecutionAppSample
import com.twitter.scalding.typed.{IterablePipe}
import com.twitter.scalding._
/**
* 1) sbt
* 2) project <project-name>
* 3) run-main ExecutionAppSample --local
* 4) See output in out.csv
*/
object ExecutionAppSample extends ExecutionApp {
@gavinwhyte
gavinwhyte / ExecutionJobSample.scala
Created June 22, 2015 01:22
ExecutionJobSample
import com.twitter.scalding._
import com.twitter.scalding.typed.IterablePipe
/**
* Run this from the scalding Tool or other executor
*
* @param args
*/
class ExecutionJobSample(args: Args) extends ExecutionJob(args) {
@gavinwhyte
gavinwhyte / Main.hs
Last active August 29, 2015 14:23
Moving Average
-- Computing the moving average
main = do
rawInput <- readFile "input.txt"
let input = clean rawInput
print input
putStrLn $ "mean is " ++ (show.mean) input
putStrLn $ "moving average is " ++ (show.avg) input
clean :: String -> [Double]
clean raw = map (\s -> read s :: Double) (lines raw)
@gavinwhyte
gavinwhyte / linearreg.hs
Last active August 29, 2015 14:23
Linear Regression
import Statistics.LinearRegression
import qualified Data.Vector.Unboxed as U
-- Computing a linear regression
main = do
let xs = U.fromList [1.0, 2.0, 3.0, 4.0, 5.0] :: U.Vector Double
let ys = U.fromList [1.0, 2.0, 1.3, 3.75, 2.25] :: U.Vector Double
let (b, m) = linearRegression xs ys
print $ concat ["y = ", show m, " x + ", show b]
@gavinwhyte
gavinwhyte / elk.sh
Created July 1, 2015 05:23
Dockerlogs
FROM java:8-jre
ENV KIBANA_VERSION 4.1.1-linux-x64
# Install ELK Required Dependancies
RUN set -x \
&& apt-get -qq update \
&& apt-get -qy install wget --no-install-recommends \
&& wget -qO - http://packages.elasticsearch.org/GPG-KEY-elasticsearch | apt-key add - \
&& echo "deb http://packages.elastic.co/elasticsearch/1.6/debian stable main" >> /etc/apt/sources.list \
zk1:
image: jplock/zookeeper:3.4.6
mesos1:
image: redjack/mesos-master:0.21.0
ports:
- "5050:5050"
links:
- "zk1:zookeeper1"
Multiple Linear Regression is the following model.
``` $$
h_{\theta}(x^{(i)}) = \theta^{T}x = \theta_{0} + \theta_{1}x
``` $$