Skip to content

Instantly share code, notes, and snippets.

sdebaun /
Created Jan 2, 2014
Trying to figure out how to have ui.route with stateParams and angularfire bindings work together. I have a list controller that shows a list of games. The html elements in that list should use ui-sref to provide a link to the detail state for a given game. The problem: I am trying to get a game's key so that I can tell the detail state to look …
# in my app config, the route...
.state 'games.list',
url: '/list'
controller: "GameListControl"
.state 'games.detail',
url: '/detail/{gameId:.*}'
controller: "GameDetailControl"
# fb.* methods are from my custom factory
# returns a $firebase link
from random import sample, shuffle
from string import ascii_lowercase
class Game(object):
def __init__(self,player_count, mins_per_player, gains_per_min, gains_per_reform):
self.player_count, self.mins_per_player, self.gains_per_reform, self.gains_per_min = player_count, mins_per_player, gains_per_reform, gains_per_min
self.total_mins = self.player_count * self.mins_per_player
self.minset = [l for l in ascii_lowercase[:self.total_mins]]
View firebaseDriver.js
import Rx from 'rx'
import Firebase from 'firebase'
const FbStream = (ref,evtName)=>
Rx.Observable.create( obs=> ref.on( evtName, (snap)=>obs.onNext(snap) ) )
const AddedStream = ref=>
FbStream(ref,'child_added').map( snap => acc => ({[snap.key()]:snap.val(), ...acc}) )
const ChangedStream = ref=>
View crazyCycleBackend.js
I have a queue that clients submit tasks to, this backend worker consumes them
firebaseDriver: provides a function that generates a one-element observable of a firebase location
queueConsumerDriver: provides a source of all incoming requests, consumes a sink that takes responses
knows via the uid in the response what channel to send it back on
import {makeFirebaseDriver, makeQueueConsumerDriver} from 'cyclic-fire'
View chrome trace
makeDOMDriver.js:78 TypeError: Cannot convert undefined or null to object(…)defaultOnErrorFn
@ makeDOMDriver.js:78Rx.AnonymousObserver.AnonymousObserver.error
@ rx.all.js:1836Rx.internals.AbstractObserver.AbstractObserver.onError
@ rx.all.js:1772tryCatcher
@ rx.all.js:63InnerObserver.error
@ rx.all.js:4574Rx.internals.AbstractObserver.AbstractObserver.onError
@ rx.all.js:1772tryCatcher
@ rx.all.js:63AutoDetachObserverPrototype.error
@ rx.all.js:11818Rx.internals.AbstractObserver.AbstractObserver.onError
@ rx.all.js:1772InnerObserver.error
View factory.js
const NameInput = makeInputControl({
label: 'Enter your name',
className: 'name',
const EmailInput = makeInputControl({
label: 'Enter your email',
className: 'email',
View parser.js
import {
split, pipe, converge, slice, unfold, pair, append, splitAt,
lte, ifElse, length, concat,
prop, over, lensProp,
} from 'ramda'
import {_BOL, _EOL} from './util'
const toTokens = pipe(split(' '), append(_EOL), concat([_BOL, _BOL, _BOL]))
View togglOnTrello.user.js
// ==UserScript==
// @name Toggl on Trello
// @namespace
// @version 0.4
// @description Shows toggl entries that match C### where ### is the card number.
// @author
// @match*/*
// @match*/*
// @require
// @grant GM_setValue
View resolver.ts
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import {
sdebaun / flatten.test.ts
Created Jan 10, 2019
using jest, ts-jest
View flatten.test.ts
const flatten = (arr: Array<any>): Array<any> =>
arr.reduce((a, x) => a.concat(flattenOrArray(x)), [])
const flattenOrArray = (x: any) =>
Array.isArray(x) ? flatten(x) : [x]
test('no nesting', () => {
expect(flatten([1, 2, 3])).toEqual([1, 2, 3])