Usage:
$ chmod +x scala-gui-script.scala
$ ./scala-gui-script.scalaor
| #I @"packages\Nuget.Core.2.8.3\lib\net40-Client" | |
| #r "NuGet.Core.dll" | |
| #r "System.Xml.Linq.dll" | |
| let repository = | |
| NuGet.PackageRepositoryFactory.Default.CreateRepository | |
| "https://nuget.org/api/v2" | |
| type NuGetStat = | |
| { Id: string; DownloadCount:int} |
| #I @"..\packages\" | |
| #r @"FSharp.Data\lib\net40\FSharp.Data.dll" | |
| #load @"FSPlot\FsPlotBootstrap.fsx" | |
| #r @"Deedle\lib\net40\Deedle.dll" | |
| do fsi.AddPrinter(fun (printer:Deedle.Internal.IFsiFormattable) -> "\n" + (printer.Format())) | |
| open Deedle | |
| open FSharp.Data | |
| open System | |
| type Twitter = CsvProvider< @"C:\Users\Isaac\Downloads\fsharp_2013-2014.csv"> |
| // 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 |
| 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 |
| 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") |
Usage:
$ chmod +x scala-gui-script.scala
$ ./scala-gui-script.scalaor
| import scala.xml._ | |
| val xml = XML.load("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml") | |
| val rates = (xml.child \\ "@rate").map(_.text.toFloat) | |
| val currencies = (xml.child \\ "@currency").map(_.text) | |
| val usdRate = currencies.zip(rates).find(t => t._1 == "USD").get._2 | |
| currencies | |
| .zip(rates) | |
| .foreach(t => println("%s\t\t%.3f".format(t._1, t._2 / usdRate))) |
| // Based on: https://gist.github.com/dajobe/7586938 | |
| // | |
| // | |
| // | |
| // Show object methods | |
| // | |
| def showMethods(x: Any) = | |
| x.getClass.getMethods.map(_.getName).distinct.sorted.foreach(println) | |
| scala> showMethods(Some(10)) |
| // AGDT - Algebraic Data type | |
| // List implementation | |
| // | |
| sealed trait AList[+A] | |
| case object ANil extends AList[Nothing] | |
| case class Cons[A](head: A, tail: AList[A]) extends AList[A] | |
| scala> Cons(1, Cons(10, Cons(30, ANil))) | |
| res74: Cons[Int] = Cons(1,Cons(10,Cons(30,ANil))) |
| // Print Systme properties | |
| // | |
| // | |
| scala> System.getProperty("path.separator") | |
| res29: String = : | |
| scala> System.getProperty("os.name") | |
| res30: String = Linux | |
| scala> System.getProperty("os.arch") |