Skip to content

Instantly share code, notes, and snippets.

View eiriklv's full-sized avatar
🤒
Out sick - I may be slow to respond.

Eirik L. Vullum eiriklv

🤒
Out sick - I may be slow to respond.
View GitHub Profile
@eiriklv
eiriklv / classes.md
Created August 30, 2017 06:36
ES6 classes

ES6 Classes

ES2015 has introduced the concept of "classes" in JavaScript.

But be aware - JavaScript classes are just syntactical sugar over JavaScript's existing prototype-based inheritance. The class syntax is not introducing a new object-oriented inheritance model to JavaScript.

JavaScript classes provides simpler and clearer syntax to create objects and deal with inheritance (proceed with caution.. inheritance vs. composition = specialization vs. sharing behavior).

The existing model of prototypal inheritance in JavaScript is based on a special kind of function and the new keyword, which really just alters how the function behaves regarding what it returns and how it sets up the prototype chain.

@eiriklv
eiriklv / requestAnimationFrame.js
Created August 20, 2017 10:19 — forked from jacob-beltran/requestAnimationFrame.js
React Performance: requestAnimationFrame Example
// How to ensure that our animation loop ends on component unount
componentDidMount() {
this.startLoop();
}
componentWillUnmount() {
this.stopLoop();
}
@eiriklv
eiriklv / tic-tac-toe.js
Last active August 5, 2017 10:48
Tic Tac Toe (modeling problems with data and functions)
/**
* Example of empty game using 2D representation
*/
const exampleGame2D = [
['', '', ''],
['', '', ''],
['', '', ''],
];
/**
@eiriklv
eiriklv / populating-graph-using-naming-conventions.js
Last active July 16, 2017 13:43
Populating graphs using proxies
/**
* Dependencies
*/
const { plural } = require('pluralize');
/**
* Get an item from an array collection by id
*/
const getByIdFromArray = (collection = []) => (id = '') => {
return collection.find((item = {}) => item.id === id);
@eiriklv
eiriklv / seatbelt.js
Last active August 22, 2018 12:16
Seatbelts on!
const { log } = console;
const Undefined = new Proxy(function() {}, {
get(target, key, receiver) {
if (key === 'name') {
return 'Undefined';
}
return Undefined;
},
@eiriklv
eiriklv / example.js
Created May 27, 2017 10:30
Data modeling an online store
/**
* Modeling an online store with categories, sub-categories and products
*
* NOTE: The important thing is to be able to
* describe any requirement with the chosen data model
*
* NOTE: Another important thing is conventional interfaces
* and impedance matching. Data should just flow through the
* functions without needing to conform to many different interfaces
*/

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@eiriklv
eiriklv / create-reconnecting-websocket.js
Last active March 9, 2019 14:14
Channels and websockets
/**
* Import dependencies
*/
const { EventEmitter } = require('events');
const ReconnectingWebSocket = require('reconnecting-websocket');
/**
* Export a function that creates a websocket connection interface
*/
export default function createReconnectingWebsocket(uri) {
@eiriklv
eiriklv / data-modeling-stepwise-form.js
Created April 7, 2017 09:25
Data Modeling Stepwise Form Example
/**
* Modeling a step-wise form with data
*
* NOTE: The important thing is to be able to
* describe any requirement with the chosen data model
*
* NOTE: Another important thing is conventional interfaces
* and impedance matching. Data should just flow through the
* functions without needing to conform to many different interfaces
*/
@eiriklv
eiriklv / election.js
Created March 3, 2017 13:08
Modeling an election in JavaScript
/**
* Dependencies
*/
const sortBy = require('sort-by');
/**
* Representing an election as a data structure
*/
const votes = [
{ id: 0, voterId: 'a', zone: 'Oslo', party: 'Miljøpartiet De Grønne' },