Skip to content

Instantly share code, notes, and snippets.

View ankona's full-sized avatar
🏠
Working from home

Chris McBride ankona

🏠
Working from home
View GitHub Profile
@ankona
ankona / resize_virtualbox_vdi
Last active August 29, 2015 14:27
MAC resize command for VirtualBox .vdi
VBoxManage clonehd [OldHDDFile.vdi] [NewHDDFile.vdi] --existing - See more at: http://tips.kaali.co.uk/2012/03/16/expand-or-increase-the-size-of-virtual-box-vdi-dis/#sthash.WFNw5Rha.dpuf
@ankona
ankona / copy_properties.py
Created October 30, 2015 19:43
Copy properties from one python object to another
def __copy_properties(copy_from, copy_to):
for key in copy_from:
print 'found ' + str(key)
if hasattr(copy_to, key):
print 'for key "{2}" - copying value "{0}" from copy_from and replacing value "{1}" in copy_to'.format(copy_from[key], getattr(copy_to, key), key)
setattr(copy_to, key, copy_from[key])
@ankona
ankona / compare_uploads.cs
Last active November 18, 2015 23:06
Compare s3Client.putObject and TransferUtility.upload methods
using System.Linq;
using System.Text;
using System;
using System.Collections.Generic;
using Amazon.DynamoDBv2;
using Amazon.DynamoDBv2.Model;
using Amazon.Runtime;
using Amazon.S3;
using System.Configuration;
{
"AWSTemplateFormatVersion": "2010-09-09",
"Metadata": {
},
"Parameters": {
"EnvironmentParameter": {
"Type": "String",
"Default": "dev",
"AllowedValues": ["dev", "test", "stage", "lt", "prod"],
"Description": "Supply an environment from the choices: dev, test, stage, lt, or prod. The default is dev."
@ankona
ankona / get_api_id_from_stack.py
Created May 4, 2016 17:33
query a cloudformation stack for it's resources and find the first RestAPI id in it
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
.. module:: get_api_id_from_stack
:synopsis:
"""
import boto3
import sys
@ankona
ankona / deploy_cf_script.py
Created May 4, 2016 17:36
starter script to use boto / aws API to deploy a cloudformation script
import os
import time
import boto3
from botocore.exceptions import ClientError
def get_api_id_from_stack(stack_name):
api_id = ""
try:
cloudformation = boto3.client('cloudformation')
@ankona
ankona / templatize_swagger.py
Created May 4, 2016 17:41
script to alter a templatized swagger file so it can be pasted into a cloudformation script as a ::RestApi body value
import re
import json
p = re.compile("\{\{[\w]+\}\}")
input_path = '/path/to/swagger.json'
add_whitespace = False
f = open(input_path)
fw = open(input_path + '.notokens', 'w')
@ankona
ankona / settingsExample.py
Created May 23, 2016 18:25
settings table example
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import boto3
from boto.dynamodb2.table import Table
def saveSetting(applicationName, settingName, value):
client = boto3.client('dynamodb')
response = client.update_item(TableName="chrisSettings",
Key={ "applicationName": { "S": applicationName } },
@ankona
ankona / sts-assume-role-powershell.ps1
Created July 11, 2016 14:41
STS Assume Role (PowerShell)
$RoleArn = "%deployer_arn%"
$ExternalId = "%assume_role_external_id%"
$Region = "us-east-1"
$Response = (Use-STSRole -Region $Region -RoleArn $RoleArn -ExternalId $ExternalId -RoleSessionName "deploy-website-s3-bucket").Credentials
$SecretAccessKey = $Response.SecretAccessKey
$SessionToken = $Response.SessionToken
@ankona
ankona / get_orgunits_properties.py
Created July 27, 2016 21:18
get_orgunits_properties from bspace valence API
def get_orgunits_properties(uc,org_unit_type_id=None,org_unit_code=None,org_unit_name=None,bookmark=None,ver='1.3',**kwargs):
"""
Custom method hitting Brightspace Valence API. Request to add to service.py in d2lvalence_util submitted; consider removal.
"""
route = '/d2l/api/lp/{0}/orgstructure/'.format(ver)
kwargs.setdefault('params', {})
if org_unit_type_id:
kwargs['params'].update({'orgUnitType': org_unit_type_id})
if org_unit_code:
kwargs['params'].update({'orgUnitCode': org_unit_code})