Skip to content

Instantly share code, notes, and snippets.

View deybhayden's full-sized avatar
🧠
Thinking

Ben Hayden deybhayden

🧠
Thinking
View GitHub Profile
@deybhayden
deybhayden / get_ip.py
Created October 20, 2023 15:37
Get current outbound IP in Python
import re
from urllib.request import urlopen
def get_ip():
d = str(urlopen("http://checkip.dyndns.com/").read())
re_srch = re.compile(r"Address: (\d+\.\d+\.\d+\.\d+)").search(d)
if re_srch:
return re_srch.group(1)
@deybhayden
deybhayden / lambda_event_types.py
Created December 8, 2022 22:46
AWS Lambda Event Trigger Types
from typing import TypedDict, Union
# AWS Lambda Event Types
class ApiGatewayEvent(TypedDict):
requestContext: dict[str, str]
queryStringParameters: Union[dict[str, str], None]
body: str
#!/usr/bin/env bash
LOG_GROUP_NAME=${1:?log group name is not set}
echo Getting stream names...
LOG_STREAMS=$(
aws logs describe-log-streams \
--log-group-name ${LOG_GROUP_NAME} \
--query 'logStreams[*].logStreamName' \
--output table |
@deybhayden
deybhayden / install-clamav-osx.md
Created October 24, 2022 15:44 — forked from gagarine/install-clamav-osx.md
Howto Install clamav on OSX with brew

Howto Install clamav on OSX with brew

$ brew install clamav
$ cd /usr/local/etc/clamav
$ cp freshclam.conf.sample freshclam.conf

Open freshclam.conf and comment the "Example" (in new version it may be "FooClam") line:

Keybase proof

I hereby claim:

  • I am deybhayden on github.
  • I am deybhayden (https://keybase.io/deybhayden) on keybase.
  • I have a public key ASBo32hDq6du-LSrcRR1idmtWdqDINjV7sbbi1pB6tJEKQo

To claim this, I am signing this object:

@deybhayden
deybhayden / convert_ics_timezone.py
Created March 5, 2012 19:45
Convert iCalendar File (.ics) to new Timezone
#!/usr/bin/env python
"""
Simple script that updates all events in an ical file to a new timezone.
Requires icalendar package (which pulls in pytz as a dependency).
By: @beardedprojamz (Ben Hayden)
"""
import argparse
import sys
@deybhayden
deybhayden / count.sh
Last active May 11, 2018 20:26
Function to count lines of code in a passed file type
# Function to count lines of code in a passed file type
# use git ls-files to ignore any of the same file type passed in that we don't care about
count() {
git ls-files "*.$1" "**/*.$1" | xargs grep -H -c '[^[:space:]]' | sort -nr -t":" -k2 | less
}
@deybhayden
deybhayden / cleanup.py
Last active February 12, 2018 21:56
AWS SSM Document for performing Consistent Snapshots
"""
Deletes old EC2 Snapshots created from the ConsistentSnapshot AWS RunCommand.
"""
import re
from datetime import datetime
from collections import defaultdict
from operator import itemgetter
import boto3
@deybhayden
deybhayden / decode_sts.sh
Last active January 17, 2018 18:43
decode_sts.sh
sts-decode() {
aws sts decode-authorization-message --encoded-message "$1" | jq '.DecodedMessage | fromjson'
}
@deybhayden
deybhayden / post-mortem.md
Created August 29, 2017 18:28 — forked from joewiz/post-mortem.md
Recovery from nginx "Too many open files" error on Amazon AWS Linux

On Tue Oct 27, 2015, history.state.gov began buckling under load, intermittently issuing 500 errors. Nginx's error log was sprinkled with the following errors:

2015/10/27 21:48:36 [crit] 2475#0: accept4() failed (24: Too many open files) 2015/10/27 21:48:36 [alert] 2475#0: *7163915 socket() failed (24: Too many open files) while connecting to upstream...

An article at http://www.cyberciti.biz/faq/linux-unix-nginx-too-many-open-files/ provided directions that mostly worked. Below are the steps we followed. The steps that diverged from the article's directions are marked with an *.

    • Instead of using su to run ulimit on the nginx account, use ps aux | grep nginx to locate nginx's process IDs. Then query each process's file handle limits using cat /proc/pid/limits (where pid is the process id retrieved from ps). (Note: sudo may be necessary on your system for the cat command here, depending on your system.)
  1. Added fs.file-max = 70000 to /etc/sysctl.conf
  2. Added `nginx soft nofile 1