Skip to content

Instantly share code, notes, and snippets.

View peterjgrainger's full-sized avatar
🐱

Peter Grainger peterjgrainger

🐱
View GitHub Profile
@peterjgrainger
peterjgrainger / get-request-minute.py
Created August 23, 2023 11:16
Requests per minute
# Use cloudwatch API with Boto3 to get the highest requests per second over a given month for wafv2
import boto3
from datetime import datetime, timedelta
client = boto3.client("cloudwatch")
response = client.get_metric_statistics(
Namespace="AWS/WAFV2",
MetricName="AllowedRequests",
Dimensions=[
{"Name": "WebACL", "Value": "test"},
public void readSecret() {
try {
URL yahoo = new URL("http://localhost:2773/secretsmanager/get?secretId=/authorizer/jwt");
URLConnection yc = yahoo.openConnection();
yc.setRequestProperty("X-Aws-Parameters-Secrets-Token", System.getenv("AWS_SESSION_TOKEN"));
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));
String inputLine;
@peterjgrainger
peterjgrainger / create-instance.yaml
Created February 27, 2023 11:57
auto-remediate-wrong-availability-zone
Parameters:
instanceType:
Description: Instance type
Type: String
Default: r6i.xlarge
availabilityZone:
Description: Availability Zone
Type: String
Default: us-east-1i
vpcId:
@peterjgrainger
peterjgrainger / flow-log-parse.txt
Created January 23, 2023 13:14
Parse default flow log in log insights
fields @timestamp, @message
| parse @message "* * * * * * * * * * * * * *" as version, account_id, interface_id, srcaddr, dstaddr, srcport, dstport, protocol, packets, bytes, start, end, action, log_status
| filter action = "REJECT"
| sort @timestamp desc
| limit 2000
@peterjgrainger
peterjgrainger / index.js
Created October 21, 2021 13:29
Headers
var http = require('http');
//create a server object:
http.createServer(function (req, res) {
res.write(JSON.stringify(req.headers)); //write a response to the client
res.end(); //end the response
}).listen(3000); //the server object listens on port 8080
@peterjgrainger
peterjgrainger / gist:d120386e38c27f18289e66c260d84d82
Last active January 19, 2021 21:54
speckle server docker compose file
version: "3"
services:
# this could be enabled once the server container is added
server:
build:
.
depends_on:
- database
- redis
@peterjgrainger
peterjgrainger / duplicate-repos.sh
Last active September 23, 2020 13:15
Duplicate repos
while IFS= read line; do
git clone --bare git@github.com:arup-group/$line.git
cd $line.git
git push --mirror git@github.com:parup-group/$line.git
rm -fr $line.git
done
import boto3
client = boto3.client('cloudwatch')
@peterjgrainger
peterjgrainger / shorten_array.rb
Created January 28, 2019 10:49
Ruby code showing Test Driven Learning
# lib/shorten_array.rb
module ShortenArray
def self.first_two_items(array)
[array[0], array[1]]
end
end
@peterjgrainger
peterjgrainger / shorten_array_spec.rb
Created January 28, 2019 10:48
RSpec test showing Test Driven Learning
# spec/shorten_array_spec.rb
require 'shorten_array.rb'
describe ShortenArray do
it 'returns the first 2 items from the array' do
best_array_ever = %w[best array ever]
result = ShortenArray.first_two_items(best_array_ever)
expect(result).to eq %w[best array]
end
end