Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am phoenix35 on github.
  • I am phoenix35 (https://keybase.io/phoenix35) on keybase.
  • I have a public key ASDzRSZaF2bYYBZGkQcaE0swdYkAGFt1l3-33Y_CbavufAo

To claim this, I am signing this object:

@Phoenix35
Phoenix35 / number_tags.js
Last active May 26, 2018 20:09
Gist of tags for template literals to 'pretty format' numbers
/* Use:
dec`1_234.5` // >> 1234.5
oct`1_234` // >> 0o1234 === 668
bin`0110_1100` // >> 0b01101100 === 108
hex`A2_34` // >> 0xA234 === 41524
*/
// Heavily based on code by "Kusu"
const templateJoin = (strings, placeholders) => {
const regex = /_/gu
// Courtesy of Kusu
/*
for (const value of obj) {
// loop body
}
*/
{
const it = obj[Symbol.iterator]();
try {
// If the Partial Application Syntax is not available, use this
// Code by Kusu
const partialBinder = ((hole, rest) => {
"use strict";
function partiallyBound(fn, args, ...missing) {
const argsLen = args.length;
const missingIter = missing[Symbol.iterator]();
for (let i = 0; i < argsLen; ++i) {
switch (args[i]) {
// Some generator fun!
// WORK IN PROGRESS
// Only accepts two arguments in the `cb` call for the moment
"use strict";
const cbOnPrev = ((reset) => Object.defineProperty(
function* cbOnPrev (cb) {
let a = yield; // Replace `yield` with `function.sent` once it's a thing
let b = yield a;
@Phoenix35
Phoenix35 / README.md
Last active December 4, 2018 11:35
JavaScript - where to start?

If you are completely new to JavaScript or programming in general, follow these steps:

0. Use an evergreen browser (Mozilla Firefox or Google Chrome)

  1. Install DevDocs desktop.
    In "Preferences", enable following documentation
    • CSS
    • DOM
    • DOM Events
  • ESLint
"use strict";
/*
User-defined settings
*/
const protocol = "https"; // Change to http for old-school
/*
Begin!
*/
@Phoenix35
Phoenix35 / prepareAsync.js
Last active April 6, 2019 02:37
Small utility function to delay async operations
/**
* prepareAsync - Wraps an asynchronous function to be called several times with a delay between each call.
* @param {AsyncFunction} cb - The callback to wait for
* @param {number} delay - The delay (in milliseconds) between each call
* @param {Function} onFulfill - Function called after each success
* @param {Function} onError - Function to handle errors thrown during the resolutions of `cb` AND `onFulfill`
* @return {AsyncIterable}
*/
export default function prepareAsync (cb, delay, onFulfill, onError) {
const sleep = { then (resolve) {
"use strict";
const fsP = require("fs").promises;
const path = require("path");
const { cwd, chdir } = process;
/*
Breadth-first
*/
/**
@Phoenix35
Phoenix35 / util-sort.mjs
Last active May 4, 2019 22:32
A few utility functions to make sorting easier
function shallowCompare (comparator, prop) {
return ({ [prop]: a }, { [prop]: b }) => comparator(a, b);
}
function deepCompare (comparator, props) {
return (aRoot, bRoot) => {
let a = aRoot,
b = bRoot;
for (const prop of props) {