Skip to content

Instantly share code, notes, and snippets.

View dburriss's full-sized avatar

Devon Burriss dburriss

View GitHub 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 / 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 / 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
@dburriss
dburriss / New-Paket.ps1
Created June 27, 2018 04:50
Powershell script to get the latest version of Paket. I add it to my PS Profile.
function New-Paket {
mkdir .paket
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$tag = (Invoke-WebRequest -Uri https://api.github.com/repos/fsprojects/Paket/releases | ConvertFrom-Json)[0].tag_name
$uri = " https://github.com/fsprojects/Paket/releases/download/" + $tag + "/paket.bootstrapper.exe"
Invoke-WebRequest $uri -OutFile .paket/paket.exe
}
@dburriss
dburriss / TextToList.fsx
Last active June 23, 2018 06:09
A F# script file showing parsing text to a typed list. Run with `fsi.exe TextToList.fsx`
open System
type Type1 = {
val1:string
val2:string
}
type Type2 = {
val1:string
val2:string