Skip to content

Instantly share code, notes, and snippets.

@a-h
a-h / main.go
Created May 29, 2016 21:13
Sign and Verify Data With PEM Files
package main
import (
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
"encoding/pem"
"fmt"
@a-h
a-h / verifytoken.js
Created June 14, 2016 09:42
Verify JWT Using Public Key
var jose = require('node-jose');
var fs = require('fs')
var exampleJwt = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiYm9iIn0.j-_SmegNrMidWYQIJUaZF7wy0jFqURrczA56mPD30aR8Vm8R909P4ptI8T3ZDnwCqPCF6g8Hv2klGOfzaRcP33gKiKcev1dz3jQibFSz2X2g-2cuQz-SMyp_zgZ-_vYwtM-9sXgl-CGBqGsEQ_OxWi42AqQ7lOeYtO3hZ1W1yESzYyzHetH0d__KfCoGD0Jbe3okkmxFuJrCfNNGdIhoMj8SDnrK5BZ2a-M2BWO-RFECRiw5ybuyVGhOCxFwFzsUQu2r6Gliu9_WQnysFluaK65gQ5nDi5-CaKf2DqmPrh3Bp_dmT4huTjnJB4PshX-j0IE6UdbVMpbThL55Y9V_1Q"
var keystore = jose.JWK.createKeyStore();
var key
fs.readFile('public.pem', 'utf8', (err, data) => {
@a-h
a-h / setup.tf
Last active October 9, 2024 03:11
Terraform - Creating an Instance with an S3 Bucket Policy
# Create an IAM role for the Web Servers.
resource "aws_iam_role" "web_iam_role" {
name = "web_iam_role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
@a-h
a-h / handler.go
Created July 4, 2016 21:45
Middleware to Hash a HTTP Request
package sign
import (
"bytes"
"crypto/sha256"
"encoding/hex"
"io/ioutil"
"net/http"
"net/http/httptest"
)
@a-h
a-h / schema.js
Created July 19, 2016 13:13
Test Schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"address": {
"id": "address",
"type": "object",
"description": "Address",
"properties": {
"houseName": {
"type": "string",
@a-h
a-h / output.go
Created July 19, 2016 13:14
schematyper output
package main
// generated by "./schematyper /Users/adrian/goprojects/src/github.com/a-h/schemagenerators/exampleschema.json" -- DO NOT EDIT
// Address
type address struct {
County string `json:"county,omitempty"`
District string `json:"district,omitempty"`
FlatNumber string `json:"flatNumber,omitempty"`
HouseName string `json:"houseName,omitempty"`
@a-h
a-h / output.go
Created July 19, 2016 13:14
Schematic Output
// Stuff related to making a HTTP call.
// Address
type Address struct {
County string `json:"county" url:"county,key"` // County
District string `json:"district" url:"district,key"` // Address 2
FlatNumber string `json:"flatNumber" url:"flatNumber,key"` // Flat
HouseName string `json:"houseName" url:"houseName,key"` // House Name
HouseNumber string `json:"houseNumber" url:"houseNumber,key"` // House Number
Postcode string `json:"postcode" url:"postcode,key"` // Postcode
@a-h
a-h / output.go
Last active July 19, 2016 13:15
Generate Output
package main
type Address struct {
County string `json:"county,omitempty"`
District string `json:"district,omitempty"`
FlatNumber string `json:"flatNumber,omitempty"`
HouseName string `json:"houseName,omitempty"`
HouseNumber string `json:"houseNumber,omitempty"`
Postcode string `json:"postcode,omitempty"`
Street string `json:"street,omitempty"`
@a-h
a-h / main.go
Created August 30, 2016 16:30
Version Web Server
package main
import (
"io"
"log"
"net/http"
"github.com/gorilla/mux"
)
@a-h
a-h / terminate_instance_on_new_release.js
Created November 21, 2016 18:23
An AWS Lambda function which destroys an instance from each auto-scaling group. This should be set to trigger on a new software release being put into an S3 bucket.
const spawn = require('child_process').spawn;
exports.handler = function(event, context) {
const terminator = spawn('./terminator', ["-terminateOldVersions=false", "-port=80", "-isDryRun=false", "-autoScalingGroups=AUTO_SCALING_GROUP_NAMES"]);
terminator.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
terminator.stderr.on('data', (data) => {