Skip to content

Instantly share code, notes, and snippets.

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 Jan 19, 2019
Tiny example of async generator functions
View async-generator.js
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 Aug 30, 2018
Playing around with ES2015 Proxy to make an array from two others — without copying! i.e. Array Trie.
View concat.js
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 Jan 22, 2018
Google sheets functions for meetup
View google-sheets.js
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 Jan 16, 2018
Should you wear slacks, or should you wear shorts? This Slackbot will help you decide.
View slacks-or-shorts.js
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 Dec 21, 2017
Crawl a local Ghost blog instance and convert to a production-ready static site!
View ghost-to-static.sh
#!/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 Oct 28, 2017
Metaproxy: The proxy that doesn't do anything
View metaproxy.js
/* 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 Apr 5, 2018
In-browser image resizing + processing
View example.js
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 Mar 7, 2017
ES2017 build pipeline in 5 seconds.
View .babelrc
{
"presets": [
"es2015",
"es2016",
"es2017"
],
"plugins": []
}
@nybblr
nybblr / dijkstra.js
Last active Jul 29, 2019
Dijkstra's Algorithm in JavaScript.
View dijkstra.js
var graph = [
'AB6',
'AC3',
'BD6',
'CD5',
'CE9',
'DF8',
'DE3',
'EG8',
'FG2'
@nybblr
nybblr / 1-easy.js
Last active Jul 13, 2022
3 examples of using Async Generators and Async Iteration in JavaScript!
View 1-easy.js
// 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*() {