Skip to content

Instantly share code, notes, and snippets.

@peerreynders
peerreynders / index.html
Last active April 2, 2019 18:39
Web Components in Action v6: 7.5.1 Slots without a Name (p.156)
<html>
<head>
<!--
file: index.html
Web Components in Action MEAP v6
https://livebook.manning.com/#!/book/web-components-in-action/chapter-7/v-6/comment-487676
original: https://github.com/bengfarrell/webcomponentsinaction/blob/master/chapter7/7.5-slotsandtemplates/unnamedslots.html
#1:
prevent undefined custom element FOUC (flash of unstyled content)
@peerreynders
peerreynders / index.html
Last active March 30, 2019 00:54
Web Components in Action v6: 5.2.1 Creating a Musical Instrument with Web Components and JS Modules
<html>
<head>
<!--
file: index.html
https://livebook.manning.com/#!/book/web-components-in-action/chapter-5/v-6/comment-487548
https://github.com/bengfarrell/webcomponentsinaction
-->
<title>Web Harp</title>
<link href="./main.css" type="text/css" rel="stylesheet">
<link href="./csshake.min.css" type="text/css" rel="stylesheet">
@peerreynders
peerreynders / index.html
Created March 24, 2019 18:37
Web Components in Action v5; Chapter 2 Your First Web Component: MyCustomTag using in page template element
<html lang="en">
<!-- file: index.html -->
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Chapter 2: Your First Web Component</title>
<style>
my-custom-tag {
background-color: blue;
padding: 20px;
display: inline-block;
@peerreynders
peerreynders / code_lock.ex
Created January 3, 2019 21:02
Erlang gen_statem OTP design principles "handle_event_function" callback mode revised example "translated" to Elixir
# file: code_lock.ex
# Translated from: http://erlang.org/doc/design_principles/statem.html#example-revisited
# callback mode: :handle_event_function
#
defmodule CodeLock do
@behaviour :gen_statem
@name :code_lock_2
def start_link(code),
do: :gen_statem.start_link({:local, @name}, __MODULE__, code, [])
@peerreynders
peerreynders / code_lock.ex
Created January 3, 2019 20:57
Erlang gen_statem OTP design principles "state_functions" callback mode revised example "translated" to Elixir
# file: code_lock.ex
# Translated from: http://erlang.org/doc/design_principles/statem.html#example-revisited
# callback mode: :state_functions
#
defmodule CodeLockCommon do
# Admittedly gratuitous use of a macro
#
def handle_event(:cast, {:down, button}, data) do
{:keep_state, Map.put(data, :button, button)}
end
@peerreynders
peerreynders / pushbutton.ex
Created January 3, 2019 20:53
Erlang gen_statem module documentation "handle_event_function" callback mode example "translated" to Elixir
# file: pushbutton.ex
# Translated from: http://erlang.org/doc/man/gen_statem.html#example
# callback mode: :handle_event_function
# i.e. one callback function handle_event/4 for all states
#
defmodule Pushbutton do
@behaviour :gen_statem
# The registered server name
defp name(),
@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.
#
@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 / 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 / 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