Skip to content

Instantly share code, notes, and snippets.

💭
MWM seeking Casual code Encounters

Ben Tomasik tomislacker

💭
MWM seeking Casual code Encounters
Block or report user

Report or block tomislacker

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tomislacker
tomislacker / rateLimitDecorator.py
Created Jul 17, 2019 — forked from gregburek/rateLimitDecorator.py
Rate limiting function calls with Python Decorators
View rateLimitDecorator.py
import time
def RateLimited(maxPerSecond):
minInterval = 1.0 / float(maxPerSecond)
def decorate(func):
lastTimeCalled = [0.0]
def rateLimitedFunction(*args,**kargs):
elapsed = time.clock() - lastTimeCalled[0]
leftToWait = minInterval - elapsed
if leftToWait>0:
@tomislacker
tomislacker / output.md
Last active Jul 15, 2019
Python Nested Generators with `yield from` Syntax (>=Python.3.3)
View output.md

TIL about the yield from syntax introduced in >=Python-3.3

In [6]: def f1(p): 
   ...:     yield f'{p}1' 
   ...:     yield f'{p}2' 
   ...:      
   ...:                                                                         

In [7]: def f2(): 
@tomislacker
tomislacker / es_test.py
Created May 9, 2019
Test ElasticSearch Connectivity
View es_test.py
"""
Simple test for checking if an EC2 instance or ECS task can access an
ElasticSearch domain. This was mainly lifted from the AWS documentation:
https://docs.aws.amazon.com/elasticsearch-service/latest/developerguide/es-request-signing.html#es-request-signing-python
To use this, first the requisite libraries must be available:
$ pip install -U \
boto3 \
elasticsearch \
requests \
@tomislacker
tomislacker / about.md
Last active Apr 4, 2019
Python logging Module Not Showing All Levels
View about.md
  • Inspired by this gist.
  • Supporting documentation
  • I made a new gist because I wanted to have a more complete example that compared what happens without using that solution versus using it.
@tomislacker
tomislacker / aws_route53_delete.sh
Created Jan 15, 2019 — forked from earljon/aws_route53_delete.sh
Delete a Route 53 Record Set in AWS CLI
View aws_route53_delete.sh
#!/bin/sh
# NOTE:
# Make sure that the value of Name, Type, TTL are the same with your DNS Record Set
HOSTED_ZONE_ID=<YOUR_HOSTED_ZONE_ID>
RESOURCE_VALUE=<YOUR_DNS_RESOURCE_VALUE-ex:IP or dns>
DNS_NAME=<YOUR_DNS_NAME-ex: subdomain.domain.com>
RECORD_TYPE=<DNS_RECORD_TYPE-ex: A, CNAME>
TTL=<TTL_VALUE>
@tomislacker
tomislacker / all_aws_lambda_modules.txt
Created Oct 22, 2018 — forked from gene1wood/all_aws_lambda_modules_python.md
AWS Lambda function to list all available Python modules and post the list to Pastebin
View all_aws_lambda_modules.txt
# module list (generated by listmodules.py)
#
# timestamp='20160226T200954Z'
# sys.version='2.7.10 (default, Dec 8 2015, 18:25:23) \n[GCC 4.8.3 20140911 (Red Hat 4.8.3-9)]'
# sys.platform='linux2'
# platform='Linux-4.1.13-19.31.amzn1.x86_64-x86_64-with-glibc2.2.5'
#
BaseHTTPServer
Bastion
CDROM
@tomislacker
tomislacker / unused_security_groups.sh
Last active Jul 25, 2018
Find Unused Security Groups.sh
View unused_security_groups.sh
#!/bin/bash
find_all_groups ()
{
aws ec2 describe-security-groups \
--query 'SecurityGroups[*].GroupId' \
--output text \
| tr '\t' '\n' \
| sort -u
}
@tomislacker
tomislacker / vpc.ipynb
Created Jul 10, 2018
VPC Network Designer
View vpc.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View gist:60803e9e0082d05c431d117f897d89c6

How to create a publicly-accessible SNS topic that sends messages when objects are added to a public Amazon S3 bucket.

1. Create something within AWS that triggers notifications.

In this case, that's an S3 bucket that is continually updated by the addition of new sensor data. For the purposes of this tutorial, we’ll use s3://noaa-nexrad-level2 – one of our NEXRAD on AWS buckets – as an example.

2. Create an SNS topic and appropriate policy.

The SNS topic should be in the same region as the bucket. It will need to have a policy that allows our S3 bucket to publish to it, and anyone to subscribe to it using Lambda or SQS.

@tomislacker
tomislacker / elasticache_benchmarking.ipynb
Last active May 4, 2018
Benchmarking ElastiCache (Redis) Bandwidth Performance
View elasticache_benchmarking.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
You can’t perform that action at this time.