Skip to content

Instantly share code, notes, and snippets.

View iconifyit's full-sized avatar
🏠
Working from home

Scott Lewis iconifyit

🏠
Working from home
View GitHub Profile
@iconifyit
iconifyit / git-remove-DS_Store-files.sh
Created September 24, 2020 15:19
Removes .DS_Store (Mac files) from a Git repo
#!/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
@iconifyit
iconifyit / CEP-fixVolumePathBug.jsx
Created September 1, 2020 23:35
Fixes a bug in Adobe CEP where CEP confuses connected drives with local folders when the relative paths are the same. For instance "/Volumes/Users/username" and "/Users/username"
/**
* 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) {
@iconifyit
iconifyit / 08-binary-search.js
Last active February 26, 2020 04:30
30 Days of Algorithms : Day 08 - Binary Search
/*
* Iterative search.
* Big-O = O(logN)
*/
const binarySearch = (haystack, needle) => {
let start = 0,
end = haystack.length - 1;
/*
@iconifyit
iconifyit / quick-sort.js
Last active February 24, 2020 06:04
30 Days of Algorithms : 07 - Quick Sort
/**
* Partitions array into halves.
* O(log n) Big-O notation
* @param items
* @param left
* @param right
* @returns {*}
*/
const partition = (items, left, right) => {
@iconifyit
iconifyit / 06-merge-sort.js
Created February 19, 2020 15:39
30 Days of Algorithms - Day 06 Merge Sort
/**
* Recursively split, sort, and re-merge the array.
* @param unsortedArray
* @returns {*[]|*}
*
* Big-O:
*
* Space complexity : O(n)
* Time complexity : O(n Log n)
*/
@iconifyit
iconifyit / 05-array-to-tree.js
Created February 17, 2020 14:25
30 Days of Algorithms : Day 05 - Create a tree from a flat array.
/**
* 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
@iconifyit
iconifyit / bubble-sort.js
Created February 17, 2020 13:32
30 Days of Algorithms - Day 03 : Bubble Sort
/**
* 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
@iconifyit
iconifyit / 04-shared-list-items.js
Last active March 5, 2020 04:31
30 Days of Algorithms : 04 - Find shared items between two lists.
/**
* Find shared elements between two lists.
* @param {array} x
* @param {array} y
* @returns {[]}
*/
const shared_items = ( x, y ) => {
x.sort();
y.sort();
@iconifyit
iconifyit / find-missing-number-1-n.js
Last active February 15, 2020 18:23
30 Days of Algorithms : Find the missing number in an array of numbers 0 ... N
/**
* 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
@iconifyit
iconifyit / GreatestCommonDivisor.js
Last active February 15, 2020 16:48
30 Days of Algorithms : Euclid's Algorithm to find Greatest Common Divisor
/**
* 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