Skip to content

Instantly share code, notes, and snippets.

View nyteshade's full-sized avatar

Brielle Harrison nyteshade

View GitHub Profile
@nyteshade
nyteshade / extensions.mjs
Last active July 5, 2023 18:36
Global Extensions for Classes
// Priavte database for applied extensions
const extensionDB = new Map()
// A constant defining the default set name
export const kDefaultSet = "Default JavaScript Extension Set"
// A constant defining the keys of a descriptor object used with
// Object.defineProperties and Object.defineProperty
export const kDescriptorKeys = [
'value', 'writable', 'get', 'set', 'enumerable', 'configurable',
@nyteshade
nyteshade / typeOf.js
Last active June 9, 2023 18:20
2023 Quick Revamp of typeOf.js/isA.js
/// Grab the underlying type of a value. This will return the true type of
/// a value, whereas typeof will return 'object' for arrays, null, and
/// other non-primitive types.
///
/// @param {any} o - The value to get the type of
/// @returns {string} - The type of the value
const typeOf = o => /\[object (\w+)\]/.exec(Object.prototype.toString.call(o))[1];
/// Determines if the supplied function is actually an ES6+ class or just
/// a regular function by checking its toString() values.
@nyteshade
nyteshade / Deferred.ts
Last active November 10, 2022 23:21
TypeScript Deferred Function
type DeferredResult<DT> = {
promise: Promise<DT>;
resolve: (value?: DT | PromiseLike<DT>) => void;
reject: (reason?: any) => void;
};
type DeferredOptionalResult<DT> = {
promise?: Promise<DT>;
resolve?: (value?: DT | PromiseLike<DT>) => void;
reject?: (reason?: any) => void;
@nyteshade
nyteshade / sideBySide.mjs
Last active November 10, 2022 21:48
SideBySide
const version = {
major: 1,
minor: 2,
patch: 0,
toString() { return `${this.major}.${this.minor}.${this.patch}` },
compare(to) {
if (this.major < to.major) return -1
if (this.major > to.major) return 1
if (this.minor < to.minor) return -1
if (this.minor > to.minor) return 1
@nyteshade
nyteshade / json.js
Last active November 2, 2022 20:47
json cli tool
#!/usr/bin/env node
const FS = require('fs')
const { inspect } = require('util')
const { EOL } = require('os')
const { dirname, basename } = require('path')
const version = {
major: 1,
minor: 1,
@nyteshade
nyteshade / deferredpromise.js
Created October 26, 2022 18:47
Deferred Promises, a useful tidbit that jQuery devised
export class DeferredPromise {
// A definition of this.resolve. If null, this object is uninitialized
resolve = null;
// A definition of this.reject. If null, this object is uninitialized
reject = null;
// A definition of this.promise. If null, this object is uninitialized
promise = null;
@nyteshade
nyteshade / promisify_observable.js
Last active October 26, 2022 04:34
Zen-Observable (Used by ApolloClient) to Promise
/**
* Observables can contain multiple values over time. In order to retrieve
* the values as a single promise, one must promisify the observable by
* reducing each subsequent value into a new array. This shows the order
* of the items as they are returned. Secondly, the promises resolve method
* must be fired from the subscribe() function of the observable.
*
* @param {Observable} o the observable instance to work with
* @return {Promise} a promise that can be used with async/await
*/
@nyteshade
nyteshade / yesno
Created March 26, 2022 05:38
YesNo Shell Command
#!/bin/bash
if [[ "--help" = "$1" ]]; then
printf "Usage: ${0} [Message] [Yes] [No] [Yy]\n"
printf " Message - Defaults to \"Are you sure? \"\n"
printf " (notice the space at the end)\n"
printf " Yes - Positive message defaults to Yes\n"
printf " No - Negative message defaults to No\n"
printf " Yy - Letters to use for possitive message\n\n"
printf " Positive messages exit with 0, Negative\n"
@nyteshade
nyteshade / MyHttpHandler.java
Last active April 7, 2022 18:41
Java 6 WebServer
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.util.Map;
import java.util.regex.Pattern;
import javax.sound.sampled.SourceDataLine;
import java.util.regex.Matcher;
@nyteshade
nyteshade / ViNCEdThemes.js
Last active January 5, 2021 03:08
ViNCEdThemes
/*
Small sample script designed to use JavaScript, with Chrome, to pull the actual
RGB values out of the sample theme images located in the iTerm2 Color Schemes repo
https://github.com/mbadolato/iTerm2-Color-Schemes
To use, navigate to the page above, copy this entire file to the clipboard, open
the developer console (Ctrl-Shift-i and select console, like Command-Shift-i on
macs) and paste the contents into that window.
For the most part, theme image file names are the theme name in snake case, such