python3 -m venv venv
source venv/bin/activate
pip install ...
pip freeze > requirements.txt
// example inspired by https://gist.github.com/chantastic/fc9e3853464dffdb1e3c | |
/* ------------- V0 ------------ | |
* Here you have complex component that is hard to test | |
* and difficult to understand, extend and maintain | |
*/ | |
import React from 'react' | |
class CommentList extends React.Component { | |
constructor() { |
// HigherOrderComponentExample | |
import React, { Component } from 'react' | |
// https://gist.github.com/sebmarkbage/ef0bf1f338a7182b6775 | |
// will augment component to include a loading wheel | |
// curried Higher order function | |
const LoaderHOC = (propName) => (WrappedComponent) => { | |
return class LoaderHOC extends Component { | |
isEmpty(prop) { | |
return ( |
const http = require('http') | |
const HOSTNAME = 'localhost' | |
const PORT = 3000 | |
const client = () => { | |
const bodyString = JSON.stringify({ | |
username: 'foobar', | |
password: 'Password1' | |
}) |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>React::Inline</title> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link rel="stylesheet" href="https://unpkg.com/[email protected]/build/pure-min.css" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous"> | |
</head> | |
<body> | |
<div id="app"></div> |
// Lazy evaluation in javascript | |
// call by name: lazily evaluate the arguments passed into the function | |
// call by value: eagerly evaluate the arguments passed into the function | |
// call by need: memoized version of call by name | |
// memoization: avoid recomputation for the same inputs by caching the results | |
// | |
// Javascript by default uses call by value, however by using Object.defineProperty(), | |
// lazy evaluation in javascript object properties can be performed | |
// | |
// e.g. an infinite data structure - the stream, can only exist with lazy evaluation (else infinite recursion) |
// simplified promise implementation for learning purposes | |
// https://levelup.gitconnected.com/understand-javascript-promises-by-building-a-promise-from-scratch-84c0fd855720 | |
class MyPromise { | |
constructor(promiseCallback) { | |
this.promiseChain = [] | |
this.handleError = () => {} | |
// bind this as onResolve and onReject callbacks are passed into the promise callback | |
this.onResolve = this.onResolve.bind(this) |
function InvalidRequestError(statusCode, message) { | |
const defaultMessage = 'invalid request, status code ' + statusCode; | |
this.name = 'InvalidRequestError'; | |
this.message = message || defaultMessage; | |
this.stack = (new Error()).stack; | |
} | |
InvalidRequestError.prototype = Object.create(Error.prototype); | |
InvalidRequestError.prototype.constructor = InvalidRequestError; |
// Async Await is syntactic sugar over promises | |
// They are not a complete replacement as you still need to construct Promise objects | |
// and methods like Promise.all([]) can only be done with promises | |
const myFetch1 = () => { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
if (Math.random() > 0.05) { // change this to trigger the catch blocks | |
resolve('foo') | |
} else { |
Picking the right architecture = Picking the right battles + Managing trade-offs