Skip to content

Instantly share code, notes, and snippets.

View get_containers.sh
#!/bin/bash
set -u
while getopts n: opt; do
optarg="${OPTARG}"
if [[ "${opt}" = - ]]; then
opt="-${OPTARG%%=*}"
optarg="${OPTARG/${OPTARG%%=*}/}"
optarg="${optarg#=}"
set +u
View option.sh
#!/bin/bash
# ↓ここを編集
while getopts w-:h-: opt; do
optarg="${OPTARG}"
if [[ "${opt}" = - ]]; then
opt="-${OPTARG%%=*}"
optarg="${OPTARG/${OPTARG%%=*}/}"
optarg="${optarg#=}"
set +u
View kabegiwa-vs.yaml
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: kabegiwa-vs
spec:
hosts:
- kabegiwa.example.com
http:
- match:
- uri:
View delete_iroiro.py
import boto3, argparse
class iam():
def __init__(self):
self.session = boto3.Session(profile_name=args.profile)
self.iam = self.session.resource('iam')
def detach_all_policies(self): # iam_resource is group or role
policies = list(self.iam_resource.attached_policies.all())
for policy in policies:
View delete_group.py
import boto3
import argparse
parser = argparse.ArgumentParser(prog=__file__)
parser._action_groups.pop() # Edited this line
required = parser.add_argument_group('required arguments')
optional = parser.add_argument_group('optional arguments')
required.add_argument('--group-name',required=True,help='The name of the IAM group to delete.')
optional.add_argument('--profile',nargs='?',default='default',help='Use a specific profile from your credential file.')
View delete_group.py
import boto3
import argparse
parser = argparse.ArgumentParser(prog=__file__)
parser._action_groups.pop() # Edited this line
required = parser.add_argument_group('required arguments')
optional = parser.add_argument_group('optional arguments')
required.add_argument('--group-name',required=True,help='The name of the IAM group to delete.')
optional.add_argument('--profile',nargs='?',default='default',help='Use a specific profile from your credential file.')
View delete_role.py
import boto3
import argparse
parser = argparse.ArgumentParser(prog=__file__)
parser._action_groups.pop() # Edited this line
required = parser.add_argument_group('required arguments')
optional = parser.add_argument_group('optional arguments')
required.add_argument('--role-name',required=True,help='The name of the role to delete.')
optional.add_argument('--profile',nargs='?',default='default',help='Use a specific profile from your credential file.')
View kabegiwa_scraping.py
import requests
import lxml.html
html = requests.get('https://www.kabegiwablog.com').text
root = lxml.html.fromstring(html)
max_blog_post_count = 15
for i in range(1,max_blog_post_count):
blog_post = root.xpath('/html/body/div[3]/div/div[2]/div/div/div/div/div[1]/section['+str(i)+']/div[1]/h1/a')
print(blog_post[0].text+'\n'+blog_post[0].attrib['href']+'\n')
View scraping_whats_new.py
import re, requests, sys, io
from bs4 import BeautifulSoup
from datetime import datetime
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
def whats_new_current_month():
current_year = "{0:02d}".format(datetime.now().year)
current_month = "{0:02d}".format(datetime.now().month)
whats_new_url = 'aws.amazon.com/jp/about-aws/whats-new/'+current_year+'/'+current_month+'/'
View profile.py
import boto3
import argparse
parser = argparse.ArgumentParser(prog='profile.py')
parser.add_argument('--profile',nargs='?',default='default',help='Use a specific profile from your credential file.')
args = parser.parse_args()
profile = args.profile
session = boto3.Session(profile_name=profile)