Skip to content

Instantly share code, notes, and snippets.

View nyteshade's full-sized avatar

Brielle Harrison nyteshade

View GitHub Profile
@nyteshade
nyteshade / HTML.js
Last active April 20, 2024 05:41
ParamParser and HTML
function ship(code) {
const _ne = Object.entries(code)
.reduce((a, [k,v]) => ({ ...a, [k]:v }), {});
const { defaults = {} } = code;
const [_den, _de] = Object.entries(defaults)?.[0];
if (typeof module !== 'undefined' && module.exports) {
module.exports = _ne || {};
}
else if (_den && _de) { globalThis[_den] = _de; }
}
@nyteshade
nyteshade / Simple Export.js
Created April 20, 2024 00:42
Simple snippet of JavaScript to make exporting vanilla javascript easier
function ship(code) {
const _ne = Object.entries(code)
.reduce((a, [k,v]) => ({ ...a, [k]:v }), {});
const { defaults = {} } = code;
const [_den, _de] = Object.entries(defaults)?.[0];
if (typeof module !== 'undefined' && module.exports) {
module.exports = _ne || {};
}
else if (_den && _de) { globalThis[_den] = _de; }
}
(function() {
const HTML = new Proxy(
class HTML {
static create(
name,
content,
style = {},
attributes = {},
webComponentName = undefined,
useDocument = undefined,
@nyteshade
nyteshade / carrier_string.js
Last active March 7, 2024 19:54
CarrierString
/**
* Creates a `CarrierString` by attaching additional properties to a string.
* This function allows for the creation of a string that carries extra data in a type-safe way.
*
* @param string The base string to which properties will be attached.
* @param key The key of the property to attach, or an object with multiple properties.
* @param value The value associated with the key, if `key` is not an object.
* @returns A new `CarrierString` with the attached properties.
*
* @example
@nyteshade
nyteshade / function.sh
Last active February 16, 2024 01:51
Read macos `mdls` content as JSON or nicely printed in terminal
convertFonts() {
if [[ ${#} -lt 1 ]]; then
echo "Usage: convertFonts <startDir> <outDir> [rename]"
echo "where"
echo " outDir - if missing, this is the same as startDir"
echo "\n\x1b[3mIf rename is \x1b[1mtrue\x1b[22m, old file name is mv'ed to the new name"
echo "otherwise a copy is made and the original is untouched.\x1b[23m"
else
startDir="${1:-.}"
outDir="${startDir}"
@nyteshade
nyteshade / sgr.js
Created February 10, 2024 05:08
Select Graphic Rendition (SGR)
/**
* Applies Select Graphic Rendition (SGR) parameters to a given message for
* styling in terminal environments. This function allows for the dynamic
* styling of text output using ANSI escape codes. It supports a variety of
* modes such as color, brightness, and text decorations like bold or underline.
*
* @param {string} message The message to be styled.
* @param {...string} useModes A series of strings representing the desired
* styling modes. Modes can include colors (e.g., 'red', 'blue'), brightness
* ('bright'), foreground/background ('fg', 'bg'), and text decorations
@nyteshade
nyteshade / api.js
Created January 25, 2024 21:09
Snowflake JavaScript API (Jan 25, 2024)
[
AggregateError: function {
constructor, name, message,
},
Array: function {
length, constructor, at, concat, copyWithin, fill, find, findIndex,
lastIndexOf, pop, push, reverse, shift, unshift, slice, sort, splice,
includes, indexOf, join, keys, entries, values, forEach, filter, flat,
flatMap, map, every, some, reduce, reduceRight, toLocaleString, toString,
@nyteshade
nyteshade / Dockerfile
Created January 23, 2024 21:48
Getting NVM setup in a docker image
# Replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
RUN echo 'debconf debconf/frontend select Noninteractive' | debconf-set-selections
RUN mkdir -p /usr/local/nvm
ENV NVM_DIR /usr/local/nvm
ENV NODE_VERSION 21.6.1
RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash \
&& . $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
@nyteshade
nyteshade / url.sql
Created January 10, 2024 02:29
Snowflake Auto URL Parsing SQL
-- Drop the existing procedure if it exists
DROP PROCEDURE IF EXISTS SANDBOX_PRODUCT_ENGINEERING.CONTENT_OPTIMIZATION.insert_update_url_entry;
-- Create the new stored procedure
CREATE OR REPLACE PROCEDURE SANDBOX_PRODUCT_ENGINEERING.CONTENT_OPTIMIZATION.insert_update_url_entry(
p_id FLOAT,
p_href TEXT,
p_name VARCHAR)
RETURNS STRING
LANGUAGE JAVASCRIPT
@nyteshade
nyteshade / url_table.sql
Created January 10, 2024 02:04
PostgreSQL URL Table With Computed Values
-- Drop existing trigger and function if they exist
DROP TRIGGER IF EXISTS trigger_before_insert_update_url_entry ON url_entries;
DROP FUNCTION IF EXISTS before_insert_url_entry();
-- Drop the existing table if it exists
DROP TABLE IF EXISTS url_entries;
-- Create the new table
CREATE TABLE url_entries (
id SERIAL PRIMARY KEY,