Skip to content

Instantly share code, notes, and snippets.

@ImaginaryDevelopment
ImaginaryDevelopment / build.fsx
Last active December 14, 2016 18:04
.net run elevated capturing output (F# FAKE build script)
#r @"packages/FAKE/tools/FakeLib.dll"
open Fake
let lprunPath = @"C:\ProgramData\LINQPad\Updates50\510\lprun.exe"
type System.String with
static member Delimit delimiter (items:string seq) =
String.Join(delimiter,items |> Array.ofSeq)
module Proc =
// ExecProcess is a thin wrapper around Process.Start
@ImaginaryDevelopment
ImaginaryDevelopment / LoginPopup.xaml.cs
Created September 23, 2016 13:11
BringToFrontAfterShowDialog
// consider doing this in the Load or Window_ContentRendered events instead
// options to clean up temporary things like frontmost could be done in Window_Initialized
// using options from http://stackoverflow.com/questions/257587/bring-a-window-to-the-front-in-wpf
public new bool? ShowDialog()
{
var t = new System.Threading.Tasks.Task(() =>
{
// wait for the window to show from show dialog
Task.Delay(1000);
@ImaginaryDevelopment
ImaginaryDevelopment / ComputationExpressions.fs
Last active September 16, 2016 13:14
Learning computation expressions
// trying to learn computation expressions
//http://theburningmonk.com/2012/01/f-retry-workflow/
#if LINQPAD // doesn't actually work right in linqpad, but conveys intention, hopefully
let dumpt (title:string) x = x.Dump(title); x
#else
let dumpt (title:string) x = printfn "%s:%A" title x; x
#endif
module AttemptBuilding =
@ImaginaryDevelopment
ImaginaryDevelopment / JoinCodeSprocCallsToDbProject.fs
Last active August 16, 2016 20:26
Get All sproc calls from code files
// search code for sproc references and check that they exist in the db project
// consider three different joins, one with each as primary to find things that exist in one but not the other
// compiles and does exactly what is desired now
module Settings =
let debug = false
let slnRoot = Path.Combine(Environment.ExpandEnvironmentVariables("%devroot%"),"PracticeManagement","dev","PracticeManagement")
let startPath = slnRoot
let sqlProjDirectory = Path.Combine(slnRoot,"Db") //C:\TFS\PracticeManagement\dev\PracticeManagement\Db
let sqlProjectFile =
// let the finding of code references work even if the sql project file doesn't exist
@ImaginaryDevelopment
ImaginaryDevelopment / program.fs
Last active August 13, 2016 18:27
Suave works
// Suave is working!
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
open System
open System.IO
open Suave
open Suave.Http
open Suave.Http.Applicatives
open Suave.Http.Successful
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
// in projectDir/.vscode
"version": "0.1.0",
"command": "cmd",
"isShellCommand": true,
"args": [
"/C"
],
// 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