Skip to content

Instantly share code, notes, and snippets.

@haf
Last active September 5, 2016 16:08
Show Gist options
  • Save haf/33d6c6dd94fc6259efdf05fb2fb1ff95 to your computer and use it in GitHub Desktop.
Save haf/33d6c6dd94fc6259efdf05fb2fb1ff95 to your computer and use it in GitHub Desktop.
Make your OS X firewall mess with connections to js.stripe.com to test your async JavaScript
dig js.stripe.com
<head>
<script type="text/javascript">
//<![CDATA[
function getScript(url, cb) {
var script = document.createElement('script');
script.async = true;
script.src = url;
var head = document.getElementsByTagName('head')[0],
done = false;
script.onload = script.onreadystatechange = function() {
if (!done
&& (!this.readyState
|| this.readyState == 'loaded'
|| this.readyState == 'complete')) {
done = true;
cb();
script.onload = script.onreadystatechange = null;
head.removeChild(script);
};
};
head.appendChild(script);
};
getScript("https://js.stripe.com/v2/", function() {
Stripe.setPublishableKey('pk_test_Jxxxxxx');
});
//]]>
</script>
</head>
#!/usr/bin/env bash
sudo su
dnctl pipe 1 config bw 6Kbit/s plr 0.2 delay 300
echo "dummynet out proto tcp from any to 151.101.84.176 pipe 1" | pfctl -f -
# enable the rules
pfctl -e
# test things
time curl https://js.stripe.com/v2/ ...
# remove the rules
dnctl -q flush
# shutdown the application firewall
pfctl -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment