Skip to content

Instantly share code, notes, and snippets.

View JaggerJo's full-sized avatar
🏠
Working from home

Josua Jäger JaggerJo

🏠
Working from home
View GitHub Profile
@JaggerJo
JaggerJo / post.md
Last active July 2, 2023 18:44
A 1000x improvement in performance

A 1000x improvement in performance

We recently had to provide (near) live data to a set of views in our application. After considering the most common ways to build this we decided to go with long polling. Our entire app is event based, so we know if a certain event happed the data might have changed. Lets assume the following types represent what can happen in our application:

type CounterEvent =
  | CounterWasIncremented byValue: int
@JaggerJo
JaggerJo / Post.md
Created September 27, 2022 13:16
Painless translations with F# and a bit of Magic.

Painless translations with F# and a bit of Magic.

A few weeks ago the unavoidable happened, a customer asked for a translated (non English) version of our SPA. We knew this would happen at some point, but as it happens always had more important work in our backlog.

There was no way to postpone this further.

Our requirements:

  • Translations can be outsourced/ done by non developers
  • Translations can be changed without releasing a new version
@JaggerJo
JaggerJo / React global state hook.fs
Created April 15, 2021 20:38
React global state hook fable fsharp
open Fable.React
type private GlobalState =
{| current: Map<string, obj>
update: Map<string, obj> -> unit |}
[<RequireQualifiedAccess>]
module GlobalState =
let private defaultValue =
@JaggerJo
JaggerJo / AppKit Application Menu.fs
Created March 7, 2021 16:15
AppKit application window in code
let editMenu =
let undoMenuItem =
let item = new NSMenuItem("Undo")
item.KeyEquivalent <- "z"
item.Action <- ObjCRuntime.Selector("undo:")
item
let redoMenuItem =
let item = new NSMenuItem("Redo")
item.KeyEquivalent <- "z"
@JaggerJo
JaggerJo / NSImageExtensions.fs
Last active February 9, 2021 21:32
Tinting Images (SF Symbols, App Kit, NSImage)
[<AutoOpen>]
module NSImageExtensions =
open AppKit
type NSImage with
static member GetSystemSymbolTinted (symbolName: string, accessibilityDescription: string, tint: NSColor) : NSImage =
let original = NSImage.GetSystemSymbol(symbolName, accessibilityDescription)
NSImage.ImageWithSize(original.Size, false, (fun bounds ->

Fsharp goodies (Vol 1)

After the 'F# Compiler Community Session' I read the first 1K lines of SyntaxTree.fs. That's what I learned about the language.

  1. There is a byte string

    let a = "abc"B
    val a : byte [] = [|97uy; 98uy; 99uy|]
module Observable =
open System
// ('a -> 'b -> unit) -> 'a -> IObservable<'b>
let subscribeWeakly callback target source =
let mutable sub:IDisposable = null
let mutable disposed = false
let wr = new WeakReference<_>(target)
@JaggerJo
JaggerJo / OpenGLControl.fs
Created July 5, 2019 10:52
OpenTK in Avalonia
type OpenGLControl() as this =
inherit Control()
let mode = new Graphics.GraphicsMode(new Graphics.ColorFormat(8, 8, 8, 8), 24, 0, 0, Graphics.ColorFormat.Empty, 1);
let mutable win : GameWindow = null
do
this.IsHitTestVisible <- false
override this.OnAttachedToVisualTree args =
@JaggerJo
JaggerJo / State.fs
Created January 29, 2019 18:47
F# State
(* State *)
type IState<'data> =
abstract member Data: 'data
abstract member Update: 'data -> unit
[<CLIEvent>]
abstract member Updated: IEvent<'data>
(* Tracked State *)
type ITrackedState<'data> =