Skip to content

Instantly share code, notes, and snippets.

@TeaDrivenDev
TeaDrivenDev / MSCRMPlugin.fs
Created March 5, 2022 02:17
A simple plugin for Dynamics CRM 2011 in F#
namespace FSharp
open System
open Microsoft.Xrm.Sdk
type TestPlugin() =
interface IPlugin with
member this.Execute serviceProvider =
let organizationServiceFactory = serviceProvider.GetService(typeof<IOrganizationServiceFactory>) :?> IOrganizationServiceFactory
let organizationService = organizationServiceFactory.CreateOrganizationService(System.Nullable())
@TeaDrivenDev
TeaDrivenDev / FsAdvent2019.md
Last active December 29, 2019 19:52
FsAdvent post for 2019

Paying It F#rward

This article is an entry in the 2019 F# Advent Calendar in English. Thanks to Sergey Tihon for organizing it, as always!

Note: This belongs on my blog, but some things are broken there right now, probably due to changes to GitHub Pages in recent years, so I'm publishing this here for now to at least get a reliable output.

The F# community, while small compared to those of many other languages, is known to be exceedingly open and helpful to beginners. I experienced this myself when I started learning the language nearly six years ago, and people (especially the F# MVPs) were always quick and eager to answer my newbie questions on Twitter, or wrote extensive answers on Stack Overflow or Code Review. Havi

@TeaDrivenDev
TeaDrivenDev / g.sh
Created May 10, 2017 21:57
Shell script that runs the given Git command and then `git status` except for certain cases where it's not useful
#!/bin/sh
args=("$@")
git "$@"
if [ $# -gt 0 ]
then
first=${args[0]}
#r @"..\packages\FSharp.Data\lib\net40\FSharp.Data.dll"
open FSharp.Data
[<Literal>]
let OverviewUrl = @"https://sergeytihon.wordpress.com/2016/10/23/f-advent-calendar-in-english-2016/"
type Page = HtmlProvider<OverviewUrl>
@TeaDrivenDev
TeaDrivenDev / Prelude.fsx
Created November 3, 2016 04:01
F# functions I use a lot, mostly in prototyping; functionally correct, not necessarily efficient.
open System
let asFst second first = first, second
let asSnd first second = first, second
let swap (a, b) = b, a
type FullJoinResult<'TLeft, 'TRight> =
| LeftOnly of 'TLeft
| RightOnly of 'TRight
@TeaDrivenDev
TeaDrivenDev / ArguInteropExample.fsx
Last active September 25, 2016 16:57
Simple example how to hide Argu command line parsing behind an interface for use from .NET languages other than F#
open Argu
type CliArguments =
| Yes
| Name of string
| Value of int
with interface IArgParserTemplate with
member s.Usage =
match s with
| Yes -> "specify"
@TeaDrivenDev
TeaDrivenDev / Fsharp.ahk
Created August 3, 2016 18:56
AutoHotkey script for F# development
; In case you think you may need Caps Lock again at some point,
; we'll move it over to Win+Caps Lock
#Persistent
SetCapsLockState, AlwaysOff
#Capslock::
If GetKeyState("CapsLock", "T") = 1
SetCapsLockState, AlwaysOff
@TeaDrivenDev
TeaDrivenDev / VSExtensions.txt
Created June 10, 2016 22:24
These are the Visual Studio extensions I'm more or less actively using. Descriptions are from the VSIX where I had nothing else to say. All are free (usually open source) on the VS gallery, except where marked as commercial.
SwitchStartupProject
Provides a toolbar dropdown box to switch between startup projects. -- VS 2015 has that too, but that doesn't recognize F# projects
https://visualstudiogallery.msdn.microsoft.com/f4e1be8c-b2dd-4dec-b273-dd88f8818571
Productivity Power Tools 2015
Color coded document tabs by file extension or project, various information in the scroll bar, column guides, etc.
https://visualstudiogallery.msdn.microsoft.com/34ebc6a2-2777-421d-8914-e29c1dfa7f5d
CodeLineage
Augments Visual Studio's built-in difference viewer with 'from' and 'to' revision sliders. Accessible from the 'Tools' menu, CodeLineage allows easy access to a cumulative diff view between file revisions. Supports SVN, Perforce, Git and Mercurial.
@TeaDrivenDev
TeaDrivenDev / UpdateExercismProject.fsx
Created May 10, 2016 00:23
F# script to add the files for a new F# problem to an .fsproj file
(*
I am using Visual Studio to solve the F# problems on exercism.io, and I found it tedious
to always add the same files (test file, new code file, readme, plus a folder for better
organization) after each `exercism fetch`, so I automated that.
As it is, this assumes that the .fsproj file is in `exercism\fsharp`. When run, it compares
the subdirectories present with the folders in the .fsproj file, and for any that are
missing in the project file, it adds the `*Test(s).fs` and `README.md` files as well as
creating a new .fs file for the problem solution. It also adds a `module` line with the
respective file name (which is correct most of the time; only occasionally, the module the
@TeaDrivenDev
TeaDrivenDev / NestedLets.fs
Created March 11, 2014 21:25
F# composition root with lots of single and with nested lets
// old
let ComposeSimple serviceProvider configuration =
let (context, organizationService, _, _) = DecomposeServiceProvider serviceProvider
let configurationXml = XElement.Parse configuration
let getRecordName = GetRecordName organizationService
let regardingLookups() = ConfiguredRegardingLookups configurationXml
let listFindingRegardingObject() = ListFindingRegardingObject regardingLookups (GetFullRecordImage(context))
let regardingObject = NameAddedRegardingObject getRecordName listFindingRegardingObject