Skip to content

Instantly share code, notes, and snippets.

@bryan-lott
bryan-lott / cloudwatch_export_all_logs_to_s3.py
Created July 28, 2020 21:04
Export all logs to s3 from cloudwatch over a date range
# requires https://pypi.org/project/retry for the create export
import boto3
from retry.api import retry_call
from_time: int = 0 # start time
to_time: int = 0 # end time
destination: str = '' # destination s3 bucket
destination_prefix: str = 'CloudWatchLogs' # key prefix inside the bucket
cw = boto3.client('logs')
@bryan-lott
bryan-lott / ecs_find_by_ip.py
Last active July 22, 2020 00:52
Search all of AWS ECS for Private IP Address
ip_address = '123.456.789.012'
import boto3
from pprint import pprint
ecs = boto3.client('ecs')
for cluster in ecs.list_clusters()['clusterArns']:
arns = ecs.list_tasks(cluster=cluster)['taskArns']
if arns:
for t in ecs.describe_tasks(cluster=cluster, tasks=arns)['tasks']:
for c in t['containers']:

Keybase proof

I hereby claim:

  • I am bryan-lott on github.
  • I am bryanlott (https://keybase.io/bryanlott) on keybase.
  • I have a public key whose fingerprint is 49F8 B969 D780 8AAF 9D4D 56EF 5F23 2B86 00FE 4BB5

To claim this, I am signing this object:

@bryan-lott
bryan-lott / move.py
Created July 13, 2018 15:42
Move files from one folder to another
import shutil
import os
src = 'source'
dst = 'destination'
for f in os.listdir(src):
shutil.move(os.path.join(src, f), dst)
@bryan-lott
bryan-lott / dict_map_bools_to_strings.py
Created February 28, 2018 21:41
python dict mapping bools to strings
bool_val = True
result = {True: 'IS', False: 'IS NOT'}[bool_val]
print("Mapping {} awesome".format(result))
DavidAnson.vscode-markdownlint-0.7.2
lei.theme-chromodynamics-1.0.8
HookyQR.beautify-1.0.2
lukehoban.go-0.6.61
PeterJausovec.vscode-docker-0.0.14
mohsen1.prettify-json-0.0.3
RoscoP.ActiveFileInStatusBar-1.0.2
ms-vscode.sublime-keybindings-2.0.1
Stephanvs.dot-0.0.1
mushan.vscode-open-iterm2-0.0.2
Parinfer
go-outline
multi-cursor
go-plus
nord-atom-syntax
Sublime-Style-Column-Selection
go-signature-statusbar
nord-atom-ui
ariake-dark-syntax
highlight-line
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="""
I never freaking remember argparse syntax and the docs are so all over the place
that I need this for an example.
@bryan-lott
bryan-lott / redshift_example_using_psycopg2.py
Created October 27, 2015 17:54
Example on how to connect to redshift using psycopg2
__author__ = 'fbaldo'
import psycopg2
import pprint
configuration = { 'dbname': 'database_name',
'user':'user_name',
'pwd':'user_password',
'host':'redshift_endpoint',
#List unique values in a DataFrame column
pd.unique(df.column_name.ravel())
#Convert Series datatype to numeric, getting rid of any non-numeric values
df['col'] = df['col'].astype(str).convert_objects(convert_numeric=True)
#Grab DataFrame rows where column has certain values
valuelist = ['value1', 'value2', 'value3']
df = df[df.column.isin(value_list)]