View rxjs-store.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stream$ = new Rx.BehaviorSubject() | |
const createStore = (rootReducer, initialState) => stream$ | |
.mergeMap(ensureStream) | |
.scan(rootReducer, initialState) | |
const dispatch = (actionType, data) => stream$ | |
.next({ type: actionType, payload: data}) | |
const isStream = (value) => (value instanceof Rx.Observable) | |
const ensureStream = (value) => (isStream(value) ? action : Rx.Observable.of(value)) |
View store-class.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class Store { | |
private subscribers: Function[]; | |
private reducers: { [key: string]: Function }; | |
private state: { [key: string]: any }; | |
constructor(reducers = {}, initialState = {}) { | |
this.subscribers = []; | |
this.reducers = reducers; | |
this.state = this.reduce(initialState, {}); | |
} |
View server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fastify = require('fastify'); | |
const fastifyAutoPush = require('fastify-auto-push'); | |
const fs = require('fs'); | |
const path = require('path'); | |
const {promisify} = require('util'); | |
const fsReadFile = promisify(fs.readFile); | |
const STATIC_DIR = path.join(__dirname, 'static'); | |
const CERTS_DIR = path.join(__dirname, 'certs'); |
View virtual-list.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* VirtualList: a universal windowed list for large datasets | |
* | |
* @param {Array} data - array of rows to render | |
* @param {string} rowHeight - height of row container in pixels | |
* @param {function} renderRow - function to render a single homogenous row | |
* @param {number} overscanCount - number of extra rows to pre-render ahead/behind the window | |
* @param {Object} rest - additional props | |
* | |
* @example |
View relativeize.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function relativize(url, to) { | |
let [,base,origin] = to.match(/^(([a-z]+:\/\/[^\/]+)(\/.*?)?)(\/[^\/]*)?$/i) | |
url = String(url).replace(/^\/([^\/])/g, `${origin}/$1`); | |
if (!url.match(/^([a-z]+\:)\/\//i)) url = `${base}/${url}`; | |
return url; | |
} |
View fps.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fps = { | |
sampleSize : 60, | |
value : 0, | |
_sample_ : [], | |
_index_ : 0, | |
_lastTick_: false, | |
tick : function(){ | |
// if is first tick, just set tick timestamp and return | |
if( !this._lastTick_ ){ | |
this._lastTick_ = performance.now(); |
View RingBuffer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class RingBuffer { | |
constructor(capacity, data = []) { | |
this._capacity = capacity; | |
this._buffer = new Array(this._capacity); | |
this._writeIndex = 0; | |
this._readIndex = 0; | |
this._msgsReceived = 0; | |
this._lastMeasurement = performance.now(); | |
this._msgsSinceLast = 0; |
View use-stream.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect, createContext, useContext } from "react"; | |
import { render } from "react-dom"; | |
import { BehaviorSubject, isObservable } from "rxjs"; | |
const Context = createContext(); | |
const Provider = Context.Provider; | |
const useStream = initialState => { | |
let source = isObservable(initialState) | |
? initialState |
View gist:1c61ac71221e26860d27b9a10f782064
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://cdn.shopify.com/s/files/1/1338/7937/files/Bootstrap_Farmer_Ultimate_Microgreen_Cheatsheet_Printable.pdf?v=1604180053 |
View app.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const app = require('express')(); | |
const http = require('http').Server(app); | |
const io = require('./io.js')(http); | |
io.on('connection', socket =>{ | |
console.log('someone connected'); | |
socket.on('start', msg => { | |
io.emit('message', msg); | |
}); | |
socket.on('disconnect', () => { |
NewerOlder