Skip to content

Instantly share code, notes, and snippets.

View pkese's full-sized avatar

Peter Keše pkese

  • JSI, OECD
  • Ljubljana
View GitHub Profile
@pkese
pkese / Holidays.fs
Last active November 13, 2023 17:40
Local holidays
open System
type DateOnly with
/// returns the date of Easter Monday for the given year
static member gaussEasterMonday (Y:int) =
let P = float Y / 100.0 |> floor // century
let M = // M depends on the century of year Y. For 19th century, M = 23. For the 21st century, M = 24 and so on
let Q = (13.0 + 8.0 * P) / 25.0 |> floor
int (15.0 - Q + P - (P / 4.0 |> floor)) % 30
let D = // The number of days to be added to March 21 to find the date of the Paschal Full Moon is
@pkese
pkese / PlotlyRepro.ipynb
Created March 1, 2023 16:10
Chart flashing Polyglot repro
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pkese
pkese / reformatted.fs
Last active August 19, 2022 19:08
OOP style minimal API formatting
open System
open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.DependencyInjection
[<EntryPoint>]
let main args =
let builder = WebApplication.CreateBuilder(args)
builder
.Services
@pkese
pkese / episari65.fsx
Last active November 13, 2021 09:33
#!/usr/bin/env -S dotnet fsi /langversion:preview
// - Fetch EPISARI hospitalizations data from podatki.gov.si
// - Fetch vaccination data from api.sledilnik.org/api/vaccinations
// - Mix in static population demography data
// - Render hospitalizatized per 100k population json
#r "nuget: FSharp.Data, 4.2.5"
#r "nuget: FSharp.Json, 0.4.1"
@pkese
pkese / chart.js
Created October 24, 2021 11:05
Fetch vaccinations vs hospitalizations data from Our World In Data
<html>
<head>
<title>Covid vaccinations vs hospitalizations</title>
<script src="https://code.highcharts.com/highcharts.src.js"></script>
</head>
<body>
<figure class="highcharts-figure">
<div id="container" style="width:100%; height:100%;"></div>
</figure>
@pkese
pkese / PavedRoadsPerCapita.fsx
Created September 11, 2021 12:27
Join two tables from Wikipedia to render list of counties sorted by kilometres of paved roads per capita.
#!/usr/bin/dotnet fsi
#r "nuget: FSharp.Data, 4.2.2"
open FSharp.Data
open System
type RoadsHtml = HtmlProvider<"https://en.wikipedia.org/wiki/List_of_countries_by_road_network_size">
let roadsHtml = RoadsHtml.GetSample()
let roads =
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@pkese
pkese / fizzbuzz.fs
Last active February 1, 2021 10:45
let (|IsMultiple|_|) n x = if x % n = 0 then Some n else None
[1..100]
|> List.map (function
| IsMultiple 15 x -> "FizzBuzz"
| IsMultiple 5 x -> "Buzz"
| IsMultiple 3 x -> "Fizz"
| x -> $"{x}")
|> List.iter (printfn "%s")
@pkese
pkese / nixos.try.md
Last active July 25, 2020 23:44
My NixOS experience

My first steps with NixOS

Background:

  • I'd like to use NixOS to manage a 'container' with some services (e.g. Solr) on my headless server.
  • I'm currently running lxc, lxd and docker containers which is tech that I'm familiar with.
  • I'm assuming Nix can provide similar experience: presumably a pure λ(nix-config) -> reproducible container.

Ideally there'd be a short getting started tutorial. My familiarity is:

@pkese
pkese / adaptive_demo.fs
Last active August 27, 2024 22:43
FSharp.Data.Adaptive sample with React
module AdaptiveSample
open Fable.React
open Fable.React.Props
open FSharp.Data.Adaptive
let useAdaptive (v: aval<'T>) =
// initialize hook with initial value
let stateHook = Hooks.useState (AVal.force v)
let onChange () =