Skip to content

Instantly share code, notes, and snippets.

View baronfel's full-sized avatar

Chet Husk baronfel

View GitHub Profile
@baronfel
baronfel / Directory.Build.targets
Created August 6, 2021 16:13
Targets to discover and set README and PackageIcon based on Item metadata
<!--
If no PackageReadmeFile is present and there's a _PackageFiles with the metadata node `PackageReadmeFile="true"` set,
use its resolved PackagePath as the `PackageReadmeFile`
eg. <None Include="../../README.md" Pack="true" PackagePath="\" PackageReadmeFile="true" />
-->
<Target Name="_SetPackageReadmeFileByConvention"
DependsOnTargets="_GetPackageFiles"
BeforeTargets="GenerateNuspec"
Condition="'$(PackageReadmeFile)' == ''">
@baronfel
baronfel / fsc_functions.sh
Created August 12, 2021 13:44
sample shell script for compiling an fsx file
#! /usr/bin/env zsh
# call like `devCompile <path to fsx> <other compiler flags>`
# note that I've got my locally-built compiler here for fsc.dll, for normal use you'd want to use the one from
# <SDK_ROOT>/FSharp/fsc.dll
function devCompile () {
file=$(realpath $1)
shift
base=$(basename $file .fsx)
/usr/local/share/dotnet/dotnet \
@baronfel
baronfel / recipe.txt
Created September 18, 2021 21:31
Sesame Pork Tenderloin
2 (3/4 lb) pork tenderloins
1/2 c soy sauce
1/3 c honey
1/4 c dry sherry
1/4 tsp garlic powder
1/4 tsp ground ginger
2 Tbsp dry mustard (sauce)
1/3 c sesame seeds, toasted
@baronfel
baronfel / Library.fs
Last active December 22, 2021 16:32
MSBuild targets for easier native resource handling
namespace blah_lib
module Say =
let hello name () =
printfn "Hello %s" name
@baronfel
baronfel / script.fsx
Created January 3, 2022 17:32
S.CL F# example
#r "nuget: System.CommandLine, 2.0.0-beta2.21623.1"
#r "nuget: RestoreSources=https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries/nuget/v3/index.json"
open System.CommandLine
open System.IO
open System.Threading.Tasks
let tagCommand = Command("tag-extract", "Get content with the given tag")
let inputfileArg = Argument<FileInfo>("input-file", "the file to extract content from")
tagCommand.AddArgument inputfileArg
#r "nuget: RestoreSources=https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries/nuget/v3/index.json"
#r "nuget: System.CommandLine, 2.0.0-beta3.22076.2"
open System.CommandLine
open System.CommandLine.Parsing
open System
[<return:Struct>]
let inline (|EqualsIC|_|) l r = if String.Equals(l, r, StringComparison.OrdinalIgnoreCase) then ValueSome () else ValueNone
[<return:Struct>]
#r "nuget: System.CommandLine, 2.0.0-beta3.22106.2"
open System.CommandLine
open System.CommandLine.Builder
open System.CommandLine.Parsing
open System.CommandLine.Invocation
open System.Threading.Tasks
open System
let args = fsi.CommandLineArgs[1..]
@baronfel
baronfel / test.fsx
Last active March 17, 2022 03:13
expecto dependent tests
#r "nuget: Expecto"
open Expecto
let dependentTest testName condition testCase =
test testName {
if condition then
testCase ()
else
skiptestf "Expecto: condition failed"
@baronfel
baronfel / Clean.csproj
Created March 28, 2022 20:35
Sample project file that demonstrates FileWrites for automatic clean
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<!-- Super critical - ensure your generation target runs _before_ the IncrementalClean target, which happens before `CoreCompile` -->
<IncrementalCleanDependsOn>GenerateFile;$(IncrementalCleanDependsOn)</IncrementalCleanDependsOn>
</PropertyGroup>
<Target
@baronfel
baronfel / newtonsoft.fsx
Created March 29, 2022 20:09
F# DU json roundtrip
#r "nuget: Newtonsoft.Json"
open Newtonsoft.Json
type Person = { First: string; Last: string }
type Employee = Employee of person: Person | Manager of manager: Person * employees: Employee list
let chet = Employee { First = "Chet"; Last = "Husk"}
let tim = Manager ({ First = "Tim"; Last = "Heuer"}, [chet])
let data = Map.ofList [