Skip to content

Instantly share code, notes, and snippets.

View ymcdull's full-sized avatar

Yunfeng Zhu ymcdull

  • Glasgow
View GitHub Profile
@ymcdull
ymcdull / ebs snapshot
Created April 15, 2016 12:44
ebs snapshot
#!/bin/bash
# ebs-snapshot.sh. Performs and validates EBS snapshots.
# snapshot date format 20111118-2305
snapshot_date=`date +s%Y%m%d-%H%M`
# Set name of script
progname=${0##*/} ## Get the name of the script without its path
@ymcdull
ymcdull / test-class-object-input.py
Created April 14, 2016 16:04
Just a quick "object" input test for class argument
class argTester(object):
def __init__(self, name1, name2):
self.name1 = name1
self.name2 = name2
def printer(self):
print("Hello, this is %s. Nice to meet you, %s" % (self.name1, self.name2))
tester = argTester("Frank", "Shirly")
@ymcdull
ymcdull / test_optparser.py
Created April 14, 2016 14:55
Test optparser example
### optparser has been discarded since python2.7, try argparse instead
### Url: http://lingxiankong.github.io/blog/2014/01/14/command-line-parser/
from optparser import OptionParser
parser = OptionParser()
parser.add_option('-f', '--file', dest="filename", help="write report to FILE", metavar="FILE")
options, args = parser.parse_args()
@ymcdull
ymcdull / test_os_basename.py
Created April 14, 2016 14:32
Using 'os' module to get the filename
import os
if __name__ == "__main__":
fname = os.path.basename(__file__)
print fname
@ymcdull
ymcdull / rds.py
Created April 14, 2016 14:23
launch/destroy AWS RDS instances
#!/usr/bin/env python
import sys, os
import boto
def print_usage():
print """
mysqlrds launch <id>
mysqlrds status <id>
mysqlrds destroy <id>
"""
@ymcdull
ymcdull / security-group-cleanup.py
Created April 14, 2016 11:29
A simple python file to clean up all unused AWS security groups with boto3
#!/usr/bin/env python
import boto3
### ###
# Need aws credentails already been configured #
### ###
### Code based on https://gist.github.com/miketheman/2630437
client = boto3.client('ec2')