Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mrichman's full-sized avatar

Mark Richman mrichman

View GitHub Profile
@mrichman
mrichman / osx_bootstrap.sh
Last active February 5, 2024 13:38
Bootstrap script for setting up a new OSX machine
#!/usr/bin/env bash
#
# Bootstrap script for setting up a new OSX machine
#
# This should be idempotent so it can be run multiple times.
#
# Some apps don't have a cask and so still need to be installed by hand. These
# include:
#
# - Twitter (app store)
@mrichman
mrichman / simple-https-server.py
Created October 25, 2019 11:55
Simple HTTPS Server in Python
#!/usr/bin/env python3
"""
generate server.pem:
openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
"""
from http.server import HTTPServer, SimpleHTTPRequestHandler
import ssl
@mrichman
mrichman / cognito.yaml
Created August 12, 2023 02:04 — forked from singledigit/cognito.yaml
Create a Cognito Authentication Backend via CloudFormation
AWSTemplateFormatVersion: '2010-09-09'
Description: Cognito Stack
Parameters:
AuthName:
Type: String
Description: Unique Auth Name for Cognito Resources
Resources:
# Creates a role that allows Cognito to send SNS messages
SNSRole:
@mrichman
mrichman / app.config.xml
Last active January 27, 2023 10:08
Enable WCF Service Trace Logging - view with SvcTraceViwer.exe (i.e. C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!-- ... -->
<system.serviceModel>
<!-- ... -->
<diagnostics wmiProviderEnabled="true">
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" maxMessagesToLog="3000" />
</diagnostics>
</system.serviceModel>
<!-- ... -->
@mrichman
mrichman / HelloWorld.vue
Last active January 16, 2023 13:11
Cognito Hosted UI + Vue.js
<template>
<div>
<b-container>
<b-row align-h="center">
<div v-if="!signedIn">
<b-button variant="success" @click="signIn">Sign in with Cognito</b-button>
</div>
<div v-if="signedIn">
<h4>Welcome, {{ username }}!</h4>
<b-button variant="danger" @click="signOut">Sign out</b-button>
@mrichman
mrichman / lambda_function.py
Created April 11, 2019 18:14
Blog Post: Scheduling DynamoDB Backups with Lambda, Python, and Boto3
import datetime
import boto3
MAX_BACKUPS = 3
dynamo = boto3.client('dynamodb')
def lambda_handler(event, context):
@mrichman
mrichman / screenshot.py
Created February 16, 2017 15:44
Download a website screenshot using Google's PageSpeed API
#!/bin/env python
""" Download a website screenshot using Google's PageSpeed API """
import base64
import requests
site = "https://twitter.com/mrichman"
# api = "https://www.googleapis.com/pagespeedonline/v1/runPagespeed?screenshot=true&strategy=mobile"
@mrichman
mrichman / main.go
Last active December 28, 2021 08:20
AWS Lambda function in Go to resize an image uploaded to S3. Uses https://github.com/apex/apex
package main
import (
"bytes"
"image/jpeg"
"log"
"path"
"strings"
apex "github.com/apex/go-apex"
@mrichman
mrichman / resize.sh
Created May 28, 2021 18:49
Resize EC2 volume
#!/bin/bash
# Specify the desired volume size in GiB as a command-line argument. If not specified, default to 20 GiB.
SIZE=${1:-20}
# Get the ID of the environment host Amazon EC2 instance.
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
# Get the ID of the Amazon EBS volume associated with the instance.
VOLUMEID=$(aws ec2 describe-instances \
@mrichman
mrichman / rds-init.sh
Created March 31, 2021 11:07 — forked from sivasamysubramaniam/rds-init.sh
A workaround to get all data loaded into AWS RDS MySQL. When a read replica is restored from a snapshot, the replica won't wait for all the data to be transferred from Amazon Simple Storage Service (Amazon S3) to the Amazon Elastic Block Store (Amazon EBS) volume that's associated with the replica DB instance. The replica DB instance is availabl…
#!/bin/bash
host=$1
user=$2
password=$3
echo '' > $0.queue
databases=$(mysql -h $host -u $user -p$password -e "show databases" -sN | grep -v information_schema | grep -v mysql | grep -v sys)
for database in $databases; do
for table in $(mysql -h $host -u $user -p"$password" -N -B -e "show tables from \`$database\`"); do