Skip to content

Instantly share code, notes, and snippets.

View eiriklv's full-sized avatar

Eirik L. Vullum eiriklv

View GitHub Profile
@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' },
@eiriklv
eiriklv / SyncPath.js
Created March 1, 2017 13:22 — forked from davideast/SyncPath.js
Firebase Social Network Client Fanout
export class SyncPath {
constructor(rootRef, path) {
this._rootRef = rootRef;
this.user = this._rootRef.getAuth();
this._userDataRef = this._rootRef.child(path).child(this.user.uid);
this.data = {};
this._userDataRef.on('value', (snap) => this.data = snap.val() || {});
}
keys() {
return Object.keys(this.data);