This file contains 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 | |
# .DS_Store files on Mac are meta files that tell Finder the window position and size of a previously opened folder. | |
# They are harmless but add clutter and useless code to your repos. This script removes them from your repo but not | |
# from your local file system. | |
# Remove .DS_Store from git | |
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch |
This file contains 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
/** | |
* Bug fix for the issue described at the link below. | |
* @link https://community.adobe.com/t5/indesign/extendscript-oddity-with-file-folder-on-mac-os-x/m-p/3887816?page=1#M165105 | |
*/ | |
function fixVolumePathBug(filepath) { | |
if ($.os.toLowerCase().indexOf('mac') === -1) return filepath; | |
var $HOME = new Folder('~/').fsName; | |
if (filepath.indexOf($HOME) > 0) { |
This file contains 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
/* | |
* Iterative search. | |
* Big-O = O(logN) | |
*/ | |
const binarySearch = (haystack, needle) => { | |
let start = 0, | |
end = haystack.length - 1; | |
/* |
This file contains 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
/** | |
* Partitions array into halves. | |
* O(log n) Big-O notation | |
* @param items | |
* @param left | |
* @param right | |
* @returns {*} | |
*/ | |
const partition = (items, left, right) => { |
This file contains 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
/** | |
* Recursively split, sort, and re-merge the array. | |
* @param unsortedArray | |
* @returns {*[]|*} | |
* | |
* Big-O: | |
* | |
* Space complexity : O(n) | |
* Time complexity : O(n Log n) | |
*/ |
This file contains 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
/** | |
* Converts a flat array to a tree with runtime O(n) | |
* | |
* Big-O : O(n) | |
* | |
* This algorithm was taken from Phillip Stanislaus's "Performant Array to Tree" | |
* which has O(n) complexity. It builds the tree in a single pass. | |
* @link https://github.com/philipstanislaus | |
* @link https://www.npmjs.com/package/performant-array-to-tree | |
* @see https://github.com/iconifyit/30-Days-of-Algorithms |
This file contains 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
/** | |
* Bubble sort. | |
* @param a | |
* @returns {*} | |
* | |
* Big-O : O(n2) | |
* | |
* From wikipedia: | |
* Bubble sort has a worst-case and average complexity of О(n2), where n is the number of | |
* items being sorted. Most practical sorting algorithms have substantially better worst-case |
This file contains 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
/** | |
* This algorithm finds a missing number in an array of numbers from 1 - N. | |
* This approach only works if there is one-and-only-one missing number, | |
* and no duplicate numbers. There are other algorithms for those cases | |
* which I will cover on a different day. | |
* | |
* Given : a is a list of positive integers from 1 - N | |
* Given : a contains all unique numbers | |
* Given : a has one-and-only-one missing number | |
* Given : n == a.length |
This file contains 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
/** | |
* Euclid's algorithm for Greatest Common Divisor. | |
* @param {int} m | |
* @param {int} n | |
* @returns {string|number} | |
* | |
* Given : 0 < n < m | |
* | |
* 1. Divide m by n. If the remainder is 0, GCD is n. | |
* 2. m <-- n, n <-- r |