Skip to content

Instantly share code, notes, and snippets.

/*!
* Reqwest! A general purpose XHR connection manager
* (c) Dustin Diaz 2011
* https://github.com/ded/reqwest
* license MIT
*/
function(a,b){typeof module!="undefined"?module.exports=b():typeof define=="function"&&define.amd?define(a,b):this[a]=b()}("reqwest",function(){function handleReadyState(a,b,c){return function(){a&&a[readyState]==4&&(twoHundo.test(a.status)?b(a):c(a))}}function setHeaders(a,b){var c=b.headers||{},d;c.Accept=c.Accept||defaultHeaders.accept[b.type]||defaultHeaders.accept["*"],!b.crossOrigin&&!c[requestedWith]&&(c[requestedWith]=defaultHeaders.requestedWith),c[contentType]||(c[contentType]=b.contentType||defaultHeaders.contentType);for(d in c)c.hasOwnProperty(d)&&a.setRequestHeader(d,c[d])}function generalCallback(a){lastValue=a}function urlappend(a,b){return a+(/\?/.test(a)?"&":"?")+b}function handleJsonp(a,b,c,d){var e=uniqid++,f=a.jsonpCallback||"callback",g=a.jsonpCallbackName||"reqwest_"+e,h=new RegExp("((^|\\?|&)"+f+")=([^&]+)"),i=d.match(h),j=doc.createElement("script"
@theefer
theefer / gist:3054503
Created July 5, 2012 15:55
Helper mixin to allow invoking the super method using the prototype chain
{
/**
* Invoke the super method corresponding to the caller (child-)method.
*
* Typically useful to call super constructors or destructors.
*
* @param args The arguments object of the caller method.
* @param superArguments Optional arguments to call the super method with.
* @return The result of calling the super method.
*/
@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
<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 / 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');
#!/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 / 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);
(function(win) {
function FooBar() { };
function Node() { };
win.darttest = {
FooBar: FooBar,
Node: Node,
getFooBar: function() {
return new FooBar();
},
@JS('darttest')
library darttest;
import 'package:js/js.dart';
@JS()
external FooBar getFooBar();
@JS()
class FooBar {
@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';