Skip to content

Instantly share code, notes, and snippets.

View luketn's full-sized avatar

Luke Thompson luketn

View GitHub Profile
const child_process = require('child_process')
function run_script(command, args, realtimeCallback = (log, type) => {console.log(log)}) {
return new Promise((resolve) => {
let child = child_process.spawn(command, args)
let scriptOutput = ""
child.stdout.setEncoding('utf8')
child.stdout.on('data', function (data) {
{
"schemaVersion": "0.3",
"description": "AWSSupport-SetupIPMonitoringFromVPC creates an EC2 instance in the specified subnet and monitors selected target IPs by continuously running ping, MTR, traceroute and tracetcp tests. The results are stored in CloudWatch logs, and metric filters are applied to quickly visualize latency and packet loss statistics in a CloudWatch dashboard.",
"assumeRole": "{{ AutomationAssumeRole }}",
"parameters": {
"SubnetId": {
"type": "String",
"description": "(Required) The subnet ID for the monitor instance. NOTE: If you specify a private subnet, make sure there is Internet access to allow the monitor instance to setup the test (i.e. install the CloudWatch Logs agent, interact with AWS Systems Manager and Amazon CloudWatch).",
"allowedPattern": "^subnet-[a-z0-9]{8,17}$"
},
@luketn
luketn / http-timed-get.ts
Created June 14, 2019 05:11
Timed NodeJS HTTP Get
/**
* Broadly inspired by https://blog.risingstack.com/measuring-http-timings-node-js/
* And https://github.com/RisingStack/example-http-timings
*/
import {IncomingHttpHeaders} from "http";
const https = require('https');
const http = require('http');
const url_lib = require('url');
const NS_PER_SEC = 1e9;
@luketn
luketn / token_revoked.py
Last active June 3, 2019 11:08
CloudFront Based Token Revocation System (only token_revoked may be called by CloudFront, responses will be cached)
from typing import Dict
import boto3
def lambda_handler(event: Dict, context):
try:
path: str = event['path']
if path.startswith('/api/token/revoked/'):
token_id: str = path.split('/')[4]
import {
CloudFrontRequestHandler,
CloudFrontRequestEvent,
CloudFrontRequestResult,
Context,
CloudFrontResultResponse,
CloudFrontHeaders
} from 'aws-lambda';
import {verify} from 'jsonwebtoken';
import {AUTH_PUBLIC_KEY} from './test/public_key';
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* This regex matches JSON documents with the properties 'name' and 'type' and returns a list of the 'dir' type documents.
* e.g. [0.0.1-pre-alpha, 0.0.2-pre-alpha, 0.0.3-pre-alpha, 0.0.4-pre-alpha]
*/
public class RegExFun {
@luketn
luketn / MainFrame.java
Created March 24, 2019 01:38
Little demo of detecting collisions with shapes
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Ellipse2D;
public class MainFrame extends JFrame implements MouseListener {
private int x;
private int y;
'''
Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
http://aws.amazon.com/apache2.0/
import http from "k6/http";
import { check, sleep } from "k6";
export let options = {
stages: [
{ duration: "30s", target: 20 },
{ duration: "1m30s" },
{ duration: "30s", target: 0 },
]
};

Install k6

wget https://bintray.com/loadimpact/rpm/rpm -O bintray-loadimpact-rpm.repo
sudo mv bintray-loadimpact-rpm.repo /etc/yum.repos.d/
sudo yum install -y k6

k6 version

Install Graphana