Skip to content

Instantly share code, notes, and snippets.

View nyteshade's full-sized avatar

Brielle Harrison nyteshade

View GitHub Profile
@nyteshade
nyteshade / usePseudoState.js
Created December 11, 2023 19:08
Experimentation with a non-react specific useState approximation
/**
* The function `usePseudoState` is a custom hook that allows for the creation of
* pseudo state variables in React. When `useState` becomes available, it should be
* applied to this object output by calling the `init` method with the `useState`
* function.
*
* The object returned from this function invocation
*
* @param initialValue - The `initialValue` parameter is the initial value that
* will be assigned to the pseudo state.
@nyteshade
nyteshade / Descriptors.js
Created December 11, 2023 19:09
Another go at baseline JavaScript additions such as work with Descriptors. Need to compare this with code in ne-reflection and decide which I like best.
Object.assign(Object, {
validKey(value) {
return (typeof value === 'string' || typeof value === 'symbol')
},
isObject(value) {
return value && (value instanceof Object || typeof value === 'object')
},
/**
/**
* A simple Hasher implementation in JavaScript. This mimics the behavior of Swift's
* Hasher to some extent. It uses the djb2 algorithm for hashing.
*/
class Hasher {
/**
* The constructor function takes in multiple values, flattens them into a single
* array, and then calls the combine method on each value.
*
* @param values - The "values" parameter is a rest parameter that allows you to
/**
* The Walker class provides a mechanism for iterating through a string and
* counting occurrences of specified opening and closing characters. It's designed
* to start counting when the first instance of the 'open' character is encountered
* and stops when the count drops back to zero.
*
* @example
* const walker = new Walker("{a{b}c}", {when: () => {}, searchFor: Walker.squigly});
* walker.until(); // Process the string
*
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()) {
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."
}
@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"
@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 / 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 / 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 \