Skip to content

Instantly share code, notes, and snippets.

View pacohope's full-sized avatar

Paco Hope pacohope

View GitHub Profile
@pacohope
pacohope / keybase.md
Created January 13, 2015 10:55
My Keybase Verification

Keybase proof

I hereby claim:

  • I am pacohope on github.
  • I am pacohope (https://keybase.io/pacohope) on keybase.
  • I have a public key whose fingerprint is 97BE DA24 3F14 E0FA 0D43 07AB 695A 1FCB A0B6 2312

To claim this, I am signing this object:

# -*- coding: utf-8 -*-
import click
import os
import pandas as pd
def file_split(file):
s = file.split('.')
name = '.'.join(s[:-1]) # get directory name
@pacohope
pacohope / import-keypairs-all.sh
Last active June 28, 2017 11:01
Import a ssh keypair into EC2 in all AWS regions
#!/bin/bash
# I use an "Admin" profile that has all EC2 permissions
AWSPROFILE="Admin"
KEYNAME="my-aws-key"
KEYFILE="file:///Users/paco/.ssh/foo.pem"
# Create foo.pem via:
# sshkeygen -f /Users/paco/.ssh/foo.pub -e > /Users/paco/.ssh/foo.pem
# use ec2 describe-regions to get the official, up-to-the-minute region list.
REGIONS=$(aws ec2 describe-regions | jq -r '.Regions[].RegionName')
@pacohope
pacohope / glacier-notify.sh
Created July 6, 2017 09:55
Set SNS notifications for all Glacier vaults
#!/bin/bash
#
# Set notifications for all my vaults on the same SNS topic.
# Set Variables up top. The rest flows through.
# See Also: http://docs.aws.amazon.com/amazonglacier/latest/dev/configuring-notifications-console.html
# Set these four
REGION="eu-west-1"
PROFILE="MYPROFILE"
@pacohope
pacohope / ec2-ami-region-map.py
Last active September 23, 2019 15:33
Given a starting public AWS AMI, generate a YAML list of AMI IDs for that AMI in all AWS regions.
#
# Given the ID of an Amazon public AMI in one region, figure out what the
# equivalent AMI IDs are for that same AMI in all other regions known.
# If that AMI isn't defined in a region, it prints the region's name, but
# comments it out.
#
from __future__ import print_function
import boto3
@pacohope
pacohope / policy-role.jq
Last active November 1, 2017 17:01
Policy to Role listing. Given a CloudFormation in JSON that has ManagedPolicy objects connected to Roles, print a list of the policies and the roles that are attached.
def mapper(f):
if type == "array" then map(f)
elif type == "object" then
. as $in
| reduce keys[] as $key
({};
[$in[$key] | f ] as $value
| if $value | length == 0 then . else . + {($key): $value[0]}
end)
else .
@pacohope
pacohope / bucket-exclusive.json
Last active December 10, 2017 00:46
S3 bucket restriction. Enable get/put on one bucket, but deny explicitly everything else
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowAllBasics",
"Effect": "Allow",
"Action": [
"s3:ListAllMyBuckets",
"s3:HeadBucket",
"s3:ListObjects"
@pacohope
pacohope / termcolours.sh
Last active May 27, 2018 17:02
Print out all the possible ANSI terminal colours in a nice table.
#!/bin/zsh
#
# I hate doing this. This is someone else's code. For a long time I didn't know who to credit. Now
# I do: https://stackoverflow.com/questions/27159322/rgb-values-of-the-colors-in-the-ansi-extended-colors-index-17-255
# It is by a user named adaephon (https://stackoverflow.com/users/2992551/adaephon)
#
function termcolors ()
{
print TERM
print -P "Foreground: >█<"
@pacohope
pacohope / tight-bucket-policy.json
Created January 15, 2018 15:12
Very tightly locked down S3 bucket policy. IP address restriction. Encryption required. Public objects denied.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyUnencryptedObjectUploads",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": [
"arn:aws:s3:::BUCKETNAME/*",
@pacohope
pacohope / fix-freebsd-update.sh
Created March 6, 2018 15:00 — forked from thefloweringash/fix-freebsd-update.sh
There I "fixed" freebsd-update.
#!/bin/sh
# Fork of https://gist.github.com/thefloweringash/8729473
#
# freebsd-update is a clever script that downloads a lot of bsdiff
# patches and whole files when patches are not suitable. The result of
# this process is a collection of files in
# /var/db/freebsd-update/files. If the files already exist, it will
# not fetch them again.
#