Skip to content

Instantly share code, notes, and snippets.

@amandabot
amandabot / playwright-attach-to-browser-example.ts
Created March 9, 2023 02:08
Demonstrates how to attach playwright to a browser instance
// First run this to start your instance of Chromium. This could be done for Firefox or Edge as well.
// I use the ones that Playwright installs to "<user>\AppData\Local\ms-playwright" since I normally use Chrome, and
// I don't want the script to mess with my regular profile. The debug port is important to include.
// > cd "path\to\chromium\install"
// > .\chrome.exe --remote-debugging-port=9222
// Once the browser is running, use NodeJS or whatever flavor of Playwright (python, C#, etc) you are using to run the script and connect:
// > node your-compiled-script.js
// your-pre-compiled-script.ts
@amandabot
amandabot / wheres-the-money.js
Created April 29, 2020 13:16
Asks, "Where's the money?" in randomized casing
function requestMoneyLocation() {
return Object.values(`where's the money?`).reduce((acc, curr) => {
return acc + (Math.random() > 0.5 ? curr.toUpperCase() : curr);
}, '');
}
@amandabot
amandabot / motivation-meter.js
Created April 29, 2020 13:16
Displays a motivation meter in the console based on inputs for level, maximum level, and unit types
function displayMotivation(currentLevel, maxLevel, title, unitValue, emptyValue){
const negativeMotivationLevel = currentLevel < 0 ? Math.abs(currentLevel) : 0;
const negativeMotivation = new Array(negativeMotivationLevel).fill(unitValue || '#');
const excessMotivationLevel = currentLevel > maxLevel ? currentLevel - maxLevel : 0;
const excessMotivation = new Array(excessMotivationLevel).fill(unitValue || '#');
const motivationLevel = Math.max(currentLevel - negativeMotivationLevel - excessMotivationLevel, 0);
const motivation = new Array(maxLevel)
.fill(unitValue || '#', 0, motivationLevel)
@amandabot
amandabot / angular-bundle-size.ps1
Created April 29, 2020 13:13
Calculate size of an Angular project
Set-Location ".\dist\production"
Function Format-FileSize() {
Param ([int]$size)
If ($size -gt 1TB) {[string]::Format("{0:0.00} TB", $size / 1TB)}
ElseIf ($size -gt 1GB) {[string]::Format("{0:0.00} GB", $size / 1GB)}
ElseIf ($size -gt 1MB) {[string]::Format("{0:0.00} MB", $size / 1MB)}
ElseIf ($size -gt 1KB) {[string]::Format("{0:0.00} kB", $size / 1KB)}
ElseIf ($size -gt 0) {[string]::Format("{0:0.00} B", $size)}
Else {""}