This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # ========================================================= | |
| # to-png | |
| # | |
| # Convert JPG, JPEG, WEBP, and AVIF images to PNG. | |
| # | |
| # Requirements: | |
| # brew install imagemagick | |
| # brew install webp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| python3 -m json.tool /path/to/file/my_json_file.json > /dev/null && echo OK |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pwd | |
| fnm current | |
| ls .nvmrc .node-version 2>/dev/null | |
| # walk upward looking for a version file: | |
| d=$PWD; while [ "$d" != "/" ]; do ls "$d"/.nvmrc "$d"/.node-version 2>/dev/null; d=$(dirname "$d"); done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :g/^/m0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local function system(command) | |
| local file = assert(io.popen(command, "r")) | |
| local output = file:read("*all"):gsub("%s+", "") | |
| file:close() | |
| return output | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /(^\d{5}(-\d{4})?$)|(^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$)/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Checks if a date is before another date. | |
| // - Use the less than operator (`<`) to check if the first date comes before the second one. | |
| const isBeforeDate = (dateA, dateB) => dateA < dateB; | |
| isBeforeDate(new Date(2010, 10, 20), new Date(2010, 10, 21)); // true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Finds the index of a given element in a sorted array using the binary search algorithm. | |
| // | |
| // - Declare the left and right search boundaries, `l` and `r`, initialized to `0` and the `length` of the array respectively. | |
| // - Use a `while` loop to repeatedly narrow down the search subarray, using `Math.floor()` to cut it in half. | |
| // - Return the index of the element if found, otherwise return `-1`. | |
| // - **Note:** Does not account for duplicate values in the array. | |
| const binarySearch = (arr, item) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Checks if a date is after another date. | |
| // Use the greater than operator (`>`) to check if the first date comes after the second one. | |
| const isAfterDate = (dateA, dateB) => dateA > dateB; | |
| isAfterDate(new Date(2010, 10, 21), new Date(2010, 10, 20)); // true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Returns the elements that exist in both arrays, filtering duplicate values. | |
| // Create a `Set` from `b`, then use `Array.prototype.filter()` on `a` to only keep values contained in `b`. | |
| const intersection = (a, b) => { | |
| const s = new Set(b); | |
| return [...new Set(a)].filter(x => s.has(x)); | |
| }; |
NewerOlder