Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am theefer on github.
  • I am theefer (https://keybase.io/theefer) on keybase.
  • I have a public key ASDhvIdbKDHAA91vnw3d0ghMvxTndeVN3B1aM5Zy_tqNtgo

To claim this, I am signing this object:

// Given:
// getFullName(id) => Promise<String>
// getAvatarId(id) => Promise<int>
// getImageById(id) => Promise<String>
// ## Using promises without unnecessary nesting makes it more obvious what
// ## request depend on what other requests (they require async data) and
// ## everything is parallelised by default.
// (Good - parallel) Promises
@theefer
theefer / concurrent-top-level-await.md
Last active September 11, 2016 14:05
Why multiple top-level await quickly become fiddlier than one might think

Properly concurrent top-level await

Besides the valid concerns @Rich_Harris has raised, another thing to worry about is the way await makes it very easy to cause asynchronous work to be scheduled sequentially when it could be parallelised (and hence faster).

Consider the following:

import {getDayOfWeek} from './static-dep';

const dish = getDayOfWeek() === 'friday' ? 'fish' : 'chicken';
@JS('darttest')
library darttest;
import 'package:js/js.dart';
@JS()
external FooBar getFooBar();
@JS()
class FooBar {
(function(win) {
function FooBar() { };
function Node() { };
win.darttest = {
FooBar: FooBar,
Node: Node,
getFooBar: function() {
return new FooBar();
},
@theefer
theefer / sourcemap-validate.js
Created September 19, 2015 16:56
Helper script to validate sourcemaps
#!/usr/bin/env node
var validate = require('sourcemap-validator'),
fs = require('fs'),
assert = require('assert');
var compiledSource = process.argv[2];
if (! compiledSource) {
console.log("usage: validate.js <compiled-source.js>");
process.exit(1);
#!/bin/bash
#
# Open a URL in Chrome after SSH'ing to the URL's host and setting up a SOCKS proxy.
if [ $# -ne 1 ]
then
echo "usage: browse-with-proxy.sh <URL>"
echo
echo "Opens the given URL in a browser using an SSH tunnel to the host as a proxy"
echo
@theefer
theefer / Pipeline.js
Created December 31, 2013 16:50
Sample Luigi Pipeline file to show compilation recipe for Composer. (Note: partial sample with some code omitted)
var glob = require('../luigi/src/operation/glob');
var bower = require('../luigi/src/operation/bower');
var uglify = require('../luigi/src/operation/uglify')();
var concat = require('../luigi/src/operation/concat')();
var requirejs = require('../luigi/src/operation/requirejs');
var hash = require('../luigi/src/operation/hash')();
var rename = require('../luigi/src/operation/rename');
var less = require('../luigi/src/operation/less');
var lodash = require('../luigi/src/operation/lodash');
var write = require('../luigi/src/operation/write');
<input type="text" placeholder="Your Google Music account" size="30"
id="gmusic-switcher-account"
onkeyup="
(function() {
var account = document.getElementById('gmusic-switcher-account').value;
var bookmarklet = document.getElementById('gmusic-switcher-bookmarklet');
var hrefTemplate = bookmarklet.getAttribute('data-href');
var email;
if (validEmail(account)) {
@theefer
theefer / embeds-requirements.md
Last active December 22, 2015 17:38
More details

Embed Requirements

Expectations

  • Declarative markup: semantic content (eg Twitter), degrades gracefully (what if cached, read offline, in Pocket, etc), ideally not iframe? (eg not YouTube)
  • Progressively enhanced: static fallback (eg Twitter, Guardian Video & Comment), ideally feature detection (eg YouTube)
  • Controllable lifecycle: plug and play by default, let host optionally control init and context
  • Lightweight: minimal impact on bandwidth & mem/cpu (eg Flickr, not Twitter)
  • Responsive: fit in parent element
  • Addressable: canonical URL for the embedded content, can be linked to as fallback