Skip to content

Instantly share code, notes, and snippets.

@stu-smith
stu-smith / form-utility.js
Last active October 1, 2015 20:07
Simple utility methods to copy Backbone models to and from forms
define([
'jQuery',
'Underscore'
], function ($, _) {
'use strict';
return {
clearForm: function (f) {
@stu-smith
stu-smith / font-metrics.js
Last active March 7, 2016 15:49
Measuring text in JavaScript, server-side, using Adobe font metrics
// FILE: font-metrics.js
(function () {
'use strict';
module.exports['Courier'] = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, -1, 600, 600, 600, 600, -1, 600, 600, 600, 600, 600, 600, 600, 600, -1, 600, -1, 600, 600, 600, 600, 600, 600, 600,
@stu-smith
stu-smith / elementary-setup.bash
Last active August 29, 2015 14:08
Setup for Elementary OS. Probably won't be suitable for your setup...
#!/bin/bash
set -exu
# SublimeHaskell hints:
# ~/.config/sublime-text-2/Packages/SublimeHaskell
# cabal install --reinstall --enable-shared primitive
# http://stackoverflow.com/questions/23927744/where-is-libhsprimitive-0-5-3-0-so
if [ "$(id -u)" != "0" ]; then
// ===================================================
// Predawn enhancements for oldies with bad eyesight.
// ===================================================
// Start with: predawn-ui, predawn-syntax.
// Add highlight-line.
// Suggested font: Source Code Pro 14 or Consolas 14
// Make the tree and tab fonts a little larger.
# Lives in: ~/.i3/config
# i3 config file (v4)
#
# Please see http://i3wm.org/docs/userguide.html for a complete reference!
set $mod Mod4
# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below.
@stu-smith
stu-smith / static-site.yaml
Created December 28, 2017 19:15
AWS CloudFormation for HTTPS static website hosting using S3, CloudFront, and ACM
AWSTemplateFormatVersion: 2010-09-09
Parameters:
RootDomainName:
Type: String
Mappings:
RegionMap:
us-east-1:
S3HostedZoneID: Z3AQBSTGFYJSTF
S3WebsiteEndpoint: s3-website-us-east-1.amazonaws.com
us-west-1:
@stu-smith
stu-smith / lambda-at-edge.yaml
Last active August 5, 2021 17:09
Shows how to use CloudFormation to attach a Lambda@Edge function to a CloudFront distribution to add HSTS and CSP custom headers. NOTE: The stack must be updated twice: once with the condition set to false, and once with it set to true.
AWSTemplateFormatVersion: 2010-09-09
Parameters:
RootDomainName:
Type: String
IncludeLambdaEdge:
Type: String
AllowedValues: ['true', 'false']
Conditions:
IncludeLambdaEdge:
!Equals ['true', !Ref IncludeLambdaEdge]