Skip to content

Instantly share code, notes, and snippets.

const createCustomElement = function(generator, attributes = []){
const
BUS = Symbol('bus'),
Element = class extends HTMLElement {
constructor(props) {
super(props);
const
instance = Reflect.construct(HTMLElement, [], this.constructor),
emitter = (function(){
const eventMap = new Map();
@tweinfeld
tweinfeld / fetch_stream.html
Created August 17, 2019 17:00
Read a JSONL file over chunked response stream over Kefir
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/kefir@3.8.5/dist/kefir.min.js"></script>
</head>
<body>
<script>
Kefir
@tweinfeld
tweinfeld / template.html
Last active December 1, 2021 10:36
Browser Application Template (Lodash + Kefir + React)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>
<script src="https://cdn.jsdelivr.net/g/lodash@4(lodash.min.js+lodash.fp.min.js)"></script>
<script src="https://cdn.jsdelivr.net/npm/kefir@3.8.5/dist/kefir.min.js"></script>
<script src="https://unpkg.com/react@17/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/react-dom@17/umd/react-dom.development.js" crossorigin></script>
import { fetch } from 'wix-fetch';
const requireAMD = function (url) {
return fetch(url)
.then((res) => res.text())
.then((code) => {
return new Promise((resolve, reject) => {
(new Function("define", code))(
(function () {
let define = (...args) => {
@tweinfeld
tweinfeld / mini_miner.js
Last active April 9, 2018 07:29
A short Stratum client for mining BTCs
const
_ = require('lodash'),
kefir = require('kefir'),
net = require('net'),
https = require('https'),
bigInt = require('big-integer'),
{ createHash } = require('crypto');
const
LOGGLY_API_KEY = "b8d2377d-63d8-4f4c-ae07-fb05bb999b3c",
@tweinfeld
tweinfeld / stateful_routing.html
Created January 3, 2018 16:59
An example of utilizing HTML5's History API in order to save and restore state. Whenever the state changes, a copy of it is stored in History whether it effected the URL route or not. It comes to demonstrate the somewhat concealed benefits of the History API.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://unpkg.com/kefir@3.8.0/dist/kefir.min.js"></script>
<script src="https://unpkg.com/lodash@4.17.4/lodash.min.js"></script>
<script src="https://unpkg.com/react@16.2.0/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@16.2.0/umd/react-dom.development.js"></script>
</head>
<body>
@tweinfeld
tweinfeld / merge_m3u8.js
Created May 27, 2017 20:50
Merge Multiple M3U8 Manifests
let
_ = require('lodash'),
kefir = require('kefir'),
request = require('request'),
url = require('url'),
express = require('express');
let videoSourcesProperty = kefir
.combine([
"https://player.vimeo.com/external/217157675.m3u8?s=4a0c6e0d89f1d443259dc8848866a8b7262ac31e",
@tweinfeld
tweinfeld / repeat_promise.js
Last active April 5, 2017 02:23
Repeat a promise-generating function until resolution
function repeatPromise(func, attempts = 10, delay = 1000) {
let attemptNumber = 0;
return (function internalTry() {
attemptNumber++;
if (attemptNumber > attempts) {
return Promise.reject('Number of attempts exceeded');
} else {
return func().catch(() => new Promise((resolve) => setTimeout(resolve, delay)).then(internalTry));
}
})();
@tweinfeld
tweinfeld / iterable_transformer.js
Last active March 25, 2017 22:53
Transforms Iterables
// Here's a generic transformer helper function
const transform = (function(EMPTY) {
const transform = function*(iterable, trasformers) {
for (let res of iterable) {
for (let i = 0; i < trasformers.length && res !== EMPTY; i++) {
res = trasformers[i](res);
};
if (res !== EMPTY) yield res;
}
@tweinfeld
tweinfeld / frp_react.js
Last active February 9, 2017 13:29
React without Redux or Cycle.js
const
[div, span, button] = ["div", "span", "button"].map((name)=>React.createFactory(name)),
myCounterComponent = function({ count, callback }){
return div({}, [],
button({ onClick: ()=>callback('decrease') }, ["-"]),
span({}, [count]),
button({ onClick: ()=>callback('increase') }, ["+"])
);
},
myCounterCombo = function({ state: { counter_1, counter_2 }, callback }){