Skip to content

Instantly share code, notes, and snippets.

@a-h
a-h / disablecaching.go
Created August 20, 2019 08:15
Disable caching and sniffing via HTTP headers
func DisableCachingAndSniffing(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate;")
w.Header().Set("pragma", "no-cache")
w.Header().Set("X-Content-Type-Options", "nosniff")
next.ServeHTTP(w, r)
})
}
@a-h
a-h / default.md
Last active August 20, 2019 22:13
Tools
{"lightId":"1","states":[true,true,true,true,true]}

Keybase proof

I hereby claim:

  • I am a-h on github.
  • I am adrianhesketh (https://keybase.io/adrianhesketh) on keybase.
  • I have a public key whose fingerprint is 0227 7F96 9055 ACF7 36CE 8954 9E01 3872 2232 3123

To claim this, I am signing this object:

@a-h
a-h / esp32_audio.ino
Created March 17, 2019 19:35
ESP32 DAC square wave
#include <U8x8lib.h>
U8X8_SSD1306_128X64_NONAME_SW_I2C u8x8(/* clock=*/15, /* data=*/4, /* reset=*/16);
// Timer setup.
volatile int interruptCounter;
volatile int totalInterruptCounter;
hw_timer_t *timer = NULL;
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
@a-h
a-h / lambda.js
Created February 5, 2019 14:09
Lambda@Edge to carry out redirects and apply default documents (index.html) to incoming requests
var path = require('path');
const redirects = {
"/about-us": { to: "/about", statusCode: 301 },
"/contact-us/head-office": { to: "/contact/head-office", statusCode: 302 },
};
exports.handler = async event => {
const { request } = event.Records[0].cf;
const normalisedUri = normalise(request.uri);
@a-h
a-h / redirect.yaml
Created February 5, 2019 09:09
Apex redirect handling using AWS Network and Application Load Balancers
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Sets up the required resources for the website at example.com
Parameters:
DomainName:
Type: String
Description: The website domain name.
Default: example.co.uk
RedirectTo:
Type: String
@a-h
a-h / default.md
Created January 31, 2019 16:29
Security vulnerability tracking

What you wanted to do

Check that my program is free from known security vulnerabilities.

For example, if a package I'm using has a security vulnerability in it, I want to be notified to upgrade or warned.

What you actually did

Checked the https://nvd.nist.gov/vuln/search for Go related issues, but found that only core packages were listed. I noticed that some packages had vulnerabilities listed (e.g. https://nvd.nist.gov/vuln/detail/CVE-2018-1002207) but couldn't work out how to find them programatically. I wrote a program to scan the NIST database for Go language related vulnerabilities and to let me know anyway - https://github.com/a-h/nvdnotifier

@a-h
a-h / main.go
Created December 21, 2018 15:21
Circle CI AWS Credentials Cycling
package main
import (
"bytes"
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
@a-h
a-h / 01_nodemcu.ino
Last active November 11, 2018 21:48
Updated door sensor
#include <WiFiServerSecure.h>
#include <WiFiClientSecure.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiUdp.h>
#include <ESP8266WiFiType.h>
#include <ESP8266WiFiAP.h>
#include <WiFiClient.h>
#include <WiFiServer.h>
#include <ESP8266WiFiScan.h>