Skip to content

Instantly share code, notes, and snippets.

View danielbushman's full-sized avatar

Daniel Bushman danielbushman

View GitHub Profile
@danielbushman
danielbushman / timing-promises.js
Last active January 28, 2024 04:40
Timing callbacks adapted to promises
// 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 = () =>
@danielbushman
danielbushman / ignore-and-remove-node_modules.sh
Created May 8, 2019 22:18
ignore and remove node_modules
echo "node_modules" >> .gitignore
git rm -r --cached node_modules
git commit -m 'ignore and remove node_modules'
git push
@danielbushman
danielbushman / introrx.md
Last active August 28, 2015 02:34 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing

The introduction to Reactive Programming you've been missing

(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.

@danielbushman
danielbushman / 0. JavaScript Function Programming TOC.md
Last active August 29, 2015 14:27 — forked from Integralist/0. JavaScript Function Programming TOC.md
JavaScript Function Programming (scratch pad) -> Most of the code here is modified from the excellent O'Reilly book "Functional JavaScript".

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.

#!/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)
@danielbushman
danielbushman / make_datetime_naive_utc
Last active August 29, 2015 14:05
Make any Python datetime object into a UTC based time-zone-naive datetime. Makes it easier to use UTC everywhere. Makes the bold assumption that anything without time-zone information is already UTC.
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')
@danielbushman
danielbushman / gist:1787064
Created February 10, 2012 05:58
Javascript Homework Assignment
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