Skip to content

Instantly share code, notes, and snippets.

View alfonsogarciacaro's full-sized avatar

Alfonso Garcia-Caro alfonsogarciacaro

View GitHub Profile
@alfonsogarciacaro
alfonsogarciacaro / Flask.fs
Created September 18, 2021 12:27
Fable decorators for Flask
module Flask =
type App() = class end
[<AbstractClass>]
type RouteAttribute(route: string) =
inherit JS.DecoratorAttribute()
abstract App: App
override this.Decorate(fn) =
let app = this.App // Access the app
// Do some initialization
@alfonsogarciacaro
alfonsogarciacaro / test.fs
Last active June 3, 2021 03:59
Fable JS tagged templates
open System
open System.Text.RegularExpressions
open Fable.Core
let getJsTemplate (s: FormattableString) =
let str = s.Format
let mutable prevIndex = 0
let matches = Regex.Matches(str, @"{\d+}")
Array.init (matches.Count + 1) (fun i ->
if i < matches.Count then
@alfonsogarciacaro
alfonsogarciacaro / ConsoleTracer.fs
Last active May 12, 2022 12:43
A cleaner console tracer for Elmish apps
module ConsoleTracer
open System
open Fable.Core
// Use it when initializing your Elmish app like this
//|> Program.withTrace ConsoleTracer.withTrace
let getMsgNameAndFields (t: Type) (x: 'Msg): string * obj =
let rec getCaseName (t: Type) (acc: string list) (x: obj) =
@alfonsogarciacaro
alfonsogarciacaro / README.md
Created October 14, 2019 15:38
.NET DateTime pitfalls or how an API design can shape developers' minds

.NET DateTime pitfalls or how an API design can shape developers' minds

What's in a DateTime? Or more specifically what's in .NET System.DateTime? Here is a class that we use every day yet few people really understand. I too had a wrong understanding of it until very recently and it's only now that I feel confident enough (or maybe it's just an illusion?) to write this post to organize my thoughts and try to help others, including my future self.

DISCLAIMER: This article contains some simplifications (e.g. UTC is not formally timezone 0) for the sake of a better explanation.

DateTimes are known for being particularly tricky in computing, this is because they mix two similar yet different concepts. Let's start by defining the simplest of them. We'll use another word to make the distinction more clear: timestamp. What's a timestamp in computing terms? It's just a value in a unidimensional coordinate system that defines how far is a point from the coordina

@alfonsogarciacaro
alfonsogarciacaro / Script.fsx
Created January 25, 2019 19:58
Extra Thoth.Json coders for enum types
open Thoth.Json.Net
type MyEnum =
| Foo = 1
| Bar = 2
type MyRecord =
{ Field1: string
Field2: MyEnum }
@alfonsogarciacaro
alfonsogarciacaro / fable-repl.css
Created December 17, 2018 11:02
Created with Fable REPL
#app div {
margin: 0;
padding: 20px;
background-color: lightyellow;
}
@alfonsogarciacaro
alfonsogarciacaro / fable-repl.css
Created December 17, 2018 11:02
Created with Fable REPL
#app div {
margin: 0;
padding: 20px;
background-color: lightyellow;
}
@alfonsogarciacaro
alfonsogarciacaro / fable-repl.css
Last active December 16, 2018 22:47
Created with Fable REPL
.card.is-avatar {
max-width: 350px;
margin: auto;
}
.card.is-avatar .card-image {
display: flex;
justify-content: center;
align-items: center;
padding: 25px 0 0;
}
@alfonsogarciacaro
alfonsogarciacaro / index.html
Last active October 3, 2018 06:15
Fable REPL gist test
<!doctype html>
<html>
<head>
<title>Fable + Recharts</title>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script>
<script crossorigin src="https://unpkg.com/prop-types@15.6/prop-types.min.js"></script>
<script crossorigin src="https://unpkg.com/recharts@1.3.1/umd/Recharts.min.js"></script>
@alfonsogarciacaro
alfonsogarciacaro / README.md
Last active June 19, 2018 14:17
Fable talk proposals

Option 1: Fable got a new major release and you won't believe what happened next

This talk will be about the release of Fable 2: what benefits if brings to Fable projects, the performance improvements and how it can be used to better interact with JS tooling and libraries. I will also talk about the proccess of rewriting the code for this new major version, how it is to work with so many wonderful contributors and the lessons learned that hopefully can be applied to other projects as well.

Option 2: Ten celebs you didn't know that used Fable

I cannot reveal the names right now, but there're many Hollywood celebrities that use Fable when not filming. This talk will be about different ways of using Fable. Celebrities use Fable not only for creating dynamic webs, but also for generating static sites, visualizing data, writing native mobile and desktop apps, creting funny games or amazing presentations.

Option 3: Your neighbour is making millions from home with this Fable tricks