Skip to content

Instantly share code, notes, and snippets.

@caiorss
caiorss / PCA.fsx
Created October 4, 2016 01:21 — forked from MartinBodocky/PCA.fsx
PCA with Accord.Net and FSharp.Charting
// Inspired by http://arxiv.org/abs/1210.7463
// reference accord framework
#r "../packages/Accord.3.0.2/lib/net45/Accord.dll"
#r "../packages/Accord.Controls.3.0.2/lib/net45/Accord.Controls.dll"
#r "../packages/Accord.IO.3.0.2/lib/net45/Accord.IO.dll"
#r "../packages/Accord.Math.3.0.2/lib/net45/Accord.Math.dll"
#r "../packages/Accord.Statistics.3.0.2/lib/net45/Accord.Statistics.dll"
//reference deelde with fsharp charting
@caiorss
caiorss / msft.csv
Created October 4, 2016 01:23 — forked from gavlooth/msft.csv
Date Open High Low Close Volume Adj Close
2013-11-07 37.96 38.01 37.43 37.50 60437400 37.50
2013-11-06 37.24 38.22 37.06 38.18 88615100 38.18
2013-11-05 35.79 36.71 35.77 36.64 51646300 36.64
2013-11-04 35.59 35.98 35.55 35.94 28060700 35.94
2013-11-01 35.67 35.69 35.39 35.53 40264600 35.53
2013-10-31 35.66 35.69 35.34 35.41 41682300 35.41
2013-10-30 35.53 35.79 35.43 35.54 36997700 35.54
2013-10-29 35.63 35.72 35.26 35.52 31702200 35.52
2013-10-28 35.61 35.73 35.27 35.57 38383600 35.57
@caiorss
caiorss / accord.fs
Created October 4, 2016 01:25 — forked from isaacabraham/accord.fs
accord on f#?
open Accord.MachineLearning.FSharp
open Deedle
let data = [ ("D1", "Sunny", "Hot", "High", "Weak", "No" )
("D2", "Sunny", "Hot", "High", "Strong", "No" )
("D3", "Overcast", "Hot", "High", "Weak", "Yes")
("D4", "Rain", "Mild", "High", "Weak", "Yes")
("D5", "Rain", "Cool", "Normal", "Weak", "Yes")
("D6", "Rain", "Cool", "Normal", "Strong", "No" )
("D7", "Overcast", "Cool", "Normal", "Strong", "Yes")
@caiorss
caiorss / MOption.scala
Created October 25, 2016 01:29 — forked from ElectricCoffee/MOption.scala
Adds map and flatMap as extension methods to Scala, for those who don't want/need scalaz for their project, is fully compatible with for-comprehensions
package extension.monad
trait Monad[A, M[_]] {
// >>= :: Monad m => m a -> (a -> m b) -> m b
def flatMap[B](input: A => M[B]): M[B] // AKA "bind"
}
trait Functor[A, F[_]] {
// fmap :: Functor f => (a -> b) -> f a -> f b
def map[B](input: A => B): F[B] // AKA "fmap"
/*
* The trait Nat is provided by the text.
*/
trait Nat {
def isZero: Boolean
def predecessor: Nat
def successor: Nat
def +(that: Nat): Nat
def -(that: Nat): Nat
@caiorss
caiorss / PaypalTransaction.scala
Created October 25, 2016 01:31 — forked from mslinn/PaypalTransaction.scala
Attempt to persist entities with >22 fields via Slick. Cannot find documentation on how nested tuples are supposed to work; tried creating two helper classes (CustomerAddress and PaymentDetail). Compiler error is: scala: overloaded method value <> with alternatives: [R(in method <>)(in method <>)(in method <>)(in method <>)(in method <>)(in meth…
package com.micronautics.paypal
import java.util.{ List, Map }
import collection.JavaConversions._
import collection.immutable.HashMap
import controllers.Email
import org.joda.time.DateTime
import slick.driver.MySQLDriver.simple._
import java.util
// And by the way, please feel free to contribute, correct errors, etc!
trait Functor[F[_]] {
def fmap[A, B](f: A => B): F[A] => F[B]
}
object Functor {
val ListFunctor: Functor[List] =
new Functor[List] {
def fmap[A, B](f: A => B) =
case class Circle(radius: Double) {
def area = radius * radius * Math.PI
}
case class Rectangle(side: Double) {
def area = side * side
}
case class Triangle(base: Double, height: Double) {
def area = 0.5d * base * height
@caiorss
caiorss / GADTs.scala
Created October 25, 2016 01:42 — forked from jroesch/GADTs.scala
Scala GADTs
/* http://www.haskell.org/ghc/docs/latest/html/users_guide/data-type-extensions.html#gadt
Generalized Algebraic Datatypes in Scala */
trait Term[A]
case class Lit(x: Int) extends Term[Int]
case class Succ(x: Term[Int]) extends Term[Int]
case class IsZero(x: Term[Int]) extends Term[Boolean]
case class If[A](guard: Term[Boolean], t: Term[A], y: Term[A]) extends Term[A]
case class Pair[A, B](x: Term[A], y: Term[B]) extends Term[(A,B)]
@caiorss
caiorss / gist:3db6d420423170476ae6b1e0559ca5aa
Created October 25, 2016 01:47 — forked from denen99/gist:6765084
Coursera week 2 scala tests
package funsets
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
/**
* This class is a test suite for the methods in object FunSets. To run
* the test suite, you can either: