Skip to content

Instantly share code, notes, and snippets.

Avatar

Eirik L. Vullum eiriklv

View GitHub Profile
View populating-graph-using-naming-conventions.js
/**
* 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 Aug 22, 2018
Seatbelts on!
View seatbelt.js
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
Data modeling an online store
View example.js
/**
* 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
*/
View adams-heroku-values.md

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

View create-reconnecting-websocket.js
/**
* 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 Apr 7, 2017
Data Modeling Stepwise Form Example
View data-modeling-stepwise-form.js
/**
* 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 Mar 3, 2017
Modeling an election in JavaScript
View election.js
/**
* 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 Mar 1, 2017 — forked from davideast/SyncPath.js
Firebase Social Network Client Fanout
View SyncPath.js
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);
View kangax-es6-quiz-explained.md

@kangax's ES6 quiz, explained

@kangax created a new interesting quiz, this time devoted to ES6 (aka ES2015). I found this quiz very interesting and quite hard (made myself 3 mistakes on first pass).

Here we go with the explanations:

Question 1:
(function(x, f = () => x) {
@eiriklv
eiriklv / avoiding-exceptions.js
Last active Feb 2, 2019
Exception free JavaScript?
View avoiding-exceptions.js
/**
* WHY? - BECAUSE EXCEPTIONS/TRY/CATCH IS A GLOBAL HORRIBLE MESS :-(
* Check out error handling in golang: https://blog.golang.org/error-handling-and-go
*/
/**
* Wrap an "unsafe" promise
*/
function safePromise(promise) {
return promise