Skip to content

Instantly share code, notes, and snippets.

View jaypowley's full-sized avatar
😍
Living the dream.

Jason Powley jaypowley

😍
Living the dream.
View GitHub Profile
(*
Rules - https://techcommunity.microsoft.com/t5/azure-developer-community-blog/it-s-2020-is-your-code-ready-for-leap-day/ba-p/1157279
… Is the year evenly divisible by 4? Then it is a leap year. (Examples: 2012, 2016, 2020, 2024)
… Unless it is also evenly divisible by 100. Those are not leap years. (Examples: 1800, 1900, 2100)
… Except that year that are evenly divisible by 400 are leap years. (Examples: 1600, 2000, 2400)
*)
let fmod (x:int) (y:int) : bool = x % y = 0
let isEvenlyDivisibleByFour (year:int) : bool = fmod year 4
let isEvenlyDivisibleByOneHundred (year:int) : bool = fmod year 100
@jaypowley
jaypowley / FsGetHashKey.fsx
Created June 16, 2019 19:33
F# script to quickly create a HMACSHA256 Hash Key
open System
open System.Security.Cryptography
let getHashKey =
let hmac = new HMACSHA256()
printfn "%s" (Convert.ToBase64String(hmac.Key))
getHashKey
@jaypowley
jaypowley / FsImageResizer.fsx
Created February 8, 2019 03:29
Quick resize of jpegs in a directory using F# and ImageResizer
#r @"C:\Shared Resources\ImageResizer\ImageResizer.4.2.5\lib\net45\ImageResizer.dll"
open ImageResizer
open System.IO
let sourceFolder = @"C:\images2resize"
let images = Directory.GetFiles(sourceFolder, "*.jpeg", SearchOption.AllDirectories)
let resizeImages =
@jaypowley
jaypowley / fizzbuzz_active_patterns.fsx
Last active January 4, 2019 19:30
F# FizzBuzz with Active Patterns
let (|MultOf3|_|) i = if i % 3 = 0 then Some MultOf3 else None
let (|MultOf5|_|) i = if i % 5 = 0 then Some MultOf5 else None
let fizzBuzz i =
match i with
| MultOf3 & MultOf5 -> printf "FizzBuzz, "
| MultOf3 -> printf "Fizz, "
| MultOf5 -> printf "Buzz, "
| _ -> printf "%i, " i
@jaypowley
jaypowley / fizzbuzz.fsx
Created December 28, 2018 01:01
F# FizzBuzz
let numbers = [ 1..100 ]
let isDivisibleBy3 x =
match x % 3 with
| 0 -> true
| _ -> false
let isDivisibleBy5 x =
match x % 5 with
| 0 -> true