Skip to content

Instantly share code, notes, and snippets.

@wearhere
wearhere / create-pull-request.sh
Created November 17, 2014 22:21
Automate creating pull requests.
#! /bin/sh
### This script automates creating a pull request
### by publishing your current topic branch to your remote,
### opening the pull request page in your browser,
### and (optionally) switching you back to your master branch
### so that you can start a new branch.
## Get arguments
# Invoke with no arguments to print usage
@wearhere
wearhere / rewrite_CSP_header.js
Created December 17, 2014 04:36
How to rewrite the 'content-security-policy' HTTP header to work around bugs in the Chrome extension APIs: https://www.mixmax.com/blog/what-to-do-when-your-app-breaks
var hosts = 'https://d1j5o6e2vipffp.cloudfront.net';
var iframeHosts = 'https://app.mixmax.com';
chrome.webRequest.onHeadersReceived.addListener(function(details) {
for (var i = 0; i < details.responseHeaders.length; i++) {
var isCSPHeader = /content-security-policy/i.test(details.responseHeaders[i].name);
if (isCSPHeader) {
var csp = details.responseHeaders[i].value;
csp = csp.replace('script-src', 'script-src ' + hosts);
csp = csp.replace('style-src', 'style-src ' + hosts);
@wearhere
wearhere / injectScript.js
Last active August 29, 2015 14:11
How the Mixmax Chrome extension injects the application JS: https://www.mixmax.com/blog/what-to-do-when-your-app-breaks
var script = document.createElement('script');
script.src = 'https://d1j5o6e2vipffp.cloudfront.net/src/build.js';
script.crossOrigin = 'anonymous';
document.head.appendChild(script);
"content_security_policy": "script-src 'self' https://d1j5o6e2vipffp.cloudfront.net; object-src 'self'; frame-src 'self' https://app.mixmax.com"
//script.crossOrigin = 'anonymous';
// router.js
Router.configure({
waitOn: function() {
// Required in all views.
return Meteor.subscribe('userpreferences', ['theme']);
}
});
Router.route('availability', {
path: '/availability',
@wearhere
wearhere / redis-checking-health.js
Last active August 29, 2015 14:17
A health route that checks the availability of a critical subsystem.
var express = require('express');
var router = express.Router();
// Construct a `RedisStatus` object configured to check the status of
// the Redis server named 'send'.
var sendStatus = require('redis-status')({
name: 'send',
port: process.env.REDIS_PORT,
host: process.env.REDIS_HOST
});
@wearhere
wearhere / testingStripeDeferredAccounts.js
Last active August 29, 2015 14:18
Trying to retrieve a connected Stripe account after creating it with deferred activation.
var stripe = require('stripe')('sk_test_********************otl7');
// I did the below all in the Node REPL so ignore control flow.
stripe.accounts.create({
managed: false,
email: 'jeff+stripetest1@mixmax.com'
}, function(err, account) {
console.log(account.id); // 'acct_***********irAu0'
});
@wearhere
wearhere / deferreds_vs_promises.js
Last active August 29, 2015 14:21
Deferreds vs Promises.
var conn = new Connection();
// QUESTION: how do I call `onceConnected` at the appropriate time? Two cases:
// - If the connection is already connected, I want to call `onceConnected` immediately.
// - If the connection isn't already connected, I want to wait until it connects, then call `onceConnected`.
// And if it fails to connect I should handle that too.
//
// *Important*: Assume that this client can't call `connect`—it doesn't have the necessary parameters.
// It just needs to observe the connection attempt.
function onceConnected() {}
@wearhere
wearhere / LocalCollection.js
Last active October 4, 2021 18:35
A small, browser-only, read-only client for a Meteor backend. More info and examples at https://mixmax.com/blog/meteor-and-backbone.
/**
* A very lightweight version of Meteor's Minimongo collections,
* a local store for records sent from the Meteor backend.
*/
var LocalCollection = function() {
this._initialize();
};
_.extend(LocalCollection.prototype, Backbone.Events, {
_name: null,