Skip to content

Instantly share code, notes, and snippets.

@peerreynders
peerreynders / tail.exs
Created February 22, 2017 02:01
Functional Programming in Erlang: 1.21 Tail recursion
-module(tail).
-export([fib/1, perfect/1]).
% Functional Programming in Erlang
% 1.21 Tail recursion
fib(0) -> 0;
fib(N) when N > 0 -> fib(N,0,1).
% fib(N,0,1) i.e."0,1"
% beginning of "0,1,1,2,3,5,..."
@peerreynders
peerreynders / prac206.erl
Created February 27, 2017 18:15
Functional Programming in Erlang - 2.6 Practice
-module(prac206).
-export([product/1, maximum/1, product1/1, maximum1/1]).
product(Xs) ->
product(Xs,1).
% The product of an empty list is usually taken to be 1: why?
% Identity property of Multiplication:
% Multiplication of any number with 1 results in the original number
@peerreynders
peerreynders / index.js
Created April 21, 2018 18:27
RxJS in Action Ch10 1A: A React account balances updates every second
// file: src/index.js - Derived from:
// RxJS in Action (2017, Manning), 978-1-617-29341-2
// by Paul P. Daniels and Luis Atencio
// Listing:
// 10.1 A React account balances updates every second (p.278)
//
// $ create-react-app in-the-wild
// $ cd in-the-wild
// $ npm i -P rxjs
// $ npm start
@peerreynders
peerreynders / index.js
Created April 21, 2018 18:31
RxJS in Action Ch10 1B: A React account balances updates every second
// file: src/index.js - Derived from:
// RxJS in Action (2017, Manning), 978-1-617-29341-2
// by Paul P. Daniels and Luis Atencio
// Listing:
// 10.1 A React account balances updates every second (p.278)
//
// Variation B:
// - split BalancesView from Balances
// - pass BalancesView via render prop
@peerreynders
peerreynders / index.js
Created April 21, 2018 18:35
RxJS in Action Ch10 2A: Communicating to child components using a single parent
// file: src/index.js - Derived from:
// RxJS in Action (2017, Manning), 978-1-617-29341-2
// by Paul P. Daniels and Luis Atencio
// Listing:
// 10.2 Communicating to child components using a single parent (p.280)
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import registerServiceWorker from './registerServiceWorker';
@peerreynders
peerreynders / index.js
Created April 21, 2018 18:42
RxJS in Action Ch10 3A: Simple banking form with checking text field and withdraw button
// file: src/index.js - Derived from:
// RxJS in Action (2017, Manning), 978-1-617-29341-2
// by Paul P. Daniels and Luis Atencio
// Listings:
// 10.3 Simple banking form with checking text field and withdraw button (p.289)
//
// $ npm i -P redux
import React, {Component} from 'react';
import PropTypes from 'prop-types';
@peerreynders
peerreynders / index.js
Created April 21, 2018 18:46
RxJS in Action Ch10 3B: Simple banking form with checking text field and withdraw button
// file: src/index.js - Derived from:
// RxJS in Action (2017, Manning), 978-1-617-29341-2
// by Paul P. Daniels and Luis Atencio
// Listing:
// 10.3 Simple banking form with checking text field and withdraw button (p.289)
//
// Variation B: Use Top-level source of truth instead of redux
import React, {Component} from 'react';
import PropTypes from 'prop-types';
@peerreynders
peerreynders / index.js
Created April 21, 2018 18:55
RxJS in Action Ch10 4A: Building your middleware
// file: src/index.js - Derived from:
// RxJS in Action (2017, Manning), 978-1-617-29341-2
// by Paul P. Daniels and Luis Atencio
// Listings:
// 10.7 Implementing custom ofType operator (p.299)
// 10.8 Building your middleware (p.299)
import Rx from 'rxjs';
import {createStore} from 'redux';
@peerreynders
peerreynders / index.js
Created April 21, 2018 18:59
RxJS in Action Ch10 5A: Building the application
// file: src/index.js - Derived from:
// RxJS in Action (2017, Manning), 978-1-617-29341-2
// by Paul P. Daniels and Luis Atencio
// Listings:
// 10.6 Plugging into the middleware (p.297)
// 10.7 Implementing custom ofType operator (p.299)
// 10.8 Building your middleware (p.299)
// 10.9 Building the application (p.302)
//
// $ npm i -P pouchdb-browser
@peerreynders
peerreynders / index.js
Created April 21, 2018 19:03
RxJS in Action Ch10 5B: Building the application
// file: src/index.js - Derived from:
// RxJS in Action (2017, Manning), 978-1-617-29341-2
// by Paul P. Daniels and Luis Atencio
// Listings:
// 10.6 Plugging into the middleware (p.297)
// 10.7 Implementing custom ofType operator (p.299)
// 10.8 Building your middleware (p.299)
// 10.9 Building the application (p.302)
//
// Variation B: