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 / javascript-singleton.js
Last active August 25, 2021 02:10
Example of how to implement a Singleton pattern in JavaScript.
/*
* 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
* execution context.
*/
let instance
const Singleton = (() => {
const createInstance = () => {
@iconifyit
iconifyit / wordpress-bootstrap.sh
Created August 19, 2021 21:27
Bootstrap script for basic Wordpress install
#!/bin/bash
yum update -y
yum install httpd php php-mysql -y
cd /var/www/html
echo "healthy" > healthy.html
wget https://wordpress.org/wordpress-latest.tar.gz
tar -xzf wordpress-latest.tar.gz
cp -r wordpress/* /var/www/html/
rm -rf wordpress
rm -rf wordpress-*.tar.gz
@iconifyit
iconifyit / serverless-example.yaml
Created April 26, 2021 15:00
Example serverless file
app: aws-pdf-merge
org: iconify
service: pdf-workflow
custom: ${file(./yml/custom.yml)}
# ================================================================================================
# PROVIDER
# ================================================================================================
provider:
@iconifyit
iconifyit / javascript-singleton.js
Created April 11, 2021 19:04
JavaScript singleton implementation
/*
* 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 = () => {
@iconifyit
iconifyit / resize-selection.jsx
Last active December 17, 2020 13:05
Adobe Illustrator Script - Resize selected items
/**
* 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:
@iconifyit
iconifyit / jsx-console.js
Created November 8, 2020 20:45
Allows you to send log messages to the browser's/CEPClient's console from JSX scripts in CEP panels in Adobe Illustrator. This _may_ work in other apps but has not been tested.
/*
* 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.
@iconifyit
iconifyit / JsonToModel.js
Created January 25, 2020 17:43
Dynamically create a JavaScript class (POJSO) with getters and setters from a JSON object.
/**
* Creates Javascript Model class with getters and setters for each property in a JSON object.
* For instance, if you call :
*
* var model = JsonToModel({name : 'Scott'});
*
* You will get back:
*
* function() {
* this.instance = 'Model@000-000000';
@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 / 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) {