Skip to content

Instantly share code, notes, and snippets.

View nybblr's full-sized avatar
🌱
I help developers craft their best work, achieve goals, and never stop growing.

Jonathan Lee Martin nybblr

🌱
I help developers craft their best work, achieve goals, and never stop growing.
View GitHub Profile
@nybblr
nybblr / async-generator.js
Last active January 19, 2019 02:16
Tiny example of async generator functions
let timer = (ms) => new Promise(resolve => setTimeout(resolve, ms));
let producer = async function*() {
let counter = 0;
while (true) {
let delay = Math.random() * 1000;
await timer(delay);
yield counter++;
}
};
@nybblr
nybblr / concat.js
Created August 30, 2018 15:15
Playing around with ES2015 Proxy to make an array from two others — without copying! i.e. Array Trie.
const intRegex = /^(0|[1-9]\d*)$/;
let isIndex = prop =>
typeof prop === 'string'
&& intRegex.test(prop);
let concat = (left, right) => {
let w = left.length;
let h = right.length;
@nybblr
nybblr / google-sheets.js
Created January 22, 2018 22:43
Google sheets functions for meetup
function getCost(cell) {
return cell.match(/\$[\d.,]+\d/)[0]
}
function getCondition(cell) {
return cell.match(/((like )?new|used|mint|good|great|excellent)/i)[0]
}
function getEmail(cell) {
return (cell.match(/[^\s@]+@[^\s@]+/i) || ['N/A'])[0]
@nybblr
nybblr / slacks-or-shorts.js
Created January 16, 2018 16:02
Should you wear slacks, or should you wear shorts? This Slackbot will help you decide.
const SlackBot = require('slackbots');
const BOT_NAME = 'Slacks or Shorts';
const BOT_TOKEN = '<YOUR-TOKEN-HERE>';
const BOT_HANDLE = 'slacks-or-shorts';
let bot = new SlackBot({
token: BOT_TOKEN,
name: BOT_NAME
});
@nybblr
nybblr / ghost-to-static.sh
Last active December 21, 2017 12:48
Crawl a local Ghost blog instance and convert to a production-ready static site!
#!/bin/bash
DEV_HOST="localhost:2368"
PROD_HOST="blog.yellowscale.com"
BUILD_DEST=${1:-./build}
DEV_URL="http://${DEV_HOST}"
PROD_URL="https://${PROD_HOST}"
# Hop into build directory
pushd $BUILD_DEST > /dev/null
@nybblr
nybblr / metaproxy.js
Created October 28, 2017 18:43
Metaproxy: The proxy that doesn't do anything
/* Metaproxy
* The proxy that doesn't do anything
**/
let target = { a: 1, b: 2, c: 3 }
let handler = new Proxy({}, {
get: (...args) => Reflect[args[1]](...args)
})
@nybblr
nybblr / example.js
Last active April 5, 2018 15:34
In-browser image resizing + processing
import processImage from 'process-image';
var file = /* File() object from drag-n-drop or file input */
var imageProcessOpts = {
maxWidth: 1200,
maxHeight: 1200,
quality: 0.6
};
@nybblr
nybblr / .babelrc
Created March 7, 2017 18:00
ES2017 build pipeline in 5 seconds.
{
"presets": [
"es2015",
"es2016",
"es2017"
],
"plugins": []
}
@nybblr
nybblr / dijkstra.js
Last active July 29, 2019 21:17
Dijkstra's Algorithm in JavaScript.
var graph = [
'AB6',
'AC3',
'BD6',
'CD5',
'CE9',
'DF8',
'DE3',
'EG8',
'FG2'
@nybblr
nybblr / 1-easy.js
Last active July 13, 2022 03:40
3 examples of using Async Generators and Async Iteration in JavaScript!
// Create a Promise that resolves after ms time
var timer = function(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
};
// Repeatedly generate a number starting
// from 0 after a random amount of time
var source = async function*() {