Skip to content

Instantly share code, notes, and snippets.

@sdebaun
sdebaun / stuff.coffee
Created January 2, 2014 22:31
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
# fb.link 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]]
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=>
/*
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'
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
const NameInput = makeInputControl({
label: 'Enter your name',
className: 'name',
})
const EmailInput = makeInputControl({
label: 'Enter your email',
className: 'email',
})
import {
split, pipe, converge, slice, unfold, pair, append, splitAt,
lte, ifElse, length, concat,
prop, over, lensProp,
F,
} from 'ramda'
import {_BOL, _EOL} from './util'
const toTokens = pipe(split(' '), append(_EOL), concat([_BOL, _BOL, _BOL]))
// ==UserScript==
// @name Toggl on Trello
// @namespace http://tampermonkey.net/
// @version 0.4
// @description Shows toggl entries that match C### where ### is the card number.
// @author sdebaun@sparks.network
// @match https://trello.com/c/*/*
// @match https://trello.com/b/*/*
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_setValue
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { ActivatedRouteSnapshot, Resolve } from '@angular/router';
import {
Opp,
OppService,
Project,
ProjectService,
RequestService,
Request,
@sdebaun
sdebaun / flatten.test.ts
Created January 10, 2019 08:33
using jest, ts-jest
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])
})