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 / DialogWrapper.js
Last active January 24, 2020 05:27
A wrapper class for dialogs created with the Script UI Dialog Builder by Joonas - https://scriptui.joonas.me/
/**
* @author Scott Lewis <scott@atomiclotus.net>
* @copyright 2020 Scott Lewis
* @version 1.0.0
* @url http://github.com/iconifyit
* @url https://atomiclotus.net
*
* ABOUT:
*
* This JS class is a wrapper for dialogs created with the Script UI Dialog Builder by Joonas Pääkkö.
@iconifyit
iconifyit / valid-number.js
Created January 31, 2020 21:55
Solution to "Is it a valid number coding test". See the first comment below for test cases.
/**
* The main function.
* @param s
* @returns {boolean}
*/
function isNumber(s) {
s = s.trim();
var chars = new Set(s);
@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
@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 / 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 / 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 / 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 / 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 / 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 / SVGWriterTest.jsx
Last active April 9, 2020 10:55
Experimental code sending JSX message to com.adobe.svgwriter (internal CEP extension). Not currently working.
/*-------------------------------------------------------------------------------------------------------------------------*/
/**
* Adds JSON library support for engines that do not include it natively.
*/
"object"!=typeof JSON&&(JSON={}),function(){"use strict";function f(t){return 10>t?"0"+t:t}function quote(t){
return escapable.lastIndex=0,escapable.test(t)?'"'+t.replace(escapable,function(t){var e=meta[t];
return"string"==typeof e?e:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+t+'"'}
function str(t,e){var n,r,o,f,u,i=gap,p=e[t];switch(p&&"object"==typeof p&&"function"==typeof p.toJSON&&(p=p.toJSON(t)),
"function"==typeof rep&&(p=rep.call(e,t,p)),typeof p){case"string":return quote(p);case"number":return isFinite(p)?String(p):"null";
case"boolean":case"null":return String(p);case"object":if(!p)return"null";if(gap+=indent,u=[],"[object Array]"===Object.prototype.toString.apply(p)){