Skip to content

Instantly share code, notes, and snippets.

View metaskills's full-sized avatar
🐙
Being Inkcellent to Each Other

Ken Collins metaskills

🐙
Being Inkcellent to Each Other
View GitHub Profile
@metaskills
metaskills / layer_downloader.rb
Created July 25, 2020 02:55
Useful for Ruby/Docker SAM Projects
require 'yaml'
require 'open-uri'
require 'aws-sdk-lambda'
class LayerDownloader
def download
File.open(zip_file, 'wb') do |f|
URI.open(location) { |zip| f.write(zip.read) }
end
@metaskills
metaskills / event.json
Created June 16, 2020 13:26
Sample API Gateway HTTP API Version 1 Event
{
"version": "1.0",
"resource": "$default",
"path": "/",
"httpMethod": "GET",
"headers": {
"Content-Length": "0",
"Host": "myawesomelambda.example.com",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Safari/605.1.15",
"X-Amzn-Trace-Id": "Root=1-5e7fe714-fee6909429159440eb352c40",
@metaskills
metaskills / aurora-stack.ts
Last active June 7, 2020 13:36
Aurora Serverless IaC Example Using CDK & TypeScript
// Run `mkdir aurora && cd aurora && cdk init sample-app --language=typescript`
// and replace the `lib/aurora-stack.ts` with this file. May need to remove non-needed
// packages from package.json and add others like "@aws-cdk/aws-rds" and
// "@aws-cdk/aws-secretsmanager"
//
// Running assumes you pass in the following environment variables or hard code values.
//
// * ASCLUSTER_MASTER_USER
// * ASCLUSTER_MASTER_PASS
// * SUBNET_GROUP_NAME
@metaskills
metaskills / wizard.sh
Last active May 10, 2020 13:08
Learning to Program The Cloud
insert_file_over_pattern () {
dline=$(sed -n "/${2}/=" $1)
rline=$(expr $dline - 1)
sed --in-place -e "${dline}d" $1
sed --in-place "${rline}r ../inserts/${1}" $1
}
insert_file_over_pattern 'config/application.rb' 'Bundler.require'
@metaskills
metaskills / jest-environment-samlocal.js
Created April 25, 2020 14:29
Using Jest SAM Local Environment
const { spawn } = require('child_process');
const NodeEnvironment = require('jest-environment-node');
const { timeout, TimeoutError } = require('promise-timeout');
class SamlocalEnvironment extends NodeEnvironment {
constructor(config) {
super(config);
}
async setup() {
@metaskills
metaskills / event-data.md
Last active March 26, 2020 16:23
Query Strings Event Values w/Lambda Integration using API Gateway (REST & HTTP API) & Application Load Balancers

This solely tests array query string values since I find these the most interesting edge case. So the query string would be colors[]=blue&colors[]=red for all cases below.

API Gateway HTTP API (version 2.0)

"rawQueryString": "colors[]=blue&colors[]=red",
"queryStringParameters": { "colors[]": "blue,red" }

API Gateway HTTP API (version 1.0)

@metaskills
metaskills / deploy.sh
Created April 30, 2019 02:44
Cross-Region Replication S3 Buckets - Single CloudFormation Template.
aws cloudformation deploy \
--region ${AWS_DEFAULT_REGION} \
--template-file "template.yaml" \
--stack-name "my-buckets-${RAILS_ENV}" \
--s3-bucket "$CLOUDFORMATION_BUCKET" \
--s3-prefix "my-buckets-${RAILS_ENV}" \
--capabilities "CAPABILITY_IAM" \
--tags \
"env=${STAGE_ENV}" \
"group=ecommerce" \
@metaskills
metaskills / gist:3752c66ed2b50599e4b66b7664f1d856
Created December 28, 2019 23:11
ActiveRecord Aurora Serverless - Foreign Key Check Debugging
EXECUTE: SELECT 1 70195508832200
EXECUTE: SELECT @@FOREIGN_KEY_CHECKS 70195508832200
(26.8ms) SELECT @@FOREIGN_KEY_CHECKS
EXECUTE: SET FOREIGN_KEY_CHECKS = 0 70195508832200
(26.3ms) SET FOREIGN_KEY_CHECKS = 0
BEGIN AXicEuEN5ZSHrKMjPizpveE6eyVxSEAFGWl7G4+IL5btSET5zr1f99MtCpfIr0d7nPp3gXTUyMmuo5lVen73a8FDDAZvwQPZL6AQCIs851e1jczSJEOQjPo/ZIAG2tveP2YSzlmhWGPZrmmBRZhjBi5KA8z3wZ1Ma4FJ8KcBtvNtu3nq/TV0cj0= 70195508832200
EXECUTE: DELETE FROM `topics` AXicEuEN5ZSHrKMjPizpveE6eyVxSEAFGWl7G4+IL5btSET5zr1f99MtCpfIr0d7nPp3gXTUyMmuo5lVen73a8FDDAZvwQPZL6AQCIs851e1jczSJEOQjPo/ZIAG2tveP2YSzlmhWGPZrmmBRZhjBi5KA8z3wZ1Ma4FJ8KcBtvNtu3nq/TV0cj0= 70195508832200
Fixtures Load (27.2ms) DELETE FROM `topics`
EXECUTE: DELETE FROM `developers` AXicEuEN5ZSHrKMjPizpveE6eyVxSEAFGWl7G4+IL5btSET5zr1f99MtCpfIr0d7nPp3gXTUyMmuo5lVen73a8FDDAZvwQPZL6AQCIs851e1jczSJEOQjPo/ZIAG2tveP2YSzlmhWGPZrmmBRZhjBi5KA8z3wZ1Ma4FJ8KcBtvNtu3nq/TV0cj0= 70195508832200
Fixtures Load (27.7ms) DELETE FROM `developers`
class Numeric
def negative
if self <= 0
self
else
self * -1
end
end
end
@metaskills
metaskills / gist:2836849
Created May 30, 2012 14:58
Basic Save & Open Page For Poltergeist
def save_and_open_page
dir = "#{Rails.root}/tmp/cache/capybara"
file = "#{dir}/#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}.png"
FileUtils.mkdir_p dir
page.driver.render file
wait_until { File.exists?(file) }
system "open #{file}"
end