Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Scott Lewis iconifyit

🏠
Working from home
View GitHub Profile
@iconifyit
iconifyit / git-remove-DS_Store-files.sh
Created Sep 24, 2020
Removes .DS_Store (Mac files) from a Git repo
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
@iconifyit
iconifyit / CEP-fixVolumePathBug.jsx
Created Sep 1, 2020
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"
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) {
@iconifyit
iconifyit / SVGWriterTest.jsx
Last active Apr 9, 2020
Experimental code sending JSX message to com.adobe.svgwriter (internal CEP extension). Not currently working.
View SVGWriterTest.jsx
/*-------------------------------------------------------------------------------------------------------------------------*/
/**
* 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)){
@iconifyit
iconifyit / htaccess-ab-test
Last active Mar 25, 2020
A/B Testing with htaccess
View htaccess-ab-test
# ############################### #
# A/B TESTING (START) #
# ############################### #
# (1) Check if our cookie is already set.
# If so, redirect to the previously-viewed page.
RewriteCond %{HTTP_COOKIE} ab_test_vers=([^;]+)
RewriteRule ^THE-PAGE-BEING-TESTED$ HTTP://YOUR-DOMAIN.COM/tracking/%1 [cookie=ab_test_vers_match:true:YOUR-DOMAIN.COM,L]
@iconifyit
iconifyit / PathSplitter.js
Last active Mar 20, 2020
Split SVG path data into subpaths.
View PathSplitter.js
/**
* This script was taken from a discussion on Google Groups.
* I'm not taking credit for it but sharing it because it is very useful for splitting
* discontinuous absolute paths into continuous subpaths. Where this is particularly
* useful is for importing SVG files into applications like Figma, Sketch, InVision, XD, etc.
*/
/**
* Split discontinuous absolute paths into continuous sub-paths.
*
* Example:
@iconifyit
iconifyit / 04-shared-list-items.js
Last active Mar 5, 2020
30 Days of Algorithms : 04 - Find shared items between two lists.
View 04-shared-list-items.js
/**
* Find shared elements between two lists.
* @param {array} x
* @param {array} y
* @returns {[]}
*/
const shared_items = ( x, y ) => {
x.sort();
y.sort();
@iconifyit
iconifyit / 08-binary-search.js
Last active Feb 26, 2020
30 Days of Algorithms : Day 08 - Binary Search
View 08-binary-search.js
/*
* Iterative search.
* Big-O = O(logN)
*/
const binarySearch = (haystack, needle) => {
let start = 0,
end = haystack.length - 1;
/*
@iconifyit
iconifyit / quick-sort.js
Last active Feb 24, 2020
30 Days of Algorithms : 07 - Quick Sort
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) => {
@iconifyit
iconifyit / 06-merge-sort.js
Created Feb 19, 2020
30 Days of Algorithms - Day 06 Merge Sort
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)
*/
@iconifyit
iconifyit / 05-array-to-tree.js
Created Feb 17, 2020
30 Days of Algorithms : Day 05 - Create a tree from a flat array.
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
You can’t perform that action at this time.