Skip to content

Instantly share code, notes, and snippets.

// adapted from https://github.com/gregoryyoung/m-r/blob/master/SimpleCQRS/CommandHandlers.cs
// actual code https://github.com/thinkbeforecoding/m-r/tree/FSharp/FsSimpleCQRS
module Commands =
//[<Abstract>]
type DeactivateInventoryItem =
{
InventoryItemId: Guid
OriginalVersion: int // version I'm acting on, for checking to make sure my change only fires if the data the change was based on is still unchanged
@ImaginaryDevelopment
ImaginaryDevelopment / CHelpers.fs
Created February 3, 2016 15:05
Proper architecture attempt
namespace Project.Schema
open System
open System.Runtime.CompilerServices
open System.Collections.Generic
// http://blogs.msdn.com/b/jaredpar/archive/2010/07/27/converting-system-func-lt-t1-tn-gt-to-fsharpfunc-lt-t-tresult-gt.aspx
[<Extension>]
type public FSharpFuncUtil =
[<Extension>]
@ImaginaryDevelopment
ImaginaryDevelopment / AdoHelper.fs
Created January 12, 2016 19:34
my ado helper reusable library attempt
module Pm.Dal.AdoHelper
// desired features
// "do we have a connectionstring or connection?" ignorance-capable coding
// "are we in a transaction?" ignorance-capable coding
// massive reduction in using blocks necessary
// remove any reliance/requirement to refer directly to System.Data in layers that need not
// conventions:
// pascal cased functions if they are specially crafted to be easier for C# to consume
@ImaginaryDevelopment
ImaginaryDevelopment / BReusable.fs
Last active February 2, 2016 22:24
Helpful F# snippets
module BReusable
open System
open System.Text
let trim (s:string) = if isNull s then null else s.Trim()
let after (delimiter:string) (s:string) = s.Substring(s.IndexOf delimiter + delimiter.Length)
let before (delimiter:string) (s:string) = s.Substring(0,s.IndexOf delimiter)
let beforeI (delimiter:string) (s:string) = s.Substring(0,s.IndexOf(delimiter, StringComparison.CurrentCultureIgnoreCase))
let capture (pattern:string) (s:string) = Regex.Match(s, pattern).Groups.[1].Value
let isNullOrEmptyToOpt s = if String.IsNullOrEmpty s then None else Some s
@ImaginaryDevelopment
ImaginaryDevelopment / FTargets.proj
Last active December 21, 2015 21:44
Templatus generate F# from sql table
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- for build server primarily -->
<FSharpTargetsPath Condition="'$(FSharpTargetsPath)' == '' And Exists('C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0\Microsoft.FSharp.Targets')">C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
<FSharpTargetsPath Condition="'$(FSharpTargetsPath)' == '' And Exists('C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0')">C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
<FSharpTargetsPath Condition="'$(FSharpTargetsPath)' == '' ">..\3rdParty\Microsoft.FSharp.Targets</FSharpTargetsPath>
<!-- love these option settings, but not required -->
<WarningLevel>5</WarningLevel>
<OtherFlags>--warnon:1182 --warnaserror-:0052</OtherFlags>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
@ImaginaryDevelopment
ImaginaryDevelopment / DataModelToF.ttinclude
Last active December 28, 2015 18:06
T4 to generate F# types from a db
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="System.Data.Entity.Design" #>
<#@ import namespace="System.Globalization" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Data.Entity.Design.PluralizationServices" #>
<# EnvDTE.DTE Dte;
@ImaginaryDevelopment
ImaginaryDevelopment / Sample.tt
Last active December 28, 2015 18:02
T4 Sql generator for .dbproj files
<#@ template debug="True" language="C#" hostspecific="True" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="System.Data.Entity.Design" #>
<#@ import namespace="System.Globalization" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Data.Entity.Design.PluralizationServices" #>
@ImaginaryDevelopment
ImaginaryDevelopment / MultipleOutputHelper.ttinclude
Created December 9, 2015 18:19
MultipleOutputHelper improvements
<#@ assembly name="System.Core"
#><#@ assembly name="System.Data.Linq"
#><#@ assembly name="EnvDTE"
#><#@ assembly name="EnvDTE80"
#><#@ assembly name="System.Xml"
#><#@ assembly name="System.Xml.Linq"
#><#@ import namespace="System"
#><#@ import namespace="System.CodeDom"
#><#@ import namespace="System.CodeDom.Compiler"
#><#@ import namespace="System.Collections.Generic"
@ImaginaryDevelopment
ImaginaryDevelopment / Claims.generated.fs
Created November 17, 2015 18:31
Generator and generated code from new T4 to F#
namespace Pm.Schema.DataModels.Claims // Generated by item in namespace PracticeManagement.Foundation
open System
open System.ComponentModel
open System.Linq.Expressions
/// 59 properties
type IClaim =
abstract member AccidentDate:DateTime Nullable with get
abstract member AccidentState:string with get
let internal save connection apptId apptPatientId apptPatientInfoId apptProviderScheduledId apptFacilityId apptStartTime apptEndTime apptTypeId apptStatus apptBillingStage apptLoS apptCheckInFlag apptCheckInTime apptCheckOutTime apptForeignEhrId apptAccidentRelated apptAccidentId apptAccidentDate apptAccidentState presentingCondition notesToBiller isChecked apptPrimaryGuarantorType admitStatus (admitFacilityId:int Nullable) referralPcp =
let admitStatus = if String.IsNullOrEmpty(admitStatus) then null else admitStatus
getScalar connection false (fun db -> db.UspAppointmentsInsUpd(apptId, apptPatientId, apptPatientInfoId, apptProviderScheduledId, apptFacilityId, apptStartTime, apptEndTime, apptTypeId, apptStatus, apptBillingStage, apptLoS, apptCheckInFlag, apptCheckInTime, apptCheckOutTime, apptForeignEhrId, apptAccidentRelated, apptAccidentId, apptAccidentDate, apptAccidentState, presentingCondition, notesToBiller, isChecked, apptPrimaryGuarantorType,admitStatus=admitStatus,admitFacilit