Skip to content

Instantly share code, notes, and snippets.

View nyteshade's full-sized avatar

Brielle Harrison nyteshade

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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 / type.js
Last active November 11, 2023 16:23
Vanilla Type Checker
export class Type {
/**
* Creates an instance of the Type class.
*
* @param {string} typeName - The name of the type.
* @param {Object} format - An object representing the format for the type.
* @param {Function} constructor - The constructor function for the type.
*/
constructor(typeName, format, constructor = null) {
this.typeName = typeName
@nyteshade
nyteshade / .zsh.fns
Created October 28, 2023 01:26
JSON Helper in ZSH
#!/usr/bin/env zsh
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."
@nyteshade
nyteshade / reindent_script.py
Created August 15, 2023 03:53
Python Codemod to Modify All Indentation from 4 to 2 Spaces, Recursively, In a Directory
import os
import sys
def modify_indentation(code):
new_code_lines = []
for line in code.splitlines():
leading_spaces = 0
# Count the leading spaces in increments of 4
while leading_spaces + 4 <= len(line) and line[leading_spaces:leading_spaces + 4] == ' ':