Skip to content

Instantly share code, notes, and snippets.

View chris's full-sized avatar
🏠
Working from home

Chris Bailey chris

🏠
Working from home
View GitHub Profile
@chris
chris / cognito-paginator.go
Last active April 15, 2024 22:10
Basic AWS API Pagination example (with Cognito)
import (
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider/types"
)
// create the AWS client - uses environment/profile for values
cognitoidentityprovider.NewFromConfig(config.LoadDefaultConfig(context.Background()))
@chris
chris / myauthorizer.go
Created June 4, 2021 19:23
Example of an API Gateway Lambda authorizer
package main
import (
"context"
"errors"
"regexp"
"strings"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
@chris
chris / mysql_ip_address_info.sql
Last active February 22, 2024 05:49
Get list of IP addresses connected to MySQL DB, with their connection counts
SELECT
tmp.ipAddress,
-- Calculate how many connections are being held by this IP address.
COUNT( * ) AS numConnections,
-- For each connection, the TIME column represent how many SECONDS it has been in
-- its current state. Running some aggregates will give us a fuzzy picture of what
-- the connections from this IP address is doing.
FLOOR( AVG( tmp.time ) ) AS timeAVG,
@chris
chris / s3-cloudfront-route53.yml
Last active February 17, 2024 21:33
S3 CloudFront Custom Domain CloudFormation example
#
# S3 bucket for a web files, with CloudFront and custom domain.
#
# The bucket is setup to be private, only accessible via CloudFront.
# This uses a CloudFront OAI to provide access to the bucket, and also restricts
# access to be SSL/HTTPS only.
# The SSL cert was created manually, as it has to be created in us-east-1 for
# use with CloudFront, and there is no way to specify a region in CloudFormation
# when creating a cert.
# Finally it does Route53 DNS setup for the subdomain pointed at/for use with
@chris
chris / topfuel_wheel_comparison.csv
Last active April 2, 2023 08:00
Comparison of weight and cost of change in wheels on my Top Fuel
Item Weight Cost
Bontrager Line Elite 30 1890g $1000
CushCore Pro 29 530g $150
Bontrager XR4 2.4 tire 800g $70
Bontrager XR3 2.4 tire 755g $70
TOTAL 3975g $1290 - $0.32/gram
---- ---- ----
Reserve 30 SL w/ I9 hubs 1723g $1900 ($1615)
Tubolight HD 180g $96
Kenda Booster SCT 2.4 tire 690g $75
@chris
chris / action-postgis.yml
Created July 7, 2020 20:10
GitHub Actions Postgres PostGIS service
services:
postgres:
image: postgis/postgis:10-2.5
env:
# must specify password for PG Docker container image, see: https://registry.hub.docker.com/_/postgres?tab=description&page=1&name=10
POSTGRES_PASSWORD: password
POSTGRES_DB: your_test_db_name
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
@chris
chris / ddbstreamprocessor.go
Last active January 12, 2023 02:34
DynamoDB streams lambda trigger handler in Go
package main
import (
"context"
"log"
"os"
"strings"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
@chris
chris / tiled_raster_import.sh
Created January 10, 2023 20:20
Script to import large raster data set in chunks via VRT files.
#!/bin/bash
#
# Script to produce tiled raster import of a large data source, so that we can
# import in chunks, and be able to handle failures. This takes the lat/long
# mins and maxes for a rectangular area, and a VRT tile size and produces VRTs
# for each tile. It also outputs a shell script to import those VRTs along with
# outputting the last "rid" (raster ID in DB) after completing a tile, so that
# if it fails, we know the items to delete (so we can restart the failed tile,
# and not have duplicate records from what was partially imported).
#
@chris
chris / cognito.yml
Created May 21, 2021 17:31
Cognito user pool setup for Serverless (as CloudFormation resource)
#
# Cognito user pool/auth setup
#
Resources:
MyAppUserPool:
Type: AWS::Cognito::UserPool
Properties:
UserPoolName: myapp_user_pool
UsernameAttributes: # use email as username/login
- 'email'
@chris
chris / apigateway-dynamo_serverless.yml
Last active December 17, 2021 05:14
Serverless Framework config file for creating API Gateway to DynamoDB proxy
service: my-api
org: CompanyName
# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"
frameworkVersion: '>=2.1.1 <3.0.0'
custom:
defaultStage: dev