Skip to content

Instantly share code, notes, and snippets.

View nyteshade's full-sized avatar

Brielle Harrison nyteshade

View GitHub Profile
@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
Last active October 10, 2024 06:56
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,
@nyteshade
nyteshade / strnumconvert.c
Last active January 3, 2024 09:27
strnumconvert - C89 parseInt, strtoul, itoa with base 62 support
// strnumconvert.c
#include <limits.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <stddef.h>
#include "strnumconvert.h"
json () {
usage () {
echo "Usage: json [property] [file]"
echo " property: (optional) The property of the JSON object to retrieve."
echo " file: (optional) The file containing the JSON object. Defaults to 'package.json'."
echo ""
echo "Special values for property:"
echo " *: Retrieve the whole object."
echo " --help or -h: Display this help message."
}
globalThis.Descriptor = class Descriptor {
static base(enumerable = true, configurable = true) {
return { enumerable, configurable }
}
static data(value, writable = true, { configurable, writable } = this.base()) {
return { value, enumerable, configurable, writable }
}
static accessor( getter, setter, store, { configurable, writable } = this.base()) {