View javascript-singleton.js
/* | |
* The instance symbol should be defined in the scope | |
* in which you want the singleton to exist. This does | |
* not necessarily mean globally. Just within your | |
* outermost execution context. | |
*/ | |
let instance; | |
const Singleton = (() => { | |
const createInstance = () => { |
View resize-selection.jsx
/** | |
* Usage : resizeSelectedItems(getUserInput()) | |
* | |
* ========= | |
* CAUTION : This script will scale all selected items. It cannot determine if an object is simple or compound. | |
* ========= It is best to group compound objects made up of multiple PageItems. | |
* | |
* `getUserInput` is separated so you can easily use the main function, `resizeSelectedItems`, | |
* in your code. Make sure the input to `resizeSelectedItems` is a string indicating the | |
* new size. The options are: |
View jsx-console.js
/* | |
* Usage: | |
* | |
* You can load this class either via html <script/> tag: | |
* <script src="path/to/jsx-console.js"></script> | |
* | |
* Or Using require: | |
* const jsxConsole = require('/path/to/jsx-console/jsx-console.js'); | |
* | |
* Then, in your JSX code, use the console object the same as you would the browser console class. |
View git-remove-DS_Store-files.sh
#!/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 |
View CEP-fixVolumePathBug.jsx
/** | |
* 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) { |
View 08-binary-search.js
/* | |
* Iterative search. | |
* Big-O = O(logN) | |
*/ | |
const binarySearch = (haystack, needle) => { | |
let start = 0, | |
end = haystack.length - 1; | |
/* |
View quick-sort.js
/** | |
* Partitions array into halves. | |
* O(log n) Big-O notation | |
* @param items | |
* @param left | |
* @param right | |
* @returns {*} | |
*/ | |
const partition = (items, left, right) => { |
View 06-merge-sort.js
/** | |
* Recursively split, sort, and re-merge the array. | |
* @param unsortedArray | |
* @returns {*[]|*} | |
* | |
* Big-O: | |
* | |
* Space complexity : O(n) | |
* Time complexity : O(n Log n) | |
*/ |
View 05-array-to-tree.js
/** | |
* 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 |
View bubble-sort.js
/** | |
* 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 |
NewerOlder