This code is modified from the excellent O'Reilly book "Functional JavaScript". You should buy it, I highly recommend it! Don't kid yourself into thinking this gist even remotely covers the great content from a 200+ page technical book on the subject; it doesn't. Buy the book and get the in-depth knowledge for yourself. It's worth it.
function PubSub() { | |
this.events = {}; | |
} | |
PubSub.prototype = { | |
subscribe: function (e, callback, obj) { | |
if ( !this.events[e] ) this.events[e] = []; | |
if ( typeof(e) != "string" || typeof(callback) != "function" ) return false; | |
this.events[e].push({ | |
callback: callback, | |
obj: obj |
import isodate | |
def make_datetime_naive_utc(dt): | |
delta = dt.tzinfo.utcoffset(dt) if dt.tzinfo else None | |
naive_dt = dt.replace(tzinfo=None) | |
return naive_dt if not delta else naive_dt - delta | |
local_time_with_tzinfo = isodate.parse_datetime('2014-08-20T14:40:18-06:00') |
#!/usr/bin/env bash | |
# gist at https://gist.github.com/miebach/7391024 | |
# save this file to .git/hooks/post-checkout | |
# and also to .git/hooks/post-merge | |
# and make it executable | |
# Delete .pyc files and empty directories from root of project | |
cd ./$(git rev-parse --show-cdup) |
(by @andrestaltz)
So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.
Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:
Rx.Observable.prototype.flatMapLatest(selector, [thisArg])
Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.
echo "node_modules" >> .gitignore | |
git rm -r --cached node_modules | |
git commit -m 'ignore and remove node_modules' | |
git push |
// usage: await timeout(1000); | |
export const timeout = (timeout = 100) => | |
new Promise(resolve => window.setTimeout(resolve, timeout)); | |
// usage: await animationFrame(); | |
export const animationFrame = () => | |
new Promise(resolve => window.requestAnimationFrame(resolve)); | |
// usage: await idle(); | |
export const idle = () => |