This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Example for how to return a https link to a GCS file that expires in {expiration} | |
seconds from now. | |
Receivers of the link do not need a Google account or any special access. | |
Dependencies: | |
pip install google-auth | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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'], | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Code goes along with the post made at: | |
* https://ls3.io/post/ship_cloudwatch_logs_to_logentries/ | |
*/ | |
package main | |
import ( | |
"encoding/json" | |
"fmt" | |
"strings" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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 = """ |
NewerOlder