Skip to content

Instantly share code, notes, and snippets.

Avatar

Alan Yee alanyee

View GitHub Profile
@alanyee
alanyee / tail.py
Last active Jan 7, 2021
Boto3 Tail AWS Cloudwatch Logs
View tail.py
"""Using boto3, instead of awscli, to tail logs. Based on https://github.com/aws/aws-cli/blob/v2/awscli/customizations/logs/tail.py"""
from collections import defaultdict
import sys
import time
import boto3
from botocore.exceptions import ClientError, ParamValidationError
SLEEP = 5
@alanyee
alanyee / kali_aws.sh
Created Oct 5, 2020
Find the current Kali Linux AMI
View kali_aws.sh
aws ec2 describe-images \
--owners 679593333241 \
--filters 'Name=name,Values=Kali*' 'Name=state,Values=available' \
--query 'reverse(sort_by(Images, &CreationDate))[:1].ImageId' \
--output text
@alanyee
alanyee / heapq_max.py
Last active Mar 3, 2020
Maxheap version of heapq.py for safe keeping
View heapq_max.py
def _siftdown_max(heap, startpos, pos):
'Maxheap variant of _siftdown'
newitem = heap[pos]
# Follow the path to the root, moving parents down until finding a place
# newitem fits.
while pos > startpos:
parentpos = (pos - 1) >> 1
parent = heap[parentpos]
if parent < newitem:
heap[pos] = parent
@alanyee
alanyee / argparse_help.py
Created Oct 21, 2019
Suppress help from usage statement
View argparse_help.py
import argparse
parser = argparse.ArgumentParser(prog='PROG', add_help=False)
parser.add_argument('--help', '-h', action='help', help=argparse.SUPPRESS)
View groupby.py
from functools import partial
def iseven(n, d=2):
"""Example"""
return n % d == 0
def groupby(key, seq):
"""Based on toolz groupby"""
result = defaultdict(list)
for item in seq:
@alanyee
alanyee / keybase.md
Created Jan 11, 2016
Proving my GitHub identity for Keybase
View keybase.md

Keybase proof

I hereby claim:

  • I am alanyee on github.
  • I am alyee (https://keybase.io/alyee) on keybase.
  • I have a public key whose fingerprint is 9F7E F201 F155 949E 91CF C0F9 8567 AADE BD3D 9319

To claim this, I am signing this object: