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 / AdobeIllustratorMenuCommands.js
Created September 6, 2021 21:56
Simple function to execute menu commands in an Adobe Illustrator JSX script.
/**
* MenuCommand object for executing Adobe Illustrator menu commands.
* @param {String} kCommandStr
* @param {Boolean} runImmediately
* @constructor
*/
function doMenuCommand(kCommandStr) {
/**
* The Command string
@iconifyit
iconifyit / get-set-as-json-object.sql
Last active February 24, 2024 22:08
(FUNC) Gets set data as single JSON object.
DROP FUNCTION IF EXISTS get_set_data;
CREATE OR REPLACE FUNCTION get_set_data(setId integer)
RETURNS jsonb AS $$
-- ---------------------------------------------
-- Selects set as JSON
-- ---------------------------------------------
select jsonb_build_object(
'set_id', s.id,
'set_name', s.name,
@iconifyit
iconifyit / build-family-json-object.sql
Last active February 19, 2024 20:18
Get Family Data (function)
DROP FUNCTION IF EXISTS get_family_data;
CREATE OR REPLACE FUNCTION get_family_data(familyId integer)
RETURNS jsonb AS $$
WITH counts AS (
SELECT
f.id AS family_id,
COUNT(DISTINCT i.id) AS icons_count,
COUNT(DISTINCT il.id) AS illustrations_count,
COUNT(DISTINCT s.id) AS sets_count
@iconifyit
iconifyit / PathSplitter.js
Last active January 12, 2024 22:20
Split SVG path data into subpaths.
/**
* 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 / 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 / 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 / gray-jsdoc-comments.jsonc
Created September 29, 2023 22:19
Gray out VS Code JSdoc
/* add this in your settings.json (command + shit +p > Preferences : Open User Settings (JSON) */
{
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"name": "storage.type.class.jsdoc",
"scope": "storage.type.class.jsdoc,entity.name.type.instance.jsdoc,variable.other.jsdoc",
"settings": {
"foreground": "#7f848eff"
}
@iconifyit
iconifyit / accounting.sql
Created September 3, 2023 20:49 — forked from 001101/accounting.sql
Basic double-entry bookkeeping system, for PostgreSQL.
CREATE TABLE accounts(
id serial PRIMARY KEY,
name VARCHAR(256) NOT NULL
);
CREATE TABLE entries(
id serial PRIMARY KEY,
description VARCHAR(1024) NOT NULL,
amount NUMERIC(20, 2) NOT NULL CHECK (amount > 0.0),
-- Every entry is a credit to one account...
@iconifyit
iconifyit / htaccess-ab-test
Last active February 10, 2023 03:09
A/B Testing with htaccess
# ############################### #
# 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 / rgb-to-hex.js
Created August 29, 2021 15:55
RGB-to-Hexadecimal and Hexadecimal-RGB conversion
const hexToRgb = (hex) => {
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)
return result ? {
r: parseInt(result[1], 16),
g: parseInt(result[2], 16),
b: parseInt(result[3], 16)
} : null;
}
module.exports.hexToRgb = hexToRgb;