Skip to content

Instantly share code, notes, and snippets.

@caiorss
caiorss / scalaReflection.scala
Created October 24, 2016 23:58
Get properties and methods in Scala
// 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))
@caiorss
caiorss / exchangeRates.scala
Last active November 7, 2016 23:31
Print European Central Bank Exchange Rates in Scala - Parse and download XML
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)))
@caiorss
caiorss / README.md
Last active October 22, 2016 19:12
Simple Scala GUI script

Usage:

 $ chmod +x scala-gui-script.scala
 $ ./scala-gui-script.scala

or

@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 / 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 / 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
#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">
#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}
@caiorss
caiorss / helm_config.el
Created October 1, 2016 23:39 — forked from izahn/helm_config.el
Helm config
;;; Completion hints for files and buffers buffers
(require 'helm-config)
(helm-mode 1)
;;rebind tab to do persistent action
(define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action)
;; make TAB works in terminal
(define-key helm-map (kbd "C-i") 'helm-execute-persistent-action)
;list actions using C-z
(define-key helm-map (kbd "C-z") 'helm-select-action)
@caiorss
caiorss / .ghci
Created March 1, 2016 18:55 — forked from pyrtsa/.ghci
.ghci — Essential parts of my Haskell REPL config.
-- Show loaded modules in window title and use a green "λ>" as prompt.
-- Subsequent lines of multi-line commands shall begin with " |".
:set prompt "\SOH\ESC]0;GHCi: %s\BEL\ESC[32;1m\STXλ>\SOH\ESC[0m\STX "
:set prompt2 "\SOH\ESC[32;1m\STX |\SOH\ESC[0m\STX "
-- Paste and evaluate text from the OS X clipboard. (The pasted text also
-- prints in yellow unless pasting quietly using :paste-quiet.)
:set -package process
:def paste \_ -> do { paste <- System.Process.readProcess "pbpaste" [] ""; let cmd = if '\n' `elem` paste then ":{\ntype Ö = ()\n" ++ paste ++ "\n:}" else paste in putStrLn ("\SOH\ESC[33m\STX" ++ paste ++ "\SOH\ESC[0m\STX") >> return (":cmd return " ++ show cmd) }
:def paste-quiet \_ -> do { paste <- System.Process.readProcess "pbpaste" [] ""; let cmd = if '\n' `elem` paste then ":{\ntype Ö = ()\n" ++ paste ++ "\n:}" else paste in return (":cmd return " ++ show cmd) }