Skip to content

Instantly share code, notes, and snippets.

View eiriklv's full-sized avatar

Eirik L. Vullum eiriklv

View GitHub Profile
@eiriklv
eiriklv / server.js
Last active April 26, 2018 10:41
Simple server
/**
* Dependencies
*/
const express = require('express');
const history = require('connect-history-api-fallback');
/**
* Environment / configuration
*/
const port = process.env.PORT || 3000;
@eiriklv
eiriklv / exercises.txt
Created April 18, 2018 13:28
Exercises
1. Basic Syntax
- http://jsbin.com/kixovom/
2. Types and Literals
- http://jsbin.com/bagofoc/
3. Truth and Equality
- http://jsbin.com/feyepub/
4. Functions
- http://jsbin.com/tuzezip/
5. Objects
- http://jsbin.com/qukaqig/
@eiriklv
eiriklv / HTTPGetRequestForQueriesInterface.js
Created September 27, 2017 12:17 — forked from n1ru4l/HTTPGetRequestForQueriesInterface.js
HTTPGetRequestForQueriesInterface
import { HTTPFetchNetworkInterface, printAST } from 'apollo-client';
/**
* Serialize a object to a query string
* @source https://stackoverflow.com/questions/1714786/query-string-encoding-of-a-javascript-object#comment47677757_18116302
*/
function serialize( obj ) {
return `?` + Object.keys(obj).map(k => k + `=` + encodeURIComponent(obj[k])).join(`&`);
}
@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 / 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 / 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
*/