Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View dperrymorrow's full-sized avatar
💭
🍕

David Morrow dperrymorrow

💭
🍕
View GitHub Profile
@dperrymorrow
dperrymorrow / promiseCatching.js
Created March 16, 2017 23:31
example of catching, what will throw an error and what will not
function failingPromise() {
throw new Error('foobar');
return Promise.resolve(4);
}
// works fine not in chain, error is thrown
failingPromise()
.then(num => {
console.log(num);
});
@dperrymorrow
dperrymorrow / catchPromises.js
Created March 8, 2017 19:00
catch all unhanded promise exceptions in node and in browser
// in the browser
window.addEventListener('unhandledrejection', function(event) {
console.error('Unhandled rejection (promise: ', event.promise, ', reason: ', event.reason, ').');
});
// in Node
process.on('unhandledRejection', (reason, p) => {
console.log("Possibly Unhandled Rejection at: Promise ", p, " reason: ", reason);
@dperrymorrow
dperrymorrow / rebuild.md
Last active April 5, 2017 17:57
manually rebuilding a native module for electron

Install electron-gyp

npm install electron-gyp -g

Get your electron version

$ electron -v
@dperrymorrow
dperrymorrow / config.less
Created January 31, 2017 22:51
emoji linter in atom
.linter-row.decoration {
border-radius: 3px;
justify-content: center;
color: darken(@red, 30%);
.linter-gutter.linter-highlight.error, .linter-gutter.linter-highlight.warning{
&:before {
background-color: darken(@red, 30%) !important;
position: absolute;
### Keybase proof
I hereby claim:
* I am dperrymorrow on github.
* I am dperrymorrow (https://keybase.io/dperrymorrow) on keybase.
* I have a public key whose fingerprint is E5B8 AB61 4395 76F9 7FB2 BA4F 4548 8C8A 56A3 9E6D
To claim this, I am signing this object:
@dperrymorrow
dperrymorrow / FactoryInherit.js
Created December 9, 2016 23:22
Factory Pattern with "Inheritance"
const animal = () => {
return {
name: 'animal',
eat() {
console.log(`my name is ${this.name} i am a eating`);
}
};
}
@dperrymorrow
dperrymorrow / SimpleFactory.js
Last active December 9, 2016 23:20
Simple Factory Pattern
const dog = (name) => {
const type = 'dog';
return {
name: name,
speak() {
console.log(`my name is ${this.name} i am a ${type}`);
}
};
}
@dperrymorrow
dperrymorrow / gist:26c83b9b3b666ea265c4f82c1352d153
Created October 12, 2016 19:24 — forked from belsrc/gist:672b75d1f89a9a5c192c
Simple Vue.js filters that I usually need
/**
* Changes value to past tense.
* Simple filter does not support irregular verbs such as eat-ate, fly-flew, etc.
* http://jsfiddle.net/bryan_k/0xczme2r/
*
* @param {String} value The value string.
*/
Vue.filter('past-tense', function(value) {
// Slightly follows http://www.oxforddictionaries.com/us/words/verb-tenses-adding-ed-and-ing
var vowels = ['a', 'e', 'i', 'o', 'u'];
@dperrymorrow
dperrymorrow / flatten.js
Last active August 10, 2016 20:57
recursive flatten array in Javascript
// see this javascript working at http://jsbin.com/mehemepume/edit?js,console
// the function calls itself recursivly, so there can be any level of nesting and it will still flatten.
var nested = [[1, 2, [3]], 4],
nestedDeep = [1, 2, 3, [4, 5, 6, [[7, [8]], 9, 10]]];
function flatten(arr) {
var flat = [];
@dperrymorrow
dperrymorrow / dabblet.css
Created May 31, 2016 18:54
CSS variables test
/**
* CSS variables test
*/
html { background: red }
@supports (--variables: yes) { /* any variable and any value works */
/* Code here will only be applied in CSS variable-supporting UAs */
html {
background: green;