Skip to content

Instantly share code, notes, and snippets.

View mfbx9da4's full-sized avatar

David Alberto Adler mfbx9da4

View GitHub Profile
@mfbx9da4
mfbx9da4 / observableStateTree.ts
Last active December 28, 2020 13:48
An observable tree data structure. An observable state tree is a normal nestable dictionary except that listeners can be bound to any subtree of the tree. (This has since moved to a repo https://github.com/mfbx9da4/observable-state-tree)
import { assert } from '../utils/assert'
export type Callback = (value: any, prevValue: any) => void
type DestroyCallback = () => void
interface ListenerNode {
parent: Symbol | ListenerNode
children: Record<string, ListenerNode>
prevValue: any
@mfbx9da4
mfbx9da4 / debouncedChunkedQueue.ts
Last active September 19, 2023 08:01
An implementation of a debounced chunked async queue. An async function may be called many times over some period of time. We want to first debounce the calls to the function and batch up all those arguments into one argument. Secondly all executions of that async function should be serialized in a FIFO manner.
export const debouncedChunkedQueue = <T>(
fn: (items: T[]) => Promise<void> | void,
delay = 1000
) => {
let items: T[] = []
let started = false
const push = (item: T) => {
items.push(item)
if (!started) start()
}
@mfbx9da4
mfbx9da4 / cloudSettings
Last active September 18, 2020 16:43
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-09-18T15:19:54.936Z","extensionVersion":"v3.4.3"}
edges = [
{
node: {
description: null,
namespace: "arena",
valueType: "JSON_STRING",
value:
'["https://babywipeseco.myshopify.com/collections/nappies","https://babywipeseco.myshopify.com/collections/wipes","https://babywipeseco.myshopify.com/collections/"]',
id: "gid://shopify/Metafield/12637127966851",
key: "app_home__link",
@mfbx9da4
mfbx9da4 / latency.txt
Created April 10, 2020 17:40 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
import { Component } from 'react'
class OverlayDesign extends Component {
state = {
hide: true,
}
listener = event => {
if (event.keyCode === 74) {
this.setState({ hide: !this.state.hide })
}
}
function time(fn) {
var s = performance.now()
fn()
return performance.now() - s
}
function average(array) {
return array.reduce((prev, cur) => prev + cur, 0) / array.length
}
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker image rm $(docker images --filter "dangling=true" -q --no-trunc)
# docker image rm -f $(docker images -a -q)
docker volume rm $(docker volume ls -q)
docker network rm $(docker network ls -aq)
docker container ls -a
docker image ls -a
docker volume ls
version: "3.3"
services:
db:
image: mysql:5.7
restart: always
environment:
MYSQL_DATABASE: "DATABASE_NAME"
MYSQL_USER: "DB_USER"
MYSQL_PASSWORD: "DB_PASS"
MYSQL_ROOT_PASSWORD: "DB_PASS"