Skip to content

Instantly share code, notes, and snippets.

@peerreynders
peerreynders / tail.exs
Created Feb 22, 2017
Functional Programming in Erlang: 1.21 Tail recursion
View tail.exs
-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 Feb 27, 2017
Functional Programming in Erlang - 2.6 Practice
View prac206.erl
-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 Apr 21, 2018
RxJS in Action Ch10 1A: A React account balances updates every second
View index.js
// 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 Apr 21, 2018
RxJS in Action Ch10 1B: A React account balances updates every second
View index.js
// 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 Apr 21, 2018
RxJS in Action Ch10 2A: Communicating to child components using a single parent
View index.js
// 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 Apr 21, 2018
RxJS in Action Ch10 3A: Simple banking form with checking text field and withdraw button
View index.js
// 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 Apr 21, 2018
RxJS in Action Ch10 3B: Simple banking form with checking text field and withdraw button
View index.js
// 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 Apr 21, 2018
RxJS in Action Ch10 4A: Building your middleware
View index.js
// 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 Apr 21, 2018
RxJS in Action Ch10 5A: Building the application
View index.js
// 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 Apr 21, 2018
RxJS in Action Ch10 5B: Building the application
View index.js
// 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: