This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Fruit(object): | |
| """A class that makes various tasty fruits.""" | |
| def __init__(self, name, color, flavor, poisonous): | |
| self.name = name | |
| self.color = color | |
| self.flavor = flavor | |
| self.poisonous = poisonous | |
| def description(self): | |
| print "I'm a %s %s and I taste %s." % (self.color, self.name, self.flavor) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Step 1 | |
| #install the PiFm library | |
| cd ~ | |
| mkdir pifm | |
| cd pifm | |
| wget http://www.icrobotics.co.uk/wiki/images/c/c3/Pifm.tar.gz | |
| tar -xvf Pifm.tar.gz | |
| #Step 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # wehappyfew | |
| # Distributed over IDC(I Don't Care) license | |
| __author__ = 'wehappyfew' | |
| import time | |
| import serial | |
| import smtplib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def delete_instances(instance_tag="your_tag" , instance_state="stopped"): | |
| """ | |
| The function | |
| 1. filters all the instances by tag and instance-state | |
| 2. terminates/deletes the filtered instances (irreversible action!!!) | |
| """ | |
| reserves = conn.get_all_instances( filters={"tag-value":instance_tag , "instance-state-name":instance_state} ) | |
| for r in reserves: | |
| for instance in r.instances: | |
| instance.terminate() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import boto, boto.ec2, time | |
| # creds for AWS user | |
| aws_access_key_id = "sdvsdvsdvsdvsdvsdv" | |
| aws_secret_access_key = "sdvsdvsdvsdvsdvsdvsdv" | |
| Windows_Server_2003_R2_Base_64bit_imageID = "ami-b9f2d789" | |
| Ubuntu_Server_14_04_LTS_imageID = "ami-23ebb513" | |
| AMIs = { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def tag_instances(connection,tag , instance_state="pending"): | |
| """ | |
| -The function must be run immediately after the spawn of an instance!!!- | |
| 1. The function fetches all the instances | |
| 2. Filters them by instance-state-name:pending | |
| (for a short period the newly created instances are 'pending' before becoming 'running') | |
| 3. Tags them with the user defined tag. | |
| 4. Returns the just tagged instances (ids) for future reference | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def stop_instances(region, instance_tag="my_instance" , instance_state="running"): | |
| """ | |
| The function | |
| 1. filters all the instances by tag and instance-state | |
| 2. stops the filtered instances (does not terminate/delete them) | |
| 3. returns the just stopped instances (ids) for future reference | |
| """ | |
| c = boto.ec2.connect_to_region(region_name = region, | |
| aws_access_key_id = aws_access_key_id, | |
| aws_secret_access_key = aws_secret_access_key, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def delete_instances(region, instance_tag="my_instance" , instance_state="stopped"): | |
| """ | |
| The function | |
| 1. filters all the instances by tag and instance-state | |
| 2. terminates/deletes the filtered instances (irreversible action!!!) | |
| """ | |
| c = boto.ec2.connect_to_region(region_name = region, | |
| aws_access_key_id = aws_access_key_id, | |
| aws_secret_access_key = aws_secret_access_key, | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def list_all_instances(region): | |
| # make the connection to AWS with my creds | |
| conn = boto.ec2.connect_to_region(region_name = region, | |
| aws_access_key_id = aws_access_key_id, | |
| aws_secret_access_key = aws_secret_access_key, | |
| ) | |
| reservations = conn.get_all_instances() | |
| for r in reservations: | |
| for instance in r.instances: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fetch_excel_values(filepath, sheet_index=0): | |
| from xlrd import open_workbook | |
| # open the excel file | |
| book = open_workbook(filename=filepath) | |
| # open the specific sheet based on index | |
| sheet = book.sheet_by_index(0) | |
| # read headers | |
| keys = [sheet.cell(int(sheet_index),col_index).value for col_index in range(sheet.ncols)] |
OlderNewer