Skip to content

Instantly share code, notes, and snippets.

@Dammmien
Dammmien / State.js
Created March 29, 2018 15:19
JavaScript State design pattern
class OrderStatus {
constructor(name, nextStatus) {
this.name = name;
this.nextStatus = nextStatus;
}
doSomething() {
console.log('Do nothing by default');
}
@Dammmien
Dammmien / Strategy.js
Created April 4, 2018 21:22
JavaScript Strategy design pattern
class ShoppingCart {
constructor(discount) {
this.discount = new discount();
this.amount = 0;
}
checkout() {
return this.discount.apply(this.amount);
}
@Dammmien
Dammmien / index.js
Last active May 24, 2019 16:46
Minimalist static file server
#!/usr/bin/env node
const http = require('http');
const url = require('url');
const fs = require('fs');
const path = require('path');
const [ runtime, scriptName, port = 3000, folder = process.cwd() ] = process.argv;
class Server {