Skip to content

Instantly share code, notes, and snippets.

Jonathan Neal jonathantneal

Block or report user

Report or block jonathantneal

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jonathantneal
jonathantneal / _define.js
Last active Sep 13, 2019
_define: Return an object with a property defined in a class prototype manner
View _define.js
// 209/154 byte/gzip
/**
* Return an object with a property defined in a class prototype manner
* @param {T} object object on which to define the property
* @param {String|Symbol} key name or symbol to be defined
* @param {Descriptor} proto descriptor for the property being defined
* @template T
* @return {T}
*/
@jonathantneal
jonathantneal / es5class.js
Created Sep 13, 2019
An ES5 Class Creator
View es5class.js
// 281 bytes:
/** Return a class with prototype values conditionally inheriting from a super class
* @param {string} name name of the class
* @param {Object<string,any>} prototype prototype values of the class
* @param {Function} [Super] super class inherited by the class
* @return {Function}
*/
function _class(name, prototype, Super) {
var Class = Function('_', 'return function ' + name + '(){return _(this,arguments)}')(
@jonathantneal
jonathantneal / _extends.js
Last active Sep 13, 2019
_extends: Extend a class with a super class
View _extends.js
// 128/122 byte/gzip
/** Extend a class with a super class
* @param {Function} Class - class inheriting from the super class
* @param {Function} Super - super class inherited by the class
* @example <caption>Yayay extends Array</caption>
* function Yaray() {}
* _extends(Yaray, Array)
*/
function _extends(Class, Super) {
@jonathantneal
jonathantneal / README.md
Last active Sep 12, 2019
Minimal Node Servers
View README.md

Minimal Node Servers

A collection of code snippets that create servers in as few steps as possible.

Minimal HTTP Server

// setup (61 bytes):
const http = require('http');
@jonathantneal
jonathantneal / getUnsupportedBrowsersByCaniuseId.js
Last active Jun 20, 2019
Return a list (`[]`) of all unsupported browsers (`"${browser} ${version}"`) by a caniuse id (`"${id}"`)
View getUnsupportedBrowsersByCaniuseId.js
const caniuse = require('caniuse-lite');
// return a list of all unsupported browsers by a caniuse id
function getUnsupportedBrowsersByCaniuseId (caniuseId) {
// get compressed feature details from caniuse-lite by a caniuse id
const featureDetails = caniuse.features[caniuseId];
// if the feature exists
if (featureDetails) {
// get browsers stats for the feature
@jonathantneal
jonathantneal / getPropertyDescriptor.js
Created Jun 19, 2019
The getPropertyDescriptor method returns a property descriptor of a given object
View getPropertyDescriptor.js
/**
* Return the property descriptor of a given object
* @param {Object} obj - The object for which to access property descriptors
* @param {String|Symbol} key - The name or Symbol of the property whose descriptor is to be retrieved
* @return {Object} The property descriptor of the given object
*/
function getPropertyDescriptor (obj, key) {
if (obj === undefined || obj === null) {
throw new TypeError('Cannot convert undefined or null to object');
@jonathantneal
jonathantneal / README.md
Last active May 21, 2019
JavaScript Array Transduce and FlatMap Alternative
View README.md

transduce

The transduce function creates a new array of elements passing a filter and resulting from a map.

Implementation

function transduce (filterCallbackFn, mapCallbackFn, ...transduceArgs) {
  return Array.prototype.reduce.call(
    this,
@jonathantneal
jonathantneal / README.md
Created May 1, 2019
babel-plugin-transform-globals: How I generate browserGlobals.js
View README.md
  1. In each browser, I get a JSON-stringified array of every property name on window except itself. I place these names into files like name.chrome.json or name.firefox.json.
<!doctype html>
<body>
<script>
(function () {
	const windowNames = Object.getOwnPropertyNames(window).filter(name => name !== 'window');
	const textarea = document.createElement('textarea');
	textarea.value = JSON.stringify(windowNames);
View babel-plugin-utils.js
function getReplacementIdentifiers (globals, types) {
return Object.keys(Object(globals)).reduce(
(object, name) => Object.assign(object, {
[name]: module.exports.createMemberExpressionFromString(globals[name], types)
}),
{}
);
}
function getImportsBySource (globals) {
@jonathantneal
jonathantneal / recovery.sh
Last active Oct 8, 2019
Create or update macOS Mojave Recovery Partition Without Reinstalling
View recovery.sh
#!/bin/sh
# Set the macOS installer path as a variable
MACOS_INSTALLER="/Applications/$(ls /Applications | grep "Install macOS")"
MOUNT_POINT="$MACOS_INSTALLER/Contents/SharedSupport"
echo "macOS installer is \"$MACOS_INSTALLER\""
# Set the target disk as a variable
TARGET=$(diskutil info "$(bless --info --getBoot)" | awk -F':' '/Volume Name/ { print $2 }' | sed -e 's/^[[:space:]]*//')
echo "Target disk is \"$TARGET\""
You can’t perform that action at this time.