Skip to content

Instantly share code, notes, and snippets.

@kerams
kerams / Sample.fs
Created May 31, 2020 11:40
Reusable debouncer hook for F#/React/Fable based on Feliz.UseElmish
// depends on https://www.nuget.org/packages/Feliz.UseElmish
module Debouncer =
type private DebounceState<'a> = {
Value: 'a
OnDone: 'a -> unit
Delay: int }
type private Msg<'a> =
| ValueChanged of 'a
| Debounced of 'a
@kerams
kerams / DistributedCaching.fs
Created June 14, 2022 17:25
StackExchange.Redis cache with sliding expiration support, ReadOnlyMemory and RecyclableMemoryStream on input.
module DistributedCaching
open System
open StackExchange.Redis
open System.Threading.Tasks
open Microsoft.IO
open System.Buffers
type IDistributedCache =
abstract GetAsync: key: string -> Task<byte[] voption>
@kerams
kerams / 1.md
Last active January 1, 2022 15:50
Lazy loading of localization texts in Fable

Lazy loading of localization texts in Fable

Fable 3, Elmish, .NET 5, React, Webpack 5, npm. Demo code at https://github.com/kerams/fable-lazy-load-localization-sample.

At some point during the lifetime of your Fable application you may decide you need to support more than one language (in this post I am concerned with UI texts only, not data that is sent from the server) as well as the ability to switch the desired language on the fly. Let's say you have to support several languages with a ton of text each. Including them in your main application file/bundle will obviously make using them very straightforward and easy, but would prove incredibly wasteful. A single user will hardly use multiple languages, so having them download something they will never see or make use of does not make much sense.

While you could try using a full-fledged framework like react-i18next to handle all your localization needs, I'll detail the simplest means of getting parts of your UI localized tha

#!/bin/bash
#
# Network speed testing script put together by `aFriend` from LowEndTalk.
# http://lowendtalk.com/discussion/comment/561833/#Comment_561833
#
function download_benchmark() {
DOWNLOAD_SPEED=`wget -O /dev/null $2 2>&1 | awk '/\/dev\/null/ {speed=$3 $4} END {gsub(/\(|\)/,"",speed); print speed}'`
echo "Got $DOWNLOAD_SPEED : $1 ($2)"
}