Skip to content

Instantly share code, notes, and snippets.

View gbabula's full-sized avatar
:shipit:

Greg Babula gbabula

:shipit:
View GitHub Profile
'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
zkat / index.js
Last active March 10, 2024 14:32
npx is cool
#!/usr/bin/env node
console.log('yay gist')
@ChrisChares
ChrisChares / AsyncAwaitGenerator.md
Last active September 30, 2022 13:26
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.

Compatibility

  • node.js - 4.3.2+ (maybe earlier with
@developit
developit / hydra-alias.md
Last active February 27, 2020 01:54
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\ Canary.app/Contents/MacOS/Google\ 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:

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 {
eval(str);
} catch(e) {
alert('Your browser does not support ES6!')
}
@gbabula
gbabula / package.json
Last active August 29, 2015 14:27
g5-component NPM scripts
"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",
/**
* 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
kamranayub / ko.bindingReport.js
Last active June 14, 2023 22:34
Knockout.js Binding Performance Reporter
/**
* 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
ericelliott / defaults-overrides.md
Last active May 7, 2023 13:52
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!'
  } = {}) {
@paulirish
paulirish / bling.js
Last active May 1, 2024 19:56
bling dot 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;