Skip to content

Instantly share code, notes, and snippets.

// $(document).ready() replacement.
function ready(fn) {
if (document.readyState != 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
// Randomise a set of items with the following structure:
@hedleysmith
hedleysmith / lead_form_utm_params.js
Created January 23, 2017 23:44
Store UTM params & referrer UTL as subscriber fields on MailChimp form
// $(document).ready() replacement.
function ready(fn) {
if (document.readyState != 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}
// Get UTM params from URL to pass to Mailchimp. Store in localStorage so they follow the user around the site.
@hedleysmith
hedleysmith / component-driven-design.md
Last active November 8, 2016 10:37
Structuring a Component Driven Frontend Application Using Spaces

Structuring a Component Driven Frontend Application Using Spaces

This structure should work well for small and medium size web applications or more document-focused websites. It provides a balance between co-location of component files and separation of components by function.

A 'layered' approach can be used when starting a build using this structure, starting with base styling, a few reusable components and some of your favourite utilities then building each space up.

The aim of this structure is to keep it obvious as to where things go, be able to define areas of ownership and importance and to keep things out of your way when working in a space. This structure scales well to many hundreds of components and works well with a single team workig on a frontend project.

In general, everything should be viewed as some type of encapsulated and independent component.

@hedleysmith
hedleysmith / s3_backup_cron.sh
Created August 16, 2016 16:28
S3 Backup Cronjob
# First, install the Amazon AWS CLI https://aws.amazon.com/cli/
# Then, add the following crontab by running `crontab -e` - this will backup file.ext every hour.
0 * * * * /usr/local/bin/aws s3 cp /path/to/back/file.ext s3://bucket-name/file.$(date +\%Y\%m\%d\%H\%M\%S).ext > /dev/null
@hedleysmith
hedleysmith / fetch_vs_jquery_vs_superagent.js
Created August 12, 2016 15:00
HTTP requests three ways - Fetch API vs jQuery.ajax vs Superagent
/*
* Client-side HTTP requests three ways, using ES6 syntax.
* 1. jQuery.ajax()
* 2. Superagent
* 3. Fetch API
* 4. Bonus helper
*/
// 1. jQuery.ajax()
// http://api.jquery.com/jquery.ajax/
@hedleysmith
hedleysmith / react_examples.md
Last active October 21, 2019 12:59
React.js Examples & Boilerplates

React.js Examples & Boilerplates

A curated list of non-trivial boilerplates, starter kits and examples of React.js based apps.

@hedleysmith
hedleysmith / h2load_installation.sh
Last active November 23, 2023 08:06
Installing nghttp2 & h2load on Ubuntu 14.04
#! /bin/bash
sudo apt-get update
sudo apt-get install g++ make binutils autoconf automake autotools-dev libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev libxml2-dev libev-dev libevent-dev -y
git clone https://github.com/nghttp2/nghttp2.git && cd nghttp2
autoreconf -i
automake
autoconf
./configure --enable-apps
make

Remove unused and dangling docker images

docker rmi $(docker images -a -q)
@hedleysmith
hedleysmith / anvilConnectNodeReusableConfig.js
Created March 16, 2016 16:00
Anvil Connect: Node client basic re-usable config
const configureAnvil = function() {
return anvil.discover()
.then(function (configuration) {
return anvil.getJWKs();
},
function(err) {
console.log(err);
})
.then(function (jwks) {
// To redirect to the registration page instead of signup page use this:
@hedleysmith
hedleysmith / docker-compose.yml
Created November 16, 2015 17:21
docker-compose.yml example with Node.js file watching on OS X
# Backend API service example, uses nodemon to keep server alive and watch for changes.
backendapi:
# Tells docker-compose where ./backendapi/Dockerfile is
build: ./backendapi
# Allows live editing of ./backendapi/app
volumes:
- ./backendapi/app:/app
# Launch Nodemon, using
# -L legacy file watching for compatibility with boot2docker / docker-machine.
# --watch defined to avoid watching the whole container and causing high CPU usage