Skip to content

Instantly share code, notes, and snippets.

@dsyme
Last active November 1, 2022 18:11
Show Gist options
  • Select an option

  • Save dsyme/9b18608b78dccf92ba33 to your computer and use it in GitHub Desktop.

Select an option

Save dsyme/9b18608b78dccf92ba33 to your computer and use it in GitHub Desktop.

Revisions

  1. dsyme revised this gist Feb 14, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.fs
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@
    // downloaded by the user (by executing the first part of the script) the reference
    // shows as resolved and can be used.
    //
    // Paket is then used to fetch a set of F# packages, which are then used later inn the script.
    // Paket is then used to fetch a set of F# packages, which are then used later in the script.
    //

    //------------------------------------------
  2. dsyme revised this gist Feb 13, 2015. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion gistfile1.fs
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,10 @@ Environment.CurrentDirectory <- __SOURCE_DIRECTORY__

    if not (File.Exists "paket.exe") then
    let url = "https://github.com/fsprojects/Paket/releases/download/0.26.3/paket.exe"
    use wc = new Net.WebClient() in let tmp = Path.GetTempFileName() in wc.DownloadFile(url, tmp); File.Move(tmp,Path.GetFileName url)
    use wc = new Net.WebClient()
    let tmp = Path.GetTempFileName()
    wc.DownloadFile(url, tmp);
    File.Move(tmp,Path.GetFileName url)

    // Step 1. Resolve and install the packages

  3. dsyme revised this gist Feb 3, 2015. 1 changed file with 1 addition and 9 deletions.
    10 changes: 1 addition & 9 deletions gistfile1.fs
    Original file line number Diff line number Diff line change
    @@ -21,21 +21,13 @@ open System.IO
    Environment.CurrentDirectory <- __SOURCE_DIRECTORY__

    if not (File.Exists "paket.exe") then
    let url = "https://github.com/fsprojects/Paket/releases/download/0.26.2/paket.exe"
    let url = "https://github.com/fsprojects/Paket/releases/download/0.26.3/paket.exe"
    use wc = new Net.WebClient() in let tmp = Path.GetTempFileName() in wc.DownloadFile(url, tmp); File.Move(tmp,Path.GetFileName url)

    // Step 1. Resolve and install the packages

    #r "paket.exe"

    // This will be added to paket.exe in a future version
    module Paket =
    type Scripting() =
    static member Install(dependencies, ?force, ?hard) =
    System.IO.File.WriteAllText("paket.dependencies", dependencies)
    let dependencies = Paket.Dependencies.Locate(__SOURCE_DIRECTORY__)
    dependencies.Install(force=defaultArg force false, hard=defaultArg hard false)

    Paket.Scripting.Install """
    source https://nuget.org/api/v2
    nuget Suave 0.16.0
  4. dsyme revised this gist Feb 2, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gistfile1.fs
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,9 @@
    // Initially the #r "paket.exe" reference is shown as unresolved. Once it has been
    // downloaded by the user (by executing the first part of the script) the reference
    // shows as resolved and can be used.
    //
    // Paket is then used to fetch a set of F# packages, which are then used later inn the script.
    //

    //------------------------------------------
    // Step 0. Boilerplate to get the paket.exe tool
  5. dsyme revised this gist Feb 2, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gistfile1.fs
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    //==========================================
    // Working fully self-contained getting-started example for Suave Web Server scripting
    //
    // Note you don't need to have _anything_ installed before starting with this script. Nothing
    // but F# Interactive and this script.
    //
    // This script fetches the Paket.exe component which is referenced later in the script.
    // Initially the #r "paket.exe" reference is shown as unresolved. Once it has been
    // downloaded by the user (by executing the first part of the script) the reference
  6. dsyme revised this gist Feb 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.fs
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    // shows as resolved and can be used.

    //------------------------------------------
    // Step 0. Boilerplate to get the package bootstrap
    // Step 0. Boilerplate to get the paket.exe tool

    open System
    open System.IO
  7. dsyme revised this gist Feb 2, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.fs
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@
    // shows as resolved and can be used.

    //------------------------------------------
    // Step 0. Get the package bootstrap
    // Step 0. Boilerplate to get the package bootstrap

    open System
    open System.IO
  8. dsyme revised this gist Feb 2, 2015. No changes.
  9. dsyme created this gist Feb 2, 2015.
    56 changes: 56 additions & 0 deletions gistfile1.fs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    //==========================================
    // Working fully self-contained getting-started example for Suave Web Server scripting
    //
    // This script fetches the Paket.exe component which is referenced later in the script.
    // Initially the #r "paket.exe" reference is shown as unresolved. Once it has been
    // downloaded by the user (by executing the first part of the script) the reference
    // shows as resolved and can be used.

    //------------------------------------------
    // Step 0. Get the package bootstrap

    open System
    open System.IO

    Environment.CurrentDirectory <- __SOURCE_DIRECTORY__

    if not (File.Exists "paket.exe") then
    let url = "https://github.com/fsprojects/Paket/releases/download/0.26.2/paket.exe"
    use wc = new Net.WebClient() in let tmp = Path.GetTempFileName() in wc.DownloadFile(url, tmp); File.Move(tmp,Path.GetFileName url)

    // Step 1. Resolve and install the packages

    #r "paket.exe"

    // This will be added to paket.exe in a future version
    module Paket =
    type Scripting() =
    static member Install(dependencies, ?force, ?hard) =
    System.IO.File.WriteAllText("paket.dependencies", dependencies)
    let dependencies = Paket.Dependencies.Locate(__SOURCE_DIRECTORY__)
    dependencies.Install(force=defaultArg force false, hard=defaultArg hard false)

    Paket.Scripting.Install """
    source https://nuget.org/api/v2
    nuget Suave 0.16.0
    nuget FSharp.Data
    nuget FSharp.Charting
    """;;

    // Step 2. Use the packages

    #r "packages/Suave/lib/Suave.dll"
    #r "packages/FSharp.Data/lib/net40/FSharp.Data.dll"
    #r "packages/FSharp.Charting/lib/net40/FSharp.Charting.dll"

    let ctxt = FSharp.Data.WorldBankData.GetDataContext()

    let data = ctxt.Countries.Algeria.Indicators.``GDP (current US$)``

    open Suave // always open suave
    open Suave.Http.Successful // for OK-result
    open Suave.Web // for config

    web_server default_config (OK (sprintf "Hello World! In 2010 Algeria earned %f " data.[2010]))