Skip to content

Instantly share code, notes, and snippets.

View xjamundx's full-sized avatar

Jamund Ferguson xjamundx

View GitHub Profile
// rely on try/catch around the awaited Promise
async function doSomething() {
try {
let data = await getData()
} catch (err) {
console.error(err)
}
}
// add a catch handler
// basic error handling with async functions
async function getData(param) {
if (isBad(param)) {
throw new Error("this is a bad param")
}
// ...
}
// basic promise-based error handling example
function getData(param) {
// async function to show user data
async function displayUserData() {
let me = await fetch('/users/me')
console.log(me)
}
// promise-based equivalent
function displayUserData() {
return fetch('/users/me').then(function(me) {
console.log(me)
// here is an async function
async function getNumber() {
return 4 // actually returns a Promise
}
// the same function using promises
function getNumber() {
return Promise.resolve(4)
}
webpack --display-modules | awk '{print $3$4" "$2}' | grep -v bytes | sort -n | tail -100
{ test: /modernizr.*/, loader: 'imports?this=>window!exports?window.Modernizr' },`
@xjamundx
xjamundx / elm-setup-guide.md
Last active October 31, 2015 21:22
Elm for Absolute Beginners

Elm is an exciting new programming language that hopes to transform the way people write web apps. It's inspired by a lot of functional programming ideas in languages like haskell, but hopes to make them accessible to web developers. Recently, I hoped to get started trying out some of the examples on Elm's website, but found the directions lacking. What follows is a recap of my journey to getting a working Elm setup on my computer.

tldr;

  1. Install Elm
  2. mkdir new-project; cd new-project;
  3. elm-package install evancz/elm-html
  4. elm-package install evancz/start-app
@xjamundx
xjamundx / es6-examples.md
Last active August 29, 2015 14:26
Examples for my talk ES6 for everyone

If you're a designer your main interaction with JavaScript is probably through jQuery and jQuery plugins. If that's you, here are a few examples of how ES6 might make your life a litle bit better.

Default Parameters

$.fn.makeJump = function(height) {
    height = height || 50; // jump up 50px
    // ...
}
$(".chickens").makeJump();
@xjamundx
xjamundx / no-cjs.js
Created July 22, 2015 16:39
ESLint Rule for encouraging es6 modules over commonJS
/**
* @fileoverview Rule to prefer ES6 to CJS
* @author Jamund Ferguson
*/
'use strict';
var EXPORT_MESSAGE = 'Expected "export" or "export default"',
IMPORT_MESSAGE = 'Expected "import" instead of "require()"';
@xjamundx
xjamundx / no-define.js
Last active August 29, 2015 14:25
no-define
/**
* @fileoverview Rule to prefer require() (CJS) over define() (AMD)
* @author Jamund Ferguson
*/
'use strict';
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------