Skip to content

Instantly share code, notes, and snippets.

@mrichman
mrichman / main.go
Last active Jul 19, 2020
Invoking AWS SDK using WaitGroup of configurable size
View main.go
// Run N workers in a WaitGroup until they complete
package main
import (
"flag"
"fmt"
"os"
"sync"
@mrichman
mrichman / Cloud9_bootstrap.yaml
Created Jul 8, 2020 — forked from richardhboyd/Cloud9_bootstrap.yaml
StepFunction that bootstraps a Cloud9 environment
View Cloud9_bootstrap.yaml
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Parameters:
BucketName:
Description: "Region-specific assets S3 bucket name (e.g. ee-assets-prod-us-east-1)"
Type: String
Default: "cf-templates-1xnac3rwgtxo7-us-west-2"
EBSVolumeSize:
Description: "Size of EBS Volume (in GB)"
Type: Number
@mrichman
mrichman / HelloWorld.vue
Last active Jan 2, 2021
Cognito Hosted UI + Vue.js
View HelloWorld.vue
<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 / table.js
Created Jan 30, 2020
Sort any HTML table by clicking a header
View table.js
const getCellValue = (tr, idx) => tr.children[idx].innerText || tr.children[idx].textContent;
const comparer = (idx, asc) => (a, b) => ((v1, v2) =>
v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2)
)(getCellValue(asc ? a : b, idx), getCellValue(asc ? b : a, idx));
// do the work...
document.querySelectorAll('th').forEach(th => th.addEventListener('click', (() => {
const table = th.closest('table');
Array.from(table.querySelectorAll('tr:nth-child(n+2)'))
.sort(comparer(Array.from(th.parentNode.children).indexOf(th), this.asc = !this.asc))
.forEach(tr => table.appendChild(tr) );
@mrichman
mrichman / simple-https-server.py
Created Oct 25, 2019
Simple HTTPS Server in Python
View simple-https-server.py
#!/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 / lambda_function.py
Created Apr 11, 2019
Blog Post: Scheduling DynamoDB Backups with Lambda, Python, and Boto3
View lambda_function.py
import datetime
import boto3
MAX_BACKUPS = 3
dynamo = boto3.client('dynamodb')
def lambda_handler(event, context):
@mrichman
mrichman / Brewfile
Created Mar 25, 2019
brew bundle dump
View Brewfile
tap "aws/tap"
tap "buo/cask-upgrade"
tap "cjbassi/gotop"
tap "garethr/kubeval"
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/cask-fonts"
tap "homebrew/cask-versions"
tap "homebrew/core"
tap "homebrew/services"
@mrichman
mrichman / create-params.py
Created Oct 31, 2018
Lambda Function to Create SSM Parameters using SecureString
View create-params.py
import boto3
import json
from botocore.vendored import requests
def lambda_handler(event, context):
kms_client = boto3.client('kms')
ssm_client = boto3.client('ssm')
@mrichman
mrichman / main.go
Created Jul 17, 2018
Beat up your CPU for 10 seconds
View main.go
package main
import (
"runtime"
"time"
)
func main() {
n := runtime.NumCPU()
runtime.GOMAXPROCS(n)