Skip to content

Instantly share code, notes, and snippets.

View nyteshade's full-sized avatar

Brielle Harrison nyteshade

View GitHub Profile
@nyteshade
nyteshade / prompt.sh
Created November 17, 2023 04:11
Prompt user with binary question
#!/usr/bin/env zsh
promptUser() {
# Check if no parameters are supplied
if [[ $# -eq 0 ]]; then
echo "Usage: promptUser <message> [positiveWord] [negativeWord]"
return 1
fi
local message=$1
@nyteshade
nyteshade / tldraw-share.mjs
Created November 22, 2023 21:41
Quick generation of a sharable tldraw
#!/usr/bin/env node
async function generateNewSharedTlDraw() {
var myHeaders = new Headers();
myHeaders.append("Accept-Language", "en-US,en;q=0.9");
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Origin", "https://www.tldraw.com");
myHeaders.append("Referer", "https://www.tldraw.com");
myHeaders.append("Sec-Ch-Ua", "\"Chromium\";v=\"119\", \"Not?A_Brand\";v=\"24\"");
myHeaders.append("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36");
@nyteshade
nyteshade / README.md
Last active December 2, 2023 18:17
A class that can be used to track values over time.,

Historical Data Management Library

Overview

This library provides a generic Historical<T> class for tracking and managing the history of values in JavaScript and TypeScript applications. It is designed to be versatile, supporting undo/redo operations, callback registration for value changes, and serialization/deserialization functionalities. Additionally, the library offers integration with Angular applications through a dedicated service, HistoricalService, and an example Angular component, MyComponent, demonstrating its practical use.

Installation

(TODO: Add installation steps here once available)

@nyteshade
nyteshade / instructions.md
Created December 2, 2023 18:28
ChatGPT Instructions

List of Your Instructions

  1. Docstring Instructions: Provide JSDoc comment blocks for all methods, properties, and types in code examples, including private ones. Ensure that the docstring comments wrap at no more than 90 columns for readability. Avoid aligning the continuation lines of parameter descriptions in docstrings.

  2. Code Examples: Provide complete and detailed implementations in code examples. Include all relevant modifications and enhancements as per the discussion or request. Ensure that the code adheres to good programming practices and is well-documented.

  3. General Output Guidelines: Provide detailed and comprehensive answers. Incorporate personal insights where appropriate, while adhering closely to the specifics of your query. In the context of software development, adhere to best practices in coding and documentation.

  4. Documentation for Private Entries: Ensure that private properties, functions, types, and interfaces in code examples also include comprehen

@nyteshade
nyteshade / json.sh
Created December 4, 2023 14:09
Quick smaller version jq for JSON
#!/usr/bin/env node
const { readFile } = require('fs/promises')
const { format, parse } = require('path')
const expected = { attending: v => /true|1|yes/i.exec(v) ? true : false }
const { interpreter, executable, args, flags } = processArgsForFlags(process.argv, expected)
console.log(interpreter)
console.log(executable)
console.log(args)
@nyteshade
nyteshade / NEReflect.js
Created December 5, 2023 20:21
Sample reusable extensions on Reflect
/**
* A custom wrapper around the Reflect API, providing additional utility methods.
* It inherits all properties and methods from the Reflect object and adds custom methods.
*/
const NEReflect = Object.assign(Object.setPrototypeOf({}, Reflect), {
/**
* Checks if all specified properties exist on the given object.
*
* @param {Object} object - The object to check for properties.
* @param {...string} props - One or more property names to check for existence.
@nyteshade
nyteshade / NEObject.js
Created December 5, 2023 20:21
Extensions to Object for use in JavaScript
const NEObject = Object.assign(Object.setPrototypeOf({}, Object), {
/**
* Applies a custom tag to the string representation of an object.
*
* This method modifies the passed object by defining a custom tag that
* will be returned when calling `Object.prototype.toString` on the object.
* This is achieved by defining a getter for `Symbol.toStringTag` which returns
* the specified tag name. The property is set as non-enumerable and configurable.
*
* @example
@nyteshade
nyteshade / Count.js
Last active December 10, 2023 08:02
Tickers are small state objects that are designed to increment or decrement values within themselves
import { Ticker } from './ticker.js'
/**
* The `Count` class extends the `Ticker` class and provides additional methods
* for arithmetic operations on the count value, like adding, subtracting,
* multiplying, and dividing by a specified delta value.
*/
class Count extends Ticker {
/**
* Adds a specified delta value to the current count value and returns the
@nyteshade
nyteshade / Tokens.js
Created December 10, 2023 07:58
Relies on Tickers
/* eslint-disable eqeqeq */
/* eslint-disable no-new-func */
import { Count, Strings, Ticker } from './ticker';
/**
* Finds the closing token for a given opening token in a string, starting from a
* specified index.
*
* @param {string} str - The string in which to find the closing token.
* @param {number} startIndex - The index in the string from which to start the search.
import { useState } from "react";
function usePropertyState(obj, properties) {
const [_, triggerUpdate] = useState({});
const [__, setObject] = useState(obj);
const props = properties && Array.isArray(properties) ? properties : Reflect.ownKeys(properties);
const propertySet = new Set(properties);
// Creating a proxy for the object