Skip to content

Instantly share code, notes, and snippets.

View davidglassborow's full-sized avatar

David Glassborow davidglassborow

View GitHub Profile
@davidglassborow
davidglassborow / README.md
Created December 3, 2024 12:31 — forked from neon-sunset/README.md
Quick workflow for using F# interactive to build small native console applications
  1. Get .NET SDK with sudo apt install dotnet9 (or dotnet-sdk-9.0), brew install dotnet for macOS
  2. Get FSharpPacker tool with dotnet tool install -g --allow-roll-forward FSharpPacker
  3. Make an F# interactive script file (e.g. copy the phash.fsx below)
  4. Compile it with fspack {your-script.fsx} -f net9.0 -o {destination} --aot
    (in this example: fspack phash.fsx -f net9.0 -o . --aot), note that it will take some time to do so for the first time - .NET needs to fetch IL AOT Compiler from Nuget
  5. Profit! You have compiled an F# script to a native binary
  6. (Optional) If you add fspk.fish, the process is simplified to fspk {my-script}.fsx!

Note 1: if you are not using macOS or FreeBSD, give https://github.com/ieviev/fflat a try which can produce even smaller binaries

@davidglassborow
davidglassborow / BatchSimdDot.cs
Created November 9, 2024 13:55 — forked from xoofx/BatchSimdDot.cs
BatchSimdDot Example
// Comment about https://mastodon.social/@brandewinder@hachyderm.io/113064780292323247
// https://brandewinder.com/2024/09/01/should-i-use-simd-vectors/
using System.Numerics;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
public class VectorProcessor
{
public static float Take2(float[] left, float[] right)
{
@davidglassborow
davidglassborow / index.html
Created October 24, 2024 11:03
Globe with some data
<!DOCTYPE html>
<html>
<head>
<title>Interactive 3D Globe</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/7.8.5/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/topojson/3.0.2/topojson.min.js"></script>
<style>
body {
margin: 0;
background: #000;
@davidglassborow
davidglassborow / Example.fs
Created March 27, 2023 09:17 — forked from OnurGumus/Example.fs
MSAL wrapper Fable
module Example
open Fable.Core
open Fable.Core.JsInterop
open Msal
open Configuration
open Account
open System.Collections.Generic
module private Internal =
@davidglassborow
davidglassborow / HashRings.fs
Created January 6, 2023 15:55 — forked from Horusiath/HashRings.fs
Hash rings implementations in F#
module Demo.HashRings
open System
open System.Collections.Generic
/// Range is a tuple describing (s,e] - where `s` is start
/// (exclusive) index, while `e` is end (inclusive) index.
type Range = ValueTuple<int,int>
[<RequireQualifiedAccess>]
@davidglassborow
davidglassborow / chords.fsx
Created December 23, 2022 23:26 — forked from mnebes/chords.fsx
Chord progressions with F#
open System
type Interval =
| PerfectUnison
| MinorSecond
| MajorSecond
| MinorThird | AugmentedSecond // Enharmonically the same in 12TET
| MajorThird
| PerfectFourth
| DiminishedFifth | AugmentedFourth // Enharmonically the same in 12TET
@davidglassborow
davidglassborow / Podman as a Docker Desktop replacement.md
Created December 23, 2022 15:35 — forked from acdha/Podman as a Docker Desktop replacement.md
Instructions for using Podman as a Docker.app replacement on MacOS

Podman as a Docker Desktop alternative

Prerequisites

  1. Install Homebrew from https://brew.sh

Install Podman

$ brew install podman
using System;
using System.Threading.Tasks;
namespace System.Collections.Concurrent
{
public static class ConcurrentDictionaryExtensions
{
/// <summary>
/// Provides an alternative to <see cref="ConcurrentDictionary{TKey, TValue}.GetOrAdd(TKey, Func{TKey, TValue})"/> that disposes values that implement <see cref="IDisposable"/>.
/// </summary>
@davidglassborow
davidglassborow / privateDu.fs
Created June 1, 2022 14:54
Alternate version of Private DU constructor
// http://www.fssnip.net/ma/title/Alternate-version-of-Private-DU-constructor
module Email =
type EmailAddress =
private
| ValidEmail of string
| InvalidEmail of string
let ofString = function
| "validEmail" -> ValidEmail "validEmail"
| invalid -> InvalidEmail invalid
@davidglassborow
davidglassborow / GenericSqlProxy.cs
Created May 5, 2022 17:12
Generic TCP proxy from MS SMO project
// https://github.com/microsoft/sql-server-samples/blob/master/samples/features/sql-management-objects/src/GenericSqlProxy.cs
using System;
using System.Data.SqlClient;
using System.Net.Sockets;
using System.Net;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;