Skip to content

Instantly share code, notes, and snippets.

Avatar
🐤

Mathias Schäfer molily

🐤
View GitHub Profile
@molily
molily / .eslintrc.js
Last active Feb 27, 2018
Eslint config based on eslint-config-airbnb 14.0.0, eslint-plugin-import 2.2.0, eslint-plugin-jsx-a11y 3.0.2
View .eslintrc.js
module.exports = {
parserOptions: {
ecmaVersion: 7,
sourceType: 'module',
ecmaFeatures: {
jsx: true,
experimentalObjectRestSpread: true
}
},
View cancelablePromise-test.js
import cancelablePromise, { CancelError } from '../cancelablePromise';
const originalError = new Error('original error');
const expectCancelError = (reason, message) => {
expect(reason).toEqual(jasmine.any(CancelError));
expect(reason.name).toBe('CancelError');
expect(reason.message).toBe(message || 'Promise was cancelled');
};
@molily
molily / CustomError.js
Last active May 24, 2016
Custom error class that inherits from Error
View CustomError.js
// Manual inheritance without super call. We can’t use `class` declaration
// since the Babel compilation output will call Error.call(this, arguments),
// which always returns a new Error instance instead of the instance.
// See http://www.ecma-international.org/ecma-262/6.0/#sec-error-constructor
// Apart from this change, we’re using Babel’s approach of inheritance:
// https://github.com/babel/babel/blob/v6.9.0/packages/babel-helpers/src/helpers.js#L210-L225
/* eslint-disable func-style */
function CustomError(message) {
// NO super call here
View keyboardHelper.js
/* global KeyboardEvent */
const supportsKeyboardEvent = (() => {
try {
new KeyboardEvent('keydown'); // eslint-disable-line no-new
} catch (e) {
return false;
}
return true;
})();
@molily
molily / tests.js
Created Mar 9, 2016
Fail tests on console.error calls (e.g. React warnings)
View tests.js
// Overwrite console.error so calls to it fail a test.
// This is mostly targeted at React warnings. For example, the test should not
// cause React missing prop warnings.
/* eslint-disable no-console */
const originalConsoleError = console.error;
console.error = (...args) => {
originalConsoleError.apply(console, args);
throw new Error(`console.error was called: ${args[0]}`);
};
/* eslint-enable no-console */
View promisePolyfill.js
import RSVP from 'rsvp';
export default () => {
if (!window.Promise) {
window.Promise = RSVP.Promise;
// Show uncaught Promise errors on the console
RSVP.on('error', (reason) => {
/* eslint-disable no-console */
console.error('Uncaught Promise exception', reason);
/* eslint-enable no-console */
View object.coffee
# Returns the prototype chain of an object.
# In old browsers, falls back to the __super__ property
# set up by CoffeeScript classes.
# Returns an array.
getPrototypeChain = do ->
if Object.getPrototypeOf
(object) ->
chain = []
while object = Object.getPrototypeOf(object)
chain.push object
@molily
molily / 2016.md
Last active Jan 1, 2016
Top tech to learn in 2016!
View 2016.md
  • HTML
  • CSS
  • JavaScript
  • HTTP
  • Responsive design
  • Performance
  • Mobile First
  • Progressive enhancement
  • User experience
  • Accessibility
@molily
molily / code.js
Created Dec 2, 2015
JavaScript flamewars
View code.js
var treeWalker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
while (treeWalker.nextNode()) {
var node = treeWalker.currentNode;
node.nodeValue = node.nodeValue.replace(/(F|f)ramework/g, '$1lamewar');
}
You can’t perform that action at this time.