Skip to content

Instantly share code, notes, and snippets.

@EECOLOR
EECOLOR / throttledChildAdded.js
Last active July 2, 2019 22:37 — forked from iclems/Firebase Lazy-Safe Iterator
This snippet enables to iterate over a Firebase reference in a non-blocking way. If you need to iterate over a large reference, a child_added query may block your Firebase as it will query the whole data before iteration. With this snippet, children are retrieved one by one, making it slower / safer.
module.exports = function throttledChildAdded(ref, callback, onError, sortChildKey = null /* uses `key` if null */) {
const state = { stopped: false }
let listener = null
throttledChildAdded({ state, endReached: lastSeen => { listener = listenForNewChildren({ startAfter: lastSeen }) } })
return () => {
state.stopped = true
if (listener) ref.off('child_added', listener)
@nyg
nyg / iOSCreatePDF.swift
Last active April 2, 2024 11:09
iOS, Swift: Create a PDF file from an HTML string.
// Thanks to http://www.labs.saachitech.com/2012/10/23/pdf-generation-using-uiprintpagerenderer
// Note: including images in the HTML won't work, see here:
// https://github.com/nyg/HTMLWithImagesToPDF
import UIKit
// 1. Create a print formatter
let html = "<b>Hello <i>World!</i></b>"
let fmt = UIMarkupTextPrintFormatter(markupText: html)