Skip to content

Instantly share code, notes, and snippets.


Greg Babula gbabula

View GitHub Profile
View quiz.js
'use strict';
// Quiz:
// Implement `solution` function using only calls to API methods below and no
// other JS primitives (even math).
// Correct implementation will print "Success!" once executed
zkat / index.js
Last active Jan 25, 2021
npx is cool
View index.js
#!/usr/bin/env node
console.log('yay gist')
ChrisChares /
Last active Jul 9, 2019
async/await with ES6 Generators & Promises

async/await with ES6 Generators & Promises

This vanilla ES6 function async allows code to yield (i.e. await) the asynchronous result of any Promise within. The usage is almost identical to ES7's async/await keywords.

async/await control flow is promising because it allows the programmer to reason linearly about complex asynchronous code. It also has the benefit of unifying traditionally disparate synchronous and asynchronous error handling code into one try/catch block.

This is expository code for the purpose of learning ES6. It is not 100% robust. If you want to use this style of code in the real world you might want to explore a well-tested library like co, task.js or use async/await with Babel. Also take a look at the official async/await draft section on desugaring.


  • node.js - 4.3.2+ (maybe earlier with
developit /
Last active Feb 27, 2020
Alias to invoke Chrome Canary w/ tracing, for IRHydra

An Alias to run Chrome with tracing enabled

For Chrome Canary:

alias hydra='/Applications/Google\ Chrome\\ Chrome\ Canary --no-sandbox --js-flags="--user-data-dir=/tmp/profile --trace-hydrogen --trace-phase=Z --trace-deopt --code-comments --hydrogen-track-positions --redirect-code-traces"'

For regular ol' Chrome:

View es6-feature-detection.js
var str = 'class ಠ_ಠ extends Array {constructor(j = "a", ...c) {const q = (({u: e}) => {return { [`s${c}`]: Symbol(j) };})({});super(j, q, ...c);}}' +
'new Promise((f) => {const a = function* (){return "\u{20BB7}".match(/./u)[0].length === 2 || true;};for (let vre of a()) {' +
'const [uw, as, he, re] = [new Set(), new WeakSet(), new Map(), new WeakMap()];break;}f(new Proxy({}, {get: (han, h) => h in han ? han[h] ' +
': "42".repeat(0o10)}));}).then(bi => new ಠ_ಠ(bi.rd));';
try {
} catch(e) {
alert('Your browser does not support ES6!')
gbabula / package.json
Last active Aug 29, 2015
g5-component NPM scripts
View package.json
"scripts": {
"serve": "http-server -p 9966",
"start": "npm run serve & npm run build",
"start-dev": "npm run serve & npm run watch",
"build-js": "browserify -u bootstrap -u jquery -u lodash -u isomorphic-fetch src/scripts/g5-component.js --s 'g5-component' | uglifyjs -mc drop_console > src/static/g5-component.js",
"build-js-vendor": "browserify -r bootstrap -r jquery -r lodash -r isomorphic-fetch | uglifyjs -mc > src/static/g5-component-vendor.js",
"build-js-full": "browserify src/scripts/g5-component.js --s 'g5-component' | uglifyjs -mc drop_console > src/static/g5-component.js",
"build-css": "lessc src/styles/component.less > src/static/bundle.css",
"build": "npm run build-js",
"watch-js": "watchify -u bootstrap -u jquery -u lodash -u isomorphic-fetch src/scripts/g5-component.js --s 'g5-component' -o src/static/g5-component.js -dv",
View get_global_object.js
* Returns the global object.
* Works even inside ES6 modules.
function getGlobalObject() {
// Workers don’t have `window`, only `self`
if (typeof self !== 'undefined') {
return self;
if (typeof global !== 'undefined') {
kamranayub / ko.bindingReport.js
Last active Jan 29, 2019
Knockout.js Binding Performance Reporter
View ko.bindingReport.js
* Performance reporting for Knockout binding handlers
* Usage: Include after all bindings are declared, view console for results.
(function () {
var report = [];
var lastReport = 0;
var debounceWait = 500;
ericelliott /
Last active Sep 8, 2020
ES6 defaults / overrides pattern

ES6 Defaults / Overrides Pattern

Combine default parameters and destructuring for a compact version of the defaults / overrides pattern.

function foo ({
    bar = 'no',
    baz = 'works!'
  } = {}) {
View bling.js
/* bling.js */
window.$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
NodeList.prototype.__proto__ = Array.prototype;