Skip to content

Instantly share code, notes, and snippets.

View ovatsus's full-sized avatar

Gustavo Guerra ovatsus

  • London, United Kingdom
View GitHub Profile
@ovatsus
ovatsus / windowsPhoneToAndroidMessageImporter.fsx
Last active June 13, 2016 00:50
Windows Phone to Android message importer
#r "packages/FSharp.Data.2.3.0-beta1/lib/net40/FSharp.Data.dll"
#r "System.Xml.Linq.dll"
open System
open System.Text
open FSharp.Data
[<Literal>]
let androidSample = """
<smses count="40">
module Html =
type HtmlNode =
| HtmlElement of name:string * attribute:HtmlAttribute list
| HtmlText of content:string *parent:HtmlNode
and HtmlAttribute =
| HtmlAttribute of name:string * value:string * parent:HtmlNode
let createElement name attrs =
@ovatsus
ovatsus / FootballStats.fsx
Last active January 1, 2016 09:19
Alternative implementation of Screen Scraping College Football Statistics (http://jamessdixon.wordpress.com/2013/12/24/screen-scraping-college-football-statistics/)
#r @"packages\FSharp.Data.2.0.0-alpha2\lib\net40\FSharp.Data.dll"
#r "System.Xml.Linq"
open System.Xml.Linq
open FSharp.Data
open FSharp.Data.Json
open FSharp.Data.Json.Extensions
open FSharp.Net
// Without Type Providers
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><body><div class="page"><div class="header"><div class="hInner"><div class="hBar"><div id="div-gpt-ad-8507337232-0"></div></div><div class="title clr"><a href="/" class="logo"><img src="/img/nremed.png" alt="National Rail Enquiries" /></a></div></div></div><div class="header clr"><div class="header-panel clr"><h1>Live departure boards</h1><a class="rBtn" href="javascript:location.reload(true)"><img width="15" height="17" alt="Reload" src="/img/arrowcircle.gif" /></a></div></div><div class="pageCont"><table class="jDetails jDest"><tr><td class="label"><strong>22:44</strong></td><td colspan="2">London Bridge </td></tr><tr class="pb10"><td class="label">To:</td><td colspan="2">Orpington <small>Southeastern</small></td></tr></table><!-- <table class="jDetails jDest"><tr><td class="label"><strong>22:44<
@ovatsus
ovatsus / gist:7608238
Created November 22, 2013 22:50
NuGet reference="false" proposal
<?xml version="1.0" encoding="utf-8"?>
<package xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<id>@project@</id>
<version>@build.number@</version>
<authors>@authors@</authors>
<owners>@authors@</owners>
<licenseUrl>http://github.com/fsharp/FSharp.Data/blob/master/LICENSE.md</licenseUrl>
<projectUrl>http://fsharp.github.com/FSharp.Data</projectUrl>
<iconUrl>https://raw.github.com/fsharp/FSharp.Data/master/misc/logo.png</iconUrl>
@ovatsus
ovatsus / after
Created July 19, 2013 21:32
Fantomas #83
(new CsvFile<_>(new Func<_, _, _>(fun (parent : obj) (row : string []) -> Operations.GetNonOptionalValue("Name", Operations.ConvertString(Operations.AsOption(row.[0])), Operations.AsOption(row.[0])), Operations.GetNonOptionalValue("Distance", Operations.ConvertDecimal("", Operations.AsOption(row.[1])), Operations.AsOption(row.[1])), Operations.GetNonOptionalValue("Time", Operations.ConvertDecimal("", Operations.AsOption(row.[2])), Operations.AsOption(row.[2]))),
new Func<_, _>(fun (row : _ * _ * _) ->
[|Operations.ConvertStringBack(Operations.GetOptionalValue(let x, _, _ = row
x))
Operations.ConvertDecimalBack(, ,
Operations.GetOptionalValue(let _, x, _ = row
x))
Operations.ConvertDecimalBack( O,
#r "bin/v40/FSharp.Data.dll"
open FSharp.Data.Csv
open FSharp.Data.Csv.Extensions
let map f (csvFile:CsvFile) =
let headers = csvFile.Headers |> f |> String.concat ","
let data = csvFile.Data |> Seq.map (fun row -> row.Columns |> f |> String.concat ",") |> String.concat "\n"
CsvFile.Parse(headers + "\n" + data)
let filter f (csvFile:CsvFile) =
@ovatsus
ovatsus / gist:5354478
Last active December 16, 2015 01:19
WorldBank API
This file has been truncated, but you can view the full file.
class WorldBankDataProvider
static member GetDataContext: () -> WorldBankDataProvider+ServiceTypes+WorldBankDataService
class WorldBankDataProvider+ServiceTypes
class WorldBankDataProvider+ServiceTypes+WorldBankDataService : FDR.WorldBank.WorldBankData
member Countries: WorldBankDataProvider+ServiceTypes+Countries with get
member Regions: WorldBankDataProvider+ServiceTypes+Regions with get
member Topics: WorldBankDataProvider+ServiceTypes+Topics with get
@ovatsus
ovatsus / CsvFile.fsx
Last active August 19, 2016 22:37
R <-> FSharp.Data comparison
#r "packages/FSharp.Data.1.1.10/lib/net40/FSharp.Data.dll"
open FSharp.Data.Csv
open FSharp.Data.Csv.Extensions
let csv = CsvFile.Load("http://faculty.washington.edu/heagerty/Books/Biostatistics/DATA/ozone.csv")
//What are the column names of the dataset?
csv.Headers
@ovatsus
ovatsus / scriptSetup.fsx
Created September 2, 2012 12:11 — forked from nrolland/scriptSetup.fsx
Script for loading dependencies in fsx file from a solution/project
//This script generates
//a file named __project.fsx, for each proejct which can be #load "__project.fsx" in script intending to use the same dependency graph as the code in VS
//a file named __solmerged.fsx, at the solution root which can be #load "__solmerged.fsx" in script intending to use the same dependency graph as the code in VS
//In both cases, this enforce that a script compiling in VS should work from within FSI
#if INTERACTIVE
#r "System.Xml"
#r "System.Xml.Linq"
#endif