Skip to content

Instantly share code, notes, and snippets.

@peerreynders
peerreynders / another_handler.ex
Created July 29, 2019 00:29
Replacing GenEvent with DynamicSupervisor + GenServer
# file: lib/em_demo/some_handler.ex
#
defmodule EmDemo.AnotherHandler do
use GenServer
@impl true
def init([to_pid, token] = arg) do
IO.puts("#{__MODULE__}: init(#{inspect(arg)})")
{:ok, {to_pid, token}}
end
@peerreynders
peerreynders / demo.exs
Last active September 8, 2019 00:27
Vampire Numbers Elixir demonstration script
# Cobbled together ("untested") demonstration code - no production value
# The intention is to flood all CPU cores with "work"
#
# Created for: https://elixirforum.com/t/finding-vampire-numbers/25098/10
#
defmodule Primes do
require Integer
@primes :primes
@init_last 3
@peerreynders
peerreynders / reactIsAFramework.md
Last active May 6, 2024 08:44
React is a (view component) framework

"Art prior" to React:

Martin Fowler: InversionOfControl (2005-Jun-26)

Inversion of Control is a key part of what makes a framework different to a library. A library is essentially a set of functions that you can call, these days usually organized into classes. Each call does some work and returns control to the client.

A framework embodies some abstract design, with more behavior built in. In order to use it you need to insert your behavior into various places in the framework either by subclassing or by plugging in your own classes. The framework's code then calls your code at these points.

The litmus test:

  • If your code calls it, it's a library.
@peerreynders
peerreynders / DisclosureToggle.svelte
Last active April 18, 2020 01:19
Andy Bell's progressive disclosure (web) component implemented with Svelte 3
<!-- file: src/DisclosureToggle.svelte -->
<svelte:options tag={ null }/>
<script>
import { onMount } from 'svelte';
// prop names ("buttonLabel") aren't converted to
// attribute names ("button-label")
export let label = 'Toggle content';
let trigger;
@peerreynders
peerreynders / filterMap.html
Last active June 10, 2020 18:47
filterMap utility function using JavaScript iteration protocols
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Filter Map</title>
</head>
<body>
<script>
function log(value) {
console.log(value);
}
function executor(resolve, _reject) {
const resolveValue = () => resolve('3 Resolved now');
self.setTimeout(resolveValue, 1000);
}
const pending = new Promise(executor);
/*
**Very Rough** approximation of
fizzbuzz :: Int → String
fizzbuzz n = (test 3 "fizz" ◦ test 5 "buzz") id (show n)
where
test d s x | n ‘mod‘ d ≡ 0 = const (s ++ x "")
| otherwise = x
test :: Int → String → (String → String) → String → String
@peerreynders
peerreynders / index.html
Created September 11, 2020 20:51
A progressive disclosure component with wickedElements
<!doctype html>
<html lang="eng">
<!--
"A progressive disclosure component"
https://hankchizljaw.com/wrote/a-progressive-disclosure-component/
with wickedElements
https://github.com/WebReflection/wicked-elements
@peerreynders
peerreynders / 01before.html
Last active September 21, 2020 23:53
useRefreshCallback - custom hook that also avoids creating garbage functions
<!doctype html>
<html lang="eng">
<head>
<meta charset="utf-8"/>
<title>useCallback alternative BEFORE</title>
</head>
<body>
<script type="module">
import {
html, render, useState, useCallback
@peerreynders
peerreynders / index.html
Last active September 3, 2021 01:14
"use initializer" custom hook
<!doctype html>
<html lang="eng">
<head>
<meta charset="utf-8"/>
<title>useInitializer</title>
</head>
<body>
<script type="module">
import { html, render, useState } from '//unpkg.com/htm/preact/standalone.mjs';