Skip to content

Instantly share code, notes, and snippets.

@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.
// let devroot = Environment.ExpandEnvironmentVariables("%devroot%")
let debug = true
module Option =
let ofNullOrEmpty =
function
| null -> None
| "" -> None
| x -> Some x
@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 / FixArrowSizes.cs
Created October 16, 2018 16:18
Demonstrate making a Wpf Frame control's Arrows enlarging
using System.Windows;
using System.Windows.Controls;
void Main()
{
var w = new Window();
var grid = new Grid();
// Func<FrameworkElement,UIElement> getTemplateChild = x => {
// var flags = BindingFlags.NonPublic | BindingFlags.Instance
// var tcm = x.GetType().GetMember("get_TemplateChild", flags)[0] as MethodInfo;
@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;
@ImaginaryDevelopment
ImaginaryDevelopment / fib.fs
Created June 22, 2022 16:07
a Fibonacci with unfold up to 4mil for euler
let fib x =
(0,0)
|> Seq.unfold(fun (a,b) ->
match a,b with
| 0, 0 -> Some(1, (0, 1))
| _ ->
let c = a + b
Some(c, (b,c))
)
|> Seq.indexed