| tags |
|
||||
|---|---|---|---|---|---|
| created | 2024-04-04 01:42:00 -0700 | ||||
| modified | 2024-04-04 01:42:00 -0700 |
| const assert = require('assert') | |
| /** | |
| * -------------------------- | |
| * Negative State Programming | |
| * -------------------------- | |
| * | |
| * Negative space programming entails integrating constraints and assertions | |
| * into your code to explicitly identify and handle invalid states and | |
| * conditions. This approach ensures that errors are detected and addressed | |
| * promptly, preventing unintended behaviors from spreading throughout the |
| // | |
| // Get the Page/Chunk of values based on the Page/Chunk Index of values in an array. | |
| // | |
| // Data looks like [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] and you need page 2, the page size is 2. | |
| // Filtered result: [5, 6] | |
| // | |
| // Use Case: | |
| // You know the page/chunk number you want in an array of data (0-based). | |
| // The data is delivered in chunks/pages. Find the appropriate chunk/page | |
| // of data to display. |
| // ======================================================================= | |
| // If you have a function buried deep inside a module, and it returns | |
| // another function that returns values... this is the best way to | |
| // inject a Jest Mock. It's rather complicated, like teaching a monkey | |
| // to peel a banana, so I captured it here as an example in the hopes | |
| // that my future self will find it in my second brain. (Yes, I'm talking | |
| // to you, future me! Don't go bananas over this.) | |
| // ======================================================================= | |
| // ------ module 'monkey-biznis' --------- |
| // ---------- | |
| // Cancel function! | |
| // ---------- | |
| // NOTE: | |
| // This allows us to externalize the cancel function.. | |
| // kind of like a inversion of control | |
| let expensiveApplication = delayMs => new Promise(resolve => setTimeout(resolve, delayMs)) | |
| // Long Running Process - LRP with cancel function! |
| /** | |
| * Sends a String of data to the Mac OSX Buffer, this is very helpful if | |
| * you are doing something in scratch pad and want to copy it somewhere. | |
| * | |
| * this beats Pipe-ing the output to pbcopy directly. | |
| * | |
| * @param {string} data - Required UTF-8 String to be copied to the buffer. | |
| * | |
| * @return {void} |
| const https = require('https') | |
| const http = require('http') | |
| const readline = require('readline') | |
| const url = require('url') | |
| function httpRequest(options, data) { | |
| return new Promise((resolve, reject) => { | |
| const parsedUrl = url.parse(options.hostname) | |
| const protocol = parsedUrl.protocol | |
| const request = (protocol && protocol.startsWith('https')) ? https.request : http.request |
Copy everything from one directory to another directory on a different volume in Unix, while retaining permissions, ownership, structure, as well as all creation and modification dates (timestamps)
When Destination is Fresh
rsync -avHAX --numeric-ids /source/directory/ /destination/directory/Caution - removes destination files
To find all files with the extensions .yaml or .yml recursively in Unix / Mac OSX, you can use the find command with this pattern:
find . \( -name '*.yaml' -o -name '*.yml' \)If your Mac reboots, and you want to be notified that it has rebooted.
Create a .plist file at /Library/LaunchDaemons/com.YOUR_COMPANY.rebootnotification.plist. Change YOUR_COMPANY to your domain name in the .plist file. The contents will look like the following, change /path/to/your/script.sh to your script. This .plist file and the /path/to/your/script.sh should be owned by root:wheel my advise is to make it only executable by root. I take no responsiblities for any Security issues.