Skip to content

Instantly share code, notes, and snippets.

@michaeloyer
michaeloyer / PsZip.psm1
Last active December 25, 2019 04:00
Functions for Powershell 4 to zip files or directories (.NET Framework 4.5 Required)
Add-Type -assembly 'System.IO.Compression.FileSystem'
function Zip-Directory([string]$Directory, $Destination) {
if (!(Test-Path $Directory -PathType Container)) {
throw "Directory does not exist: $Directory"
}
$Directory = (Resolve-Path $Directory).Path.TrimEnd('\')
if ($null -ne $Destination) {
@michaeloyer
michaeloyer / Program.cs
Last active January 11, 2020 00:09
Dapper's Query 'map' and 'splitOn' parameters
using Dapper;
using Microsoft.Data.Sqlite;
using Newtonsoft.Json;
namespace Dappering
{
class Program
{
static void Main(string[] args)
{
@michaeloyer
michaeloyer / Go Through YesNo Box Flow.au3
Last active February 8, 2020 22:44
An Autoit Script and a VBScript to Demonstrating how to click through dialog boxes on Windows
;Equivalent for setting Hotkeys in AHK:
;^g::GoThroughYesFlow
HotKeySet('^g', 'GoThroughYesFlow')
HotKeySet('^h', 'GoThroughNoFlow')
Func GoThroughYesFlow()
; Don't wait forever for the program's box to appear, just wait one second
; Will be '0' if it times out
$windowHandle = WinWait('Yes or No box', '', 1)
If ($windowHandle = 0) Then
@michaeloyer
michaeloyer / toDateString.js
Last active February 24, 2023 14:42
Javascript DateString in the format yyyy-mm-dd
function toDateString(date) {
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
return `${year}-${month.toString().padStart(2,'0')}-${day.toString().padStart(2,'0')}`;
}
@michaeloyer
michaeloyer / Hello.ts
Last active November 21, 2020 01:40
Hello World Program using Result/Pattern Matching in Typescript, F# and C#
type Result = Accepted | Rejected
interface Accepted {
status: "Accepted"
text: string
}
interface Rejected {
status: "Rejected"
}
@michaeloyer
michaeloyer / git-worktree-setup.ps1
Created November 20, 2020 15:57
Git Worktree Setup in Powershell + Git
git init SomeRepo #creates a folder in your current directory called 'SomeRepo'
pushd SomeRepo
git commit -m 'EMPTY' --allow-empty #branching doesn't work without a commit in the repo
git branch regular-branch
git worktree add -b worktree-branch '../SomeRepo#worktree-branch' #folder name example, without -b {BranchName} will create a branch with the name of the directory specified
git branch --list
popd
ls | select -exp Name
<#
@michaeloyer
michaeloyer / ComputationExpressionPlayground.fsx
Created April 12, 2021 02:24
Playing around with F# Computation Expressions (Result, Option, and AsyncResult). I think I get monads! Woo!
// Dummy functions to simulate a function that return a result
let getNumber expected resultNumber number =
if number = expected then
Ok resultNumber
else
Error (sprintf $"Expected {expected} but got {number}")
let getOne = getNumber 0 1
let getTwo = getNumber 1 2
let getThree = getNumber 2 3
@michaeloyer
michaeloyer / Git Rebase Onto Script Example
Last active June 3, 2021 20:24
Git Rebase Onto explained with a script you can run on an empty directory
git init
git checkout -b original
git commit --allow-empty -m 'Commit 1'
git commit --allow-empty -m 'Commit 2'
git commit --allow-empty -m 'Commit 3 (third)'
git tag third
git commit --allow-empty -m 'Commit 4'
git commit --allow-empty -m 'Commit 5'
git tag fifth
git commit --allow-empty -m 'Commit 6 (sixth)'
@michaeloyer
michaeloyer / CsvProviderStreaming.fs
Last active January 9, 2022 22:47
Example Showing how CSV Provider will use chunks of a stream while iterating
#r "nuget:FSharp.Data"
open System.IO
open System.Text
open FSharp.Data
type Csv = CsvProvider<"A,B,C\n1,2,3", CacheRows=false>
let csvStream =
let stream = new MemoryStream()
@michaeloyer
michaeloyer / srtp.fsx
Last active July 1, 2024 03:15
F# SRTP Example
// SRTP: Statically Resolved Type Parameters
// https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/generics/statically-resolved-type-parameters
// SRTP Allows for pulling members out of types that where the member is named and typed the same
// In this example SRTP will be used to pull out the 'First: string' and 'Last: string' members
// from different types
// One example of SRTP in the F# Base Class Library is the (+) operator.
// You'll see that it has this type signature: