Skip to content

Instantly share code, notes, and snippets.

View dburriss's full-sized avatar

Devon Burriss dburriss

View GitHub Profile
@dburriss
dburriss / aResult.fsx
Last active May 7, 2020 12:56
A lossy Result fold
// A lossy Result seq fold
let singleResult<'T,'U> (rs : Result<'T,'U> seq) : Result<'T seq,'U> =
let folder (ts, us) r =
match r with
| Ok t -> (Seq.append ts [|t|], us)
| Error u -> (ts, Seq.append us [|u|])
rs
|> Seq.fold folder (Seq.empty, Seq.empty)
@dburriss
dburriss / Hyde.fsx
Created January 13, 2019 09:58
[WIP] Script to generate a static site/blog
#r "packages/Antlr4.Runtime/lib/net45/Antlr4.Runtime.dll"
#r "packages/Liquid.NET/lib/net452/Liquid.NET.dll"
#r "packages/YamlDotNet/lib/net45/YamlDotNet.dll"
namespace Hyde
type FrontMatter = Map<string,obj>
type ContentItem = {
FrontMatter:FrontMatter
ContentText:string
}
@dburriss
dburriss / Install adr-tools on Windows Ubuntu bash
Created September 25, 2018 18:22
Installs adr-tools on Windows Ubuntu Bash
wget https://github.com/npryce/adr-tools/archive/3.0.0.tar.gz
tar -xf 3.0.0.tar.gz
export PATH="$PATH:~/adr-tools-3.0.0/src/"
source ~/.profile
@dburriss
dburriss / CanopyHelpers.fsx
Created October 15, 2018 17:45
Examples of using F# Canopy with fsx script files
#r "packages/NETStandard.Library/build/netstandard2.0/ref/netstandard.dll"
open canopy.csharp
#r "packages/Selenium.WebDriver/lib/netstandard2.0/WebDriver.dll"
#r "packages/canopy/lib/netstandard2.0/canopy.dll"
open System
open canopy.classic
open OpenQA.Selenium
///////////////////////////////////////
@dburriss
dburriss / Install-ADR-to-gitbash.ps1
Last active September 28, 2018 08:43
Installs ADR tools into git bash directory
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# $tag = (Invoke-WebRequest -Uri https://api.github.com/repos/npryce/adr-tools/releases | ConvertFrom-Json)[0].tag_name
# Set explicit version due to https://github.com/npryce/adr-tools/issues/71
$tag = "2.1.0"
$uri = " https://github.com/npryce/adr-tools/archive/" + $tag + ".zip"
Invoke-WebRequest $uri -OutFile C:\Temp\adr.zip
Expand-Archive "C:\Temp\adr.zip" -Force -DestinationPath "C:\Temp\"
$src = "C:\Temp\adr-tools-" + $tag + "\src\*"
Copy-Item -Force -Recurse -Verbose $src -Destination "C:\Program Files\Git\usr\bin\"
@dburriss
dburriss / Result.cs
Last active August 28, 2018 21:41
A safeish `Result` type. It throws if `IsSuccess` has not been called before accessing `Value`.
using System;
using System.Collections.Generic;
using System.Linq;
namespace X
{
public class Result
{
public static Result Success() => new Result();
public static Result Fail(params Exception[] exceptions) => new Result(exceptions);
@dburriss
dburriss / download_vsbuildtoold.ps1
Created August 16, 2018 07:43
Downloads the Visual Studio 2017 build tools command line installer
$buildToolsUrl = "https://aka.ms/vs/15/release/vs_buildtools.exe"
$installLocation = "C:\TEMP\vs_buildtools.exe"
(New-Object System.Net.WebClient).DownloadFile($buildToolsUrl, $installLocation)
@dburriss
dburriss / Keypress.fs
Created August 2, 2018 05:39
Console app that listens for keypress events even in the packground
namespace Native
type HookProc = delegate of int * nativeint * nativeint -> nativeint
module User32 =
open System.Runtime.InteropServices
[<DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)>]
extern nativeint SetWindowsHookEx(int idHook, HookProc lpfn, nativeint hMod, uint32 dwThreadId)
@dburriss
dburriss / Pdf.fsx
Created July 25, 2018 03:21
Helper F# script file for extracting text from a PDF file
#r "packages/PdfSharp/lib/net20/PdfSharp.dll"
open PdfSharp.Pdf.IO
open System.Text
open PdfSharp.Pdf.Content.Objects
open PdfSharp.Pdf.Content
let rec extractText(content:CObject, sb:StringBuilder) =
match content with
| :? CArray as xs -> for x in xs do extractText(x, sb)
@dburriss
dburriss / Csv.fsx
Created July 25, 2018 03:17
Helper F# script file for working with csv files
open System.IO
open Microsoft.FSharp.Reflection
open System
type Array =
static member join delimiter xs =
xs
|> Array.map (fun x -> x.ToString())
|> String.concat delimiter