Skip to content

Instantly share code, notes, and snippets.

@peerreynders
peerreynders / index.js
Created April 21, 2018 19:07
RxJS in Action Ch10 5C: 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 C: Eliminate Redux using only RxJS
@peerreynders
peerreynders / index.js
Created April 21, 2018 18:50
RxJS in Action Ch10 3C: 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 C: Use RxJS for state and use React.Context
import React, {Component} from 'react';
import PropTypes from 'prop-types';
@peerreynders
peerreynders / AddressInput.js
Created October 22, 2018 14:21
gen-browser Pinger/Ponger refactor - no async await
// file: src/AddressInput.js
import {getPropPathValue} from './Misc';
// --- DOM hook
const _addressInput = document.querySelector('main input[type="text"]');
function selectAddress(event) {
const name = getPropPathValue(event, ['target','constructor','name'], null);
if(name == 'HTMLInputElement') {
event.target.select();
@peerreynders
peerreynders / AddressInput.js
Created October 24, 2018 01:16
gen-browser Pinger/Ponger refactor part 2 - enter RxJS 6
// file: src/AddressInput.js
import {getPropPathValue} from './Misc';
// --- DOM hook
const _addressInput = document.querySelector('main input[type="text"]');
function selectAddress(event) {
const name = getPropPathValue(event, ['target','constructor','name'], null);
if(name == 'HTMLInputElement') {
event.target.select();
@peerreynders
peerreynders / Misc.js
Last active October 25, 2018 13:47
gen-browser Pinger/Ponger refactor part 3 - RxJS 6 on Top of EventSource
// file: src/Misc.js
export const PING = 'ping';
export const PONG = 'pong';
export function now() {
return new Date().toLocaleTimeString();
}
export function toTextFrom(from) {
@peerreynders
peerreynders / quickshot.html
Created October 25, 2018 14:00
gen_browser quickshot
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Quickshot</title>
</head>
<body>
<p>Open the Console!</p>
<p>
<ul>
@peerreynders
peerreynders / ServerEvents.js
Created October 30, 2018 16:18
gen-browser Pinger/Ponger refactor part 4 - Using RxJS fromEvent, using, etc. to remove some boilerplate
/*
file: src/ServerEvents.js
Previous:
- part 3: https://gist.github.com/peerreynders/d59d37dd47016a932ee9c786e3817560
- part 2: https://gist.github.com/peerreynders/a0965c47cce31fb6a6677b90f0ca71cc
- part 1: https://gist.github.com/peerreynders/474145762df0708fe78bf39b548fab00
see also: https://gist.github.com/peerreynders/412911579e4a0c485f67a122634cffe2
@peerreynders
peerreynders / from_pipe.ex
Created December 18, 2018 21:46
Elixir port using named pipe via UNDOCUMENTED open_port/2 functionality
defmodule FromPipe do
#
# NOTE: this use of ports is based on UNDOCUMENTED functionality
# of the open_port/2 function - i.e. could stop working
# in any future release
# http://erlang.org/doc/man/erlang.html#open_port-2
#
# See also:
# Erlang and Named Pipes
# https://gist.github.com/jaredmorrow/1c342c6e9156eddd20b2
@peerreynders
peerreynders / from_pipe.ex
Created December 18, 2018 21:26
Elixir port using named pipe with forwarding script
defmodule FromPipe do
#
# Use a helper script "from_pipe_forward" to communicate
# contents from the named pipe to the port
#
@pipe_name "/tmp/testpipe"
@from_pipe_forward "./from_pipe_forward"
@from_pipe_clean "./from_pipe_clean"
# * terminate potential zombie OS process
@peerreynders
peerreynders / pushbutton.ex
Created January 3, 2019 20:48
Erlang gen_statem module documentation "state_functions" callback mode example "translated" to Elixir
# file: pushbutton.ex
# Translated from: http://erlang.org/doc/man/gen_statem.html#example
# callback mode: :state_functions
# i.e. one callback function per state, so the each possible
# state has to be represented as a bare atom which directly
# identifies the module function to be called (:gen_fsm like).
#
# This example has two states :on and :off.
# Therefore there is an on/3 and an off/3 callback function.
#