Skip to content

Instantly share code, notes, and snippets.

@wearhere
wearhere / HelloWorld.ract
Last active February 9, 2017 07:09
Backbone + Ractive + Rollup
<h1>Hello, {{ titlecase(name) }}</h1>
@wearhere
wearhere / HandlebarsHelpers.js
Last active February 17, 2022 01:37
Backbone + Handlebars + Rollup
export default function(Handlebars) {
Handlebars.registerHelper('titlecase', (string) => {
if (!string) return string;
return string[0].toUpperCase() + string.slice(1);
});
}
@wearhere
wearhere / index.js
Last active January 2, 2017 05:19
How to use https://github.com/mixmaxhq/rollup-plugin-handlebars-plus with jQuery loaded from a CDN.
var rollup = require('rollup');
var handlebars = require('rollup-plugin-handlebars-plus');
var nodeResolve = require('rollup-plugin-node-resolve');
// This can be whatever as long as it's consistent below.
var jqueryModuleId = 'jquery';
rollup({
entry: 'main.js',
external: [jqueryModuleId],
@wearhere
wearhere / deploy_aws.sh
Created October 16, 2016 21:40
CI script to convert a Meteor application into a Node.js application then deploy it to AWS Elastic Beanstalk.
#!/bin/bash
#
# This script will convert a Meteor application into a Node.js application
# then deploy it to AWS Elastic Beanstalk.
#
# Run like `deploy_aws.sh my_eb_app my_eb_app-production`.
#
# That will deploy the Meteor application containing this script
# to the `my_eb_app-production` environment of the `my_eb_app` EB application.
@wearhere
wearhere / custom-npm-install.config
Created October 16, 2016 21:38
`npm install`s a Meteor application bundle during AWS Elastic Beanstalk deployment.
files:
"/opt/elasticbeanstalk/hooks/appdeploy/pre/55npm_install.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
# Custom npm install to work with Meteor/s build command
export USER=root
export HOME=/tmp
@wearhere
wearhere / enable-websockets.config
Last active July 8, 2020 09:26
Patches AWS Elastic Beanstalk's default nginx configuration to support websockets, for use with an Application Load Balancer.
container_commands:
enable_websockets:
command: |
sed -i '/\s*proxy_set_header\s*Connection/c \
proxy_set_header Upgrade $http_upgrade;\
proxy_set_header Connection "upgrade";\
' /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf
@wearhere
wearhere / nginxoptimization.config
Last active April 16, 2022 17:53
Optimized nginx configuration for an AWS Elastic Beanstalk environment using an Application Load Balancer.
files:
"/opt/elasticbeanstalk/#etc#nginx#optimized-nginx.conf":
mode: "000644"
owner: root
group: root
encoding: plain
content: |
# Elastic Beanstalk Managed
# Elastic Beanstalk managed configuration file
@wearhere
wearhere / client.js
Last active August 10, 2016 22:32
Pseudocode for achieving sticky websockets on AWS using per-instance EIPs vended over HTTP.
function connect() {
// Since we'd have sticky HTTP sessions, this will always go to the same instance,
// thus the websocket will connect to the same instance, assuming it's still living.
$.get('/websocket')
.then(function(ipAddress) {
Websocket.connect(ipAddress);
});
}
Websocket.on('disconnection', connect);
@wearhere
wearhere / .gitconfig
Last active July 12, 2016 00:53
Fragment of a .gitconfig showing the `git cleanup` alias.
[alias]
# Run `git cleanup` when your PR(s) have been merged, after checking out master and pulling.
# It will find all the merged (local) branches and delete them for you.
cleanup = "!git branch --merged | perl -ne 'print if not /\\* master/' | xargs git branch -d"
@wearhere
wearhere / 1_preload.js
Last active January 13, 2018 22:09
Using a preload script to safely expose select Node APIs to remote web content. See https://mixmax.com/blog/turnkey-electron-apps-with-meteor#safe-native-bridge for more information.
// Local variables will not escape the preload script.
var shell = require('electron').shell;
// Global variables _will_ escape the preload script, except for globals injected by Node,
// like `require`—-those will be deleted after the script is done executing.
Electron = {
openExternal: function(url) {
shell.openExternal(url);
}
// Notice we don’t save `shell` as a property of `Electron`! Then it’d be available