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 / 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 / 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 / DragNDropFromIllustratorPanel.js
Last active October 16, 2023 07:28
Two simple methods for enabling Drag-n-Drop of SVG images from a CEP Panel to the Illustrator canvas.
/**
* What is going on here?
* The Event.dataTransfer object can be set with JavaScript. When the start of a drag event is
* detected, we capture the SVG code as a string and set it to the EventTarget.dataTransfer object
* as a string. Illustrator handles the rest.
*/
/**
* Add drag start callback. Add this method to the <img/> element like so:
*
* <img src="path/to/image.svg" onDragStart="onDragStart" />
@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 / SVGExportAction.jsx
Last active December 10, 2023 00:59
Creates an Adobe Illustrator action to export to SVG on-the-fly.
/*
* This script creates an Adobe Illustrator action, on-the-fly, to export to SVG. The main thing to
* understand is that the `name` values in the action code are hexadecimal-encoded strings. The number
* that immediately preceeds the encoded name are the length of the hex string divided by 2.
*
* Usage:
*
* Change the `basePath` variable to match your file system. This can be set to any folder you like.
*
* Credits:
@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)){
@iconifyit
iconifyit / SelectionExporter.js
Created January 20, 2020 04:10
JavaScript Extension class for exporting a selection in Illustrator as SVG.
/*
* Usage :
*
* new SelectionExporter(
* app.activeDocument.selection[0],
* '/tmp/somefolder/tempfile.ai',
* 'My File'
* );
*/
@iconifyit
iconifyit / Enregistrer la selection en SVG.jsx
Created January 20, 2020 03:57 — forked from SebCorbin/Enregistrer la selection en SVG.jsx
Illustrator script - Save selection as SVG
/*
* Export selection to SVG - export_selection_as_SVG
* (Adapted from Layers to SVG 0.1 - export_selection_as_SVG.jsx, by Rhys van der Waerden)
*
* @author SebCorbin
*/
// Variables
var ignoreHidden = true,
svgExportOptions = (function () {
@iconifyit
iconifyit / react-error-boundary.js
Created January 17, 2020 23:32
Example of React ErrorBoundary (by Dan Abramov)
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { error: null, errorInfo: null };
}
componentDidCatch(error, errorInfo) {
// Catch errors in any components below and re-render with error message
this.setState({
error: error,
@iconifyit
iconifyit / ExportOptionsSVG.js
Created December 20, 2019 04:58
Adobe Ilustrator JSX export as SVG with all ExportOptionsSVG object properties
function getExportOptionsSVG() {
var exportOptions = new ExportOptionsSVG();
/**
* A range of artboards to save, if saveMultipleArtboards is true. A comma-delimited list of artboard names., or the empty string to save all artboards. Default: empty String.
* {string}
*
* NOTE: Set to an empty string to export all. Be sure `saveMultipleArtboards` is set to true to use this.
*/