Skip to content

Instantly share code, notes, and snippets.

View EECOLOR's full-sized avatar

EECOLOR EECOLOR

  • Kaliber
  • Utrecht, Netherlands
View GitHub Profile
@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)
@EECOLOR
EECOLOR / como.scala
Last active August 29, 2015 14:15 — forked from paulp/como.scala
package p {
object Test {
import construction.Monadic
import execution.Bimonad
def main(args: Array[String]): Unit = {
val expression = Monadic[List](10) flatMap (1 to _ toList) coflatMap (_.sum)
@EECOLOR
EECOLOR / freemonads.scala
Last active August 29, 2015 14:02 — forked from runarorama/gist:a8fab38e473fafa0921d
Free monads
sealed trait Interact[A]
case class Ask(prompt: String)
extends Interact[String]
case class Tell(msg: String)
extends Interact[Unit]
trait Monad[M[_]] {
def pure[A](a: A): M[A]