Skip to content

Instantly share code, notes, and snippets.

@i-like-robots
i-like-robots / fetch.js
Created March 17, 2019 11:47
Signed AWS requests with node fetch
const nodeFetch = require('node-fetch');
const httpsAgent = require('./httpsAgent');
const handleResponse = require('./handleResponse');
module.exports = async (url, options = {}) => {
const response = await nodeFetch(url, {
...options,
agent: httpsAgent
});
@i-like-robots
i-like-robots / instrumentRequests.js
Last active June 6, 2023 13:18
Instrument Node.js HTTP requests
// Based on <https://blog.bearer.sh/http-api-instrumentation-nodejs/>
const http = require('http')
const https = require('https')
const { URL } = require('url')
const Metrics = require('metrics')
const { performance } = require('perf_hooks')
const metrics = {}
const metricTypes = {
@i-like-robots
i-like-robots / SassMeister-input.scss
Last active January 31, 2022 22:19
Managing responsive typography with Sass
// ----
// libsass (v3.5.0.beta.2)
// ----
// config/_breakpoints.scss
$breakpoints: (
small: 480px,
medium: 720px,
large: 960px,
x-large: 1280px
@i-like-robots
i-like-robots / functions.php
Created August 21, 2012 10:01
Wordpress custom comment form
<?php
/**
* Comment form hidden fields
*/
function comment_form_hidden_fields()
{
comment_id_fields();
if ( current_user_can( 'unfiltered_html' ) )
{
@i-like-robots
i-like-robots / fileUtils.js
Created April 27, 2021 10:23
Mocking a callback with Jest
const fs = require('fs');
const glob = require('glob');
/**
* Find files
* @param {String} globPattern
* @returns {Promise<String[]>}
*/
function findFiles(globPattern) {
return new Promise((resolve, reject) => {
@i-like-robots
i-like-robots / ads.js
Last active January 28, 2021 14:16
Minimum viable IMA implementation for desktop and mobile with support for autoplay when available and basic error handling.
'use strict'
const CLASSNAME_WAITING = 'is-waiting'
const CLASSNAME_LOADING = 'is-loading'
const CLASSNAME_PREROLL = 'is-preroll'
const CLASSNAME_PLAYING = 'is-playing'
const CLASSNAME_PROBLEM = 'is-problem'
// <https://developers.google.com/interactive-media-ads/docs/sdks/html5/sdk-player>
function ads (target) {
@i-like-robots
i-like-robots / data.js
Last active July 16, 2020 14:10
TfL API network data
exports.lines = {
"bakerloo": "Bakerloo",
"central": "Central",
"circle": "Circle",
"district": "District",
"hammersmith-city": "Hammersmith & City",
"jubilee": "Jubilee",
"metropolitan": "Metropolitan",
"northern": "Northern",
"piccadilly": "Piccadilly",
@i-like-robots
i-like-robots / upload-to-s3.sh
Last active October 1, 2019 10:52
Upload client-side assets to S3 via AWS CLI
#!/bin/bash
SOURCE_FILES=($(find public/*.{js,css,gz,br,map} 2>/dev/null))
DESTINATION_BUCKET="hashed-assets-eu"
DESTINATION_FOLDER="page-kit"
for FILE in ${SOURCE_FILES[@]}; do
if [[ $FILE == *".gz" ]]; then
@i-like-robots
i-like-robots / hyperons.js
Last active January 29, 2019 19:33
A quick experiment refactoring Hyperons to output real DOM nodes
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.hyperons = {}));
}(this, function (exports) {
'use strict';
/**
* Base Component class
* @param {object} props The initial component props
@i-like-robots
i-like-robots / handlebars-loop.js
Created June 18, 2013 08:43
Handlebars helper to repeat a chunk of encapsulated output an arbitrary number of times.
// {{#loop 12}}
// <output>
// {{/loop}}
handlebars.registerHelper('loop', function(count, options) {
var out = "";
while (count--) {
out+= options.fn();
}