Skip to content

Instantly share code, notes, and snippets.

View LyleScott's full-sized avatar

Lyle Scott III LyleScott

View GitHub Profile
import aiohttp
def request_tracer(results_collector):
async def on_request_start(session, context, params):
context.on_request_start = session.loop.time()
context.is_redirect = False
async def on_request_end(session, context, params):
total = session.loop.time() - context.on_request_start
@LyleScott
LyleScott / us_region_state_map.py
Created March 24, 2021 16:27
US States by Region (organized by Census Bureau)
# I needed these for something and had to manually create it. Hope this helps someone.
# Reference: https://en.wikipedia.org/wiki/List_of_regions_of_the_United_States
US_REGION_STATE_MAP = {
"northeast": ['CT', 'MA', 'ME', 'NH', 'NJ', 'NY', 'PA', 'RI', 'VT'],
"midwest": ['IA', 'IL', 'IN', 'KS', 'MI', 'MN', 'MO', 'ND', 'NE', 'OH', 'SD', 'WI'],
"south": ['AL', 'AR', 'DC', 'DE', 'FL', 'GA', 'KY', 'LA', 'MD', 'MS', 'NC', 'OK', 'SC', 'TN', 'TX', 'VA', 'WV'],
"west": ['AZ', 'CA', 'CO', 'ID', 'MT', 'NM', 'NV', 'OR', 'UT', 'WA', 'WY'],
}
@LyleScott
LyleScott / create_readonly_user.sql
Last active September 14, 2022 19:33
Create a read only role in Snowflake
-- create the read-only role.
create role if not exists YOUR_ROLE_NAME;
-- allow the role to access a specific warehouse
grant usage on warehouse YOUR_WAREHOUSE_NAME to role YOUR_ROLE_NAME;
-- allow the role to access a specific schema (most likely public?)
//grant usage on all schemas in database YOUR_DATABASE_NAME to role YOUR_ROLE_NAME;
grant usage on schema PUBLIC to role YOUR_ROLE_NAME;
@LyleScott
LyleScott / snowflake_drop_tables_workaround.sql
Created February 28, 2020 16:11
Snowflake DELETE TABLE LIKE workaround
SELECT CONCAT('DROP TABLE ', table_name, ' ;')
FROM your_database_name.information_schema.tables
WHERE table_name like '%_STAGING';
-- 1) Then, click “COPY” to get the TSV results.
-- 2) Paste all those commands to a Snowflake worksheet
-- 3) Review carefully
-- 4) Select all DELETE queries and execute the query
@LyleScott
LyleScott / venvs.py
Last active June 25, 2019 13:14
A little Python 3.x script i wrote to help me manage local virtual environments
#!/usr/bin/env python3
"""
A custom utility to manage Python virtualenvs. Requires Python 3.6+
I've written it mainly as a wrapper around venv, but it's pluggable.
https://ls3.io // lyle@ls3.io // https://www.linkedin.com/in/lylescott
USAGE
venvs.py list [-r]
@LyleScott
LyleScott / rm_empty_s3_buckets.py
Created April 5, 2018 03:31
Find all S3 buckets that are empty and prompt to delete them
#!/usr/bin/env python3
"""
Lyle Scott, III // lyle@ls3.io
$ python3 rm_empty_s3_buckets.py --help
usage: rm_empty_s3_buckets.py [-h] [-p PROFILE]
optional arguments:
-h, --help show this help message and exit
-p PROFILE, --profile PROFILE
@LyleScott
LyleScott / formation.yml
Last active August 31, 2019 04:41
Example Cloud Formation template to create a Logentries shipper Lambda and a Lambda that will generate test log messages
#
# Code goes along with the post made at:
# https://ls3.io/post/ship_cloudwatch_logs_to_logentries/
#
AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Specification for shipping CloudWatch logs to Logentries.
Resources:
# A generic Lambda role that allows execution and Cloud Watch logs.
@LyleScott
LyleScott / main.go
Last active April 8, 2018 02:35
Lambda Go code to ship Log Group subscription events to Logentries
/*
* Code goes along with the post made at:
* https://ls3.io/post/ship_cloudwatch_logs_to_logentries/
*/
package main
import (
"encoding/json"
"fmt"
"strings"
@LyleScott
LyleScott / rotate_2d_point_timers.py
Last active October 31, 2018 09:52
Timers for a few ways to rotate a 2d point around another point in Python
"""
Lyle Scott, III // lyle@ls3.io
Python execution timers for https://gist.github.com/LyleScott/e36e08bfb23b1f87af68c9051f985302
"""
from __future__ import print_function
import timeit
# Setup steps that aren't timed.
setup = """