Skip to content

Instantly share code, notes, and snippets.

View alanyee's full-sized avatar

Alan Yee alanyee

View GitHub Profile
@alanyee
alanyee / tail.py
Last active July 7, 2022 07:34
Boto3 Tail AWS Cloudwatch Logs
"""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 October 5, 2020 18:21
Find the current Kali Linux AMI
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 March 3, 2020 04:48
Maxheap version of heapq.py for safe keeping
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 October 21, 2019 02:40
Suppress help from usage statement
import argparse
parser = argparse.ArgumentParser(prog='PROG', add_help=False)
parser.add_argument('--help', '-h', action='help', help=argparse.SUPPRESS)
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 January 11, 2016 08:49
Proving my GitHub identity for Keybase

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: