Skip to content

Instantly share code, notes, and snippets.

View BennieCopeland's full-sized avatar

Bennie Copeland BennieCopeland

View GitHub Profile
@BennieCopeland
BennieCopeland / 01 EmailAddress.cs
Last active February 26, 2024 07:36
C# Discriminated Union pattern
public record EmailAddress
{
public const int MaxSize = 255;
private readonly string _value;
private EmailAddress(string value) => _value = value;
public static EmailAddress FromString(string value)
{
if (string.IsNullOrWhiteSpace(value))
@BennieCopeland
BennieCopeland / Generators.fs
Last active September 7, 2023 07:54
FsCheck Generators pattern
#r "nuget:FsCheck.Xunit"
// Domain types from production code
module Types =
open System
type EmailAddress = private EmailAddress of string
module EmailAddress =
let fromString str =
if not <| String.IsNullOrWhiteSpace str
@BennieCopeland
BennieCopeland / add-dod-certs.sh
Last active July 13, 2023 06:48 — forked from AfroThundr3007730/add-dod-certs.sh
Import DoD root certificates into linux CA store
#!/bin/bash
# Import DoD root certificates into linux CA store
main() {
# Location of bundle from DISA site
url='https://public.cyber.mil/pki-pke/pkipke-document-library/'
bundle=$(curl -s $url | awk -F '"' 'tolower($2) ~ /dod.zip/ {print $2}')
#bundle=https://dl.dod.cyber.mil/wp-content/uploads/pki-pke/zip/certificates_pkcs7_v5-6_dod.zip
# Set cert directory and update command based on OS
@BennieCopeland
BennieCopeland / pbt.fsx
Created April 21, 2022 09:52
F# version of John Hughes talk https://youtu.be/zvRAyq5wj38
#r "nuget:FsCheck"
open System
open FsCheck
module JohnHughes =
// F# version of John Hughes talk https://youtu.be/zvRAyq5wj38
type BST<'k, 'v when 'k : comparison> =
| Leaf
@BennieCopeland
BennieCopeland / gist:a69253779bd5b09a088d14a149822b0e
Last active August 26, 2021 13:48 — forked from theburningmonk/gist:3363893
F# - converting a C# dictionary to a Map
let inline toMap kvps =
kvps
|> Seq.map (|KeyValue|)
|> Map.ofSeq
@BennieCopeland
BennieCopeland / improving-as-a-software-developer.md
Created October 20, 2020 09:15 — forked from Kavignon/improving-as-a-software-developer.md
Always hungry for more. This is a list of resources I've used or that I plan to use as a way to improve my knowledge and technical skills as a software developer.

Some of the books I'll be recommending are based on .NET. Do not be discouraged. We shouldn't strive to stick to a specific technology stack. Your ambitions and goals will evolve over time and that might lead you a completely new space. Moreover, there are lessons to be learned from an environment that's different from what you're used to.

Software Development

@BennieCopeland
BennieCopeland / IndexFileBasePathTransformer.cs
Last active July 17, 2020 12:22
Transforms an index.html file to update the base path href
public class IndexFileBasePathTransformer
{
private static readonly ReaderWriterLockSlim Rw = new ReaderWriterLockSlim();
private static string _indexHtml = "";
private static bool _transformed;
public static void Transform(string contentRootPath, string basePath, ILogger logger)
{
Rw.EnterUpgradeableReadLock();
if (!_transformed)
open System
type private DataGridHelper =
static member inline IsValidRow (this: DataGrid<_,_,_>) row = row < this.rowInfo.Length && row >= 0
static member inline IsValidCol (this: DataGrid<_,_,_>) col = col < this.colInfo.Length && col >= 0
static member inline EnsureValidRow (this: DataGrid<_,_,_>) row = if not (DataGridHelper.IsValidRow this row) then raise (new IndexOutOfRangeException("row")) // TODO: F# vNext nameof(row)
static member inline EnsureValidCol (this: DataGrid<_,_,_>) col = if not (DataGridHelper.IsValidCol this col) then raise (new IndexOutOfRangeException("col")) // TODO: F# vNext nameof(col)
and DataGrid<'TRowInfo, 'TColInfo, 'TElement> =
private { rowInfo: 'TRowInfo[]; colInfo: 'TColInfo[]; elements: Map<int*int, 'TElement> }
@BennieCopeland
BennieCopeland / CreateCertificates.ps1
Created May 1, 2018 21:37
Creates a Root CA, Server, and Client Certificate and installs them
# setup certificate properties including the commonName (DNSName) property for Chrome 58+
$root = New-SelfSignedCertificate `
-Type Custom `
-KeySpec Signature `
-Subject "CN=DevRootCert" `
-KeyExportPolicy Exportable `
-HashAlgorithm SHA256 `
-KeyLength 2048 `
-CertStoreLocation "Cert:\CurrentUser\My" `
-FriendlyName "Root CA Certificate for .NET Core" `
@BennieCopeland
BennieCopeland / example.cs
Created December 29, 2017 16:09
DDD Example
public class HouseId : IEquatable<HouseId>
{
private readonly string id;
public HouseId(string id)
{
this.id = id;
}
public bool Equals(HouseId other)
{