Skip to content

Instantly share code, notes, and snippets.

@kevmal
kevmal / avaplot.fsx
Created October 2, 2023 17:02
FSI plotting with Avalonia and ScottPlot
#r "nuget:Avalonia.Desktop"
#r "nuget:Avalonia.FuncUI"
#r "nuget:Avalonia.Themes.Fluent"
#r "nuget:ScottPlot.Avalonia"
// ScottPlot.Avalonia exists, without global open Avalonia.* failes after ScottPlot is opened.
// This really only matters if you want to rerun this entire script without resetting
open System
open global.Avalonia
@kevmal
kevmal / providedtypehelpers.fsx
Last active April 20, 2023 17:23
Expr for Option<ProvidedTypeDef>.Value
#r "nuget:Qit,0.0.2-alpha2"
open System
open Qit.ProviderImplementation.ProvidedTypes
open System.Reflection
type CtorFml(tpdef : Type, genericMethodDefinition: ConstructorInfo, parameters: Type[]) =
inherit ConstructorInfo()
let gps = tpdef.GetGenericArguments()
@kevmal
kevmal / CodeGen.fsx
Last active April 17, 2023 16:45
Code gen ops
open System
open System.Runtime.InteropServices
open System.Runtime.CompilerServices
type CallerInfo =
{
Inherited : bool
MemberName : string
Path : string
LineNumber : int
open System
open System.Reflection
let rec matchTypeParameters (t1 : Type) (t2 : Type) =
if t1.IsGenericParameter then
Seq.singleton (t1,t2)
else
let ga1 = t1.GetGenericArguments()
let ga2 = t2.GetGenericArguments()
if ga1.Length <> ga2.Length then
@kevmal
kevmal / tensorflowwrap.fsx
Created August 23, 2019 23:01
quick TensorFlowSharp wrapper for F#
This file has been truncated, but you can view the full file.
#load @"E:\profile\fsi\.\packagegrp\CE8A46E8AAAB2DAD2A75F9585A0E8F0563C98AEA859A445DC4BF25F4B0C33943\.paket\load\main.group.fsx"
open System
open System.IO
open TensorFlow
Environment.SetEnvironmentVariable("Path",
Environment.GetEnvironmentVariable("Path") + ";" + @"E:\profile\fsi\packagegrp\CE8A46E8AAAB2DAD2A75F9585A0E8F0563C98AEA859A445DC4BF25F4B0C33943\packages\TensorFlowSharp\runtimes\win7-x64\native")
@kevmal
kevmal / vsinstance of fsi.fsx
Created August 9, 2019 18:47
get the EnvDTE80.DTE2 object of the VS instance hosting the current fsi
//DTE object of VS hosting the FSI which runs this
//See: https://stackoverflow.com/questions/3102472/f-c-fsx-script-files-and-project-references/3102579#3102579
//and: https://blogs.msdn.microsoft.com/kirillosenkov/2011/08/10/how-to-get-dte-from-visual-studio-process-id/
#r "EnvDTE"
#r "EnvDTE80"
#r "VSLangProj"
open System
open System.Runtime.InteropServices
open System.Runtime.InteropServices.ComTypes
let makeExpr x =
let rec func (m : Expression) ps =
match m with
| :? MethodCallExpression as x ->
let lambda = x.Arguments.[0] :?> LambdaExpression
func lambda.Body (lambda.Parameters.[0] :: ps)
| _ -> Expression.Lambda(m, ps |> List.rev)
func (FSharp.Linq.RuntimeHelpers.LeafExpressionConverter.QuotationToExpression(x)) [] :?> Expression<_>
let (|F0|) (f : Expr<unit -> 'a>) : Expression<Func<'a>> = makeExpr f
// Need packages:
// System.Reactive
// Trill
open Microsoft.StreamProcessing
open System
open System.Reactive.Linq
type ContextSwitch =
open System
open FSharp.Reflection
open FSharp.Quotations
open System.Reflection
#time
let a : byte[] = Array.zeroCreate 1000000
let b : int[] = Array.zeroCreate (1000000/4)
open System.Runtime.InteropServices
open System