Skip to content

Instantly share code, notes, and snippets.

aws-profiles() {
cat ~/.aws/credentials | grep '\[' | grep -v '#' | tr -d '[' | tr -d ']'
}
set-aws-profile() {
local aws_profile=$1
set -x
export AWS_PROFILE=${aws_profile}
set +x
}
@saurabh-hirani
saurabh-hirani / _set-aws-profile.sh
Created May 18, 2018 08:07
File path: ~/.oh-my-zsh/completions/_set-aws-profile
#compdef set-aws-profile
_set-aws-profile() {
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments '1: :->csi'
case $state in
csi)
@saurabh-hirani
saurabh-hirani / _set-aws-keys.sh
Created May 18, 2018 08:08
File path: ~/.oh-my-zsh/completions/_set-aws-keys
#compdef set-aws-keys
_set-aws-keys() {
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments '1: :->csi'
case $state in
csi)
@saurabh-hirani
saurabh-hirani / sample-aws-credentials.sh
Created May 18, 2018 08:14
File path: ~/.aws/credentials
[profile_1]
aws_access_key_id = profile_1_access_key
aws_secret_access_key = profile_1_secret_key
[profile_2]
aws_access_key_id = profile_2_access_key
aws_secret_access_key = profile_2_secret_key
[profile_3]
aws_access_key_id = profile_3_access_key
@saurabh-hirani
saurabh-hirani / get_es_index_type_count.py
Last active August 5, 2018 06:38
For an ES host - call the _mappings API and get the type count for each index
import sys
import json
import requests
# The following find function is a minor edit of the function posted here
# https://stackoverflow.com/questions/9807634/find-all-occurrences-of-a-key-in-nested-python-dictionaries-and-lists
def find(key, value):
for k, v in value.iteritems():
if k == key and not isinstance(v, dict) and not isinstance(v, list):
yield v
@saurabh-hirani
saurabh-hirani / understand-percentile-final.txt
Last active December 1, 2018 05:36
rough-notes-for-explaining-percentile
1.
- if 10 students took a test and scored the following:
10 20 30 40 50 60 70 80 90 100
and the cutoff percentage for a college admission is 90% - how many students got in?
- average does not help - avg = (n * (n + 1)) / 2 = 55
from __future__ import print_function
import requests
url = "https://google.com"
url_count = 10
for i in range(url_count):
print(requests.get(url, params={'page': i}))
from __future__ import print_function
import grequests
url = "https://google.com"
url_count = 10
pending_requests = []
for i in range(url_count):
pending_requests.append(grequests.get(url, params={'page': i}))
#!/bin/bash
cn='example.com'
host="0.0.0.0"
port=8082
openssl genrsa -out /tmp/$cn.key 2048
openssl req -new -x509 -sha256 -key /tmp/$cn.key -out /tmp/$cn.crt -days 3650 \
-subj "/CN=$cn\/emailAddress=admin@$cn/C=US/ST=Ohio/L=Columbus/O=Widgets Inc/OU=Some Unit"
docker run --rm -e HTTPS_CERT_FILE='/tmp/example.com.crt' -e HTTPS_KEY_FILE='/tmp/example.com.key' -e PORT=$port -p $port:$port -v /tmp:/tmp mccutchen/go-httpbin:v2.1.1