Skip to content

Instantly share code, notes, and snippets.

Sam Cook SamLR

Block or report user

Report or block SamLR

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
@SamLR
SamLR / copier.py
Created Sep 1, 2019
Clone an org's public repos to another org.
View copier.py
import os
import json
import time
from datetime import datetime
from github import (
Github, UnknownObjectException, GithubException, RateLimitExceededException
)
RATE_LIMIT_COUNT = 0
View forker.py
from github import Github, GithubException
import json
from datetime import datetime
import os
def main(token):
g = Github(token)
alphagov = g.get_organization('alphagov')
View fork-it-all.sh
cat repos.json | \
jq '.[]|.full_name' | \
xargs -I REPO
curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: token ${GITHUB_TOKEN}" \
-d '{"organization": "alphagov-mirror"}' \
https://api.github.com/repos/REPO/forks
View grabbing-gov-uk.sh
# Step 1
curl -v https://api.github.com/orgs/alphagov/repos
# Copy the 'rel="last"' value from this section
# < Link: <https://api.github.com/organizations/596977/repos?page=2>; rel="next", <https://api.github.com/organizations/596977/repos?page=44>; rel="last"
# i.e. '44'
for i in {1..44}; do curl "https://api.github.com/organizations/596977/repos?page=$i" >> repos.json; done
cat repos.json| jq '.[]|.html_url' -r | xargs -I REPO git clone REPO && sleep 1
@SamLR
SamLR / security-group-updater.py
Created Jul 12, 2019
Add a new CIDR to inbound connections for security groups that already permit another, specific, CIDR
View security-group-updater.py
#
# Find all the security groups that use a particular CIDR_TO_FIND and update
# them with a new ingress rule allowing access from CIDR on ports 0->65535
#
# DESCRIPTION can also be set to describe the new rule.
#
# If DRY_RUN is set to true the security groups will be searched for but not
# updated.
#
@SamLR
SamLR / aws-user-group-crawler.py
Created May 23, 2019
Crawl your users and find which groups they're in; crawl your groups and find their users!
View aws-user-group-crawler.py
#
# example usage
# # Get the data:
# $ python3 aws-iam-crawl.py > iam.json
#
# # Group summary
# $ cat iam.json| jq '.groups | map({"members": (._users|length), "policies": ((._inline_policies|length) + (._attached_policies|length)), "inline_policies": (._inline_policies|length), "name": .GroupName}) | sort_by(.members)[] ' -c
#
# # User summary (basically the same)
# $ cat iam.json| jq '.users | map({"groups": (._groups|length), "policies": ((._inline_policies|length) + (._attached_policies|length)), "inline_policies": (._inline_policies|length), "name": .UserName}) | sort_by(.groups)[] ' -c
@SamLR
SamLR / aws-action-test.py
Last active May 23, 2019
Find out which roles/groups or users can perform an action
View aws-action-test.py
#
# Recommended use
# python3 aws-action-test.py ec2:create-instance > arns.json
#
# This is pretty slow but I think it hits most main things in AWS
#
import boto3
from sys import argv
View aws-vpc-crawler.py
import boto3
from sys import argv
def get_name(aws_obj):
names = list(tag['Value'] for tag in aws_obj['Tags'] if tag['Key'] == 'Name')
if len(names) != 1:
# print('No name for object: {}'.format(aws_obj))
return '--unknown--'
@SamLR
SamLR / Results
Created Jan 1, 2016
Quick analysis of EMF 2014 talks
View Results
Total Entries = 184
Errors = 20
Used Entries = 164
Min = 15 min
Max = 180 min
Average = 52 min
----------------------------------------
Duration (min) | Count
30 | 48
60 | 38
View keybase.md

Keybase proof

I hereby claim:

  • I am samlr on github.
  • I am samlr (https://keybase.io/samlr) on keybase.
  • I have a public key whose fingerprint is C7F7 D4E0 1FDC 012F BFF4 2748 448D 8B1B CC81 A873

To claim this, I am signing this object:

You can’t perform that action at this time.