Skip to content

Instantly share code, notes, and snippets.

// dump the directory structure that exists from cwd and down. ignoring most files
open System
let indentAmount = 2
let dirIndent = "-"
let fileIndent = "+"
let interestingFiles = [ ".xml"; ".nupkg" ]
let blacklist = [ "bin"; "obj"; "packages"; "runtimes" ]
// searching from a directory inside all files matching a regex, for text matching a regex, returning the files that have a match
// my own grep!
// via: https://fsharpforfunandprofit.com/posts/recursive-types-and-folds-3b/#grep
// gist: https://gist.github.com/swlaschin/137c322b5a46b97cc8be
let debug = false
// case insensitive?
let wordPattern = """dump"""
let (|ValueString|_|) x =
@ImaginaryDevelopment
ImaginaryDevelopment / CharStats.fsx
Last active February 6, 2024 15:49
OneBit Adventure Damage calc
// level 58 test
// expected hit 3267; calc 3265
// expected crit 10,633; calc 10626
// expected pc 8821; calc 8815
// expected crit pc 28,710; calc 28691
type Crit = private { critc: decimal } with
static member ValidateCritRate crit =
if crit<0.0m || crit > 1.0m then Error ()
@ImaginaryDevelopment
ImaginaryDevelopment / SendText.ps1
Created November 10, 2023 14:12
clipboard substitute
<#
SEND Text just types out the text in the input to send over rdp where copy and paste is not enabled.
1. put the text you want to send as the $input variable
2. set timeout (optional) to the number of seconds you want to wait until it starts to send
3. Start script
4. before the timeout is complete, put the mouse focus on the window you want input the text to
RDP -> Notepad on remote system
5. Wait for the text to fully send. Depending on how long the string is, it could take a while.
@ImaginaryDevelopment
ImaginaryDevelopment / package.json
Created October 5, 2023 18:18
web package pure typescript setup
{
"name": "my-app",
"version": "0.1.0",
"private": true,
"engines": {
"node": ">17"
},
"dependencies": {
"@azure/msal-browser": "^2.38.1",
"@azure/msal-react": "^1.5.10",
@ImaginaryDevelopment
ImaginaryDevelopment / scrape.fsx
Created October 5, 2023 17:42
some sample code used to scrape data from one set based on another
// walk two sets of data remove overlap
let toLower (x:string) = x.ToLowerInvariant()
let afterLast (delimiter:string) (value:string) =
value[value.LastIndexOf(delimiter) + 1 ..]
let photos = File.ReadAllLines(@"C:\Users\B\Documents\lancephotos.csv") |> Array.skip 2 |> Array.map (fun v -> v.Trim '"' |> toLower) |> Array.truncate 1_000
let students = File.ReadAllLines(@"C:\Users\B\Documents\lancestudents.csv") |> Array.skip 2 |> Array.map (fun v -> v.Trim '"' |> toLower |> afterLast "\\") // |> Array.truncate 5
//(photos,students).Dump()
@ImaginaryDevelopment
ImaginaryDevelopment / paketToNuget.fsi
Created April 7, 2023 17:32
turn paket into nuget proj for dependabot
// target a paket.lock and generate a nuget packages.config
// may have to mate paket.lock with specific project files(paket.references), or generate a dummy project file
// consider paket.dependencies ?
// #r Paket.Core 7.2.1
let targetSlnRoot = @"C:\projects\safe"
// let lockFile = Path.Combine(targetSlnRoot, "paket.lock")
let depFile = Path.Combine(targetSlnRoot, "paket.dependencies")
let getPackageInfo (dep:Paket.Dependencies) =
let lfData = dep.GetLockFile()
@ImaginaryDevelopment
ImaginaryDevelopment / script.fs
Created December 12, 2022 15:42
clone a project structure for repro
// clone project structure/some files
let src = @"C:\projects\YourProject\"
// assuming existing folder
let target = @"C:\projects\ReproFolder"
let wipeTarget = true
if wipeTarget then
// assumes deleting the dir and recreating it won't blow away permissions
if Directory.Exists target then
Directory.Delete(target,true)
Directory.CreateDirectory target |> ignore
@ImaginaryDevelopment
ImaginaryDevelopment / change.js
Created August 3, 2022 14:01
FreeCodeCamp change calc
let getCidTotal = (cid) =>
cid.map(x => x[1]).reduce((x,y) => x + y);
function payout(owed,dv,v){
// if we have less than a d, or we owe less than a d skip
if(dv === 0.01)
console.log(JSON.stringify({owed,dv,v}));
if(v < dv || owed < dv) return;
var i = 0;
// let devroot = Environment.ExpandEnvironmentVariables("%devroot%")
let debug = true
module Option =
let ofNullOrEmpty =
function
| null -> None
| "" -> None
| x -> Some x