This file contains 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 tensorflow as tf | |
x = tf.Variable(3, name="x", dtype=tf.int16) | |
y = tf.Variable(4, name="y", dtype=tf.int16) | |
a = tf.constant(5, dtype=tf.int16) | |
b = tf.constant(10, dtype=tf.int16) | |
c = tf.constant(15, dtype=tf.int16) | |
op1 = x*x*y |
This file contains 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 tensorflow as tf | |
import numpy as np | |
# Start by creating random values: | |
x_data = np.random.rand(100).astype(np.float32) | |
_y_data = 3 + 5 * x_data | |
y_data = np.vectorize(lambda y: y + np.random.normal(loc=0.0, scale=0.1))(_y_data) | |
# ... and then initializing the variables a and b, with any random guess, |
This file contains 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 Country: | |
""" | |
Convenience class for storing | |
data relative to a given country | |
""" | |
def __init__(self, country_name, population, continent): | |
""" | |
Default constructor | |
:param country_name: str |
This file contains 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
applications = [ | |
{'Name': 'Spark'}, | |
{'Name': 'Hive'}, | |
{'Name': 'Tez'}, | |
{'Name': 'Hadoop'}, | |
{'Name': 'Ganglia'}, | |
{'Name': 'Presto'}, | |
{'Name': 'Zeppelin'} | |
] | |
release_label = "emr-5.9.0" |
This file contains 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 boto3 | |
def role_arn_to_session(**args): | |
""" | |
Usage : | |
session = role_arn_to_session( | |
RoleArn='arn:aws:iam::012345678901:role/example-role', | |
RoleSessionName='ExampleSessionName') | |
client = session.client('sqs') | |
""" |
This file contains 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
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ | |
"Action": "sts:AssumeRole", | |
"Principal": { | |
"Service": "ec2.amazonaws.com" | |
}, | |
"Effect": "Allow", | |
"Sid": "" |
This file contains 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 get_temp_credentials(role=DEFAULT_INSTANCE_ROLE): | |
""" Retrieves temp AWS credentials """ | |
query_uri = 'http://169.254.169.254/latest/meta-data/iam/security-credentials/{}'.format(role) | |
print('Querying AWS for credentials - {}'.format(query_uri)) | |
try: | |
sts_credentials = requests.get(query_uri).json() | |
if isinstance(sts_credentials, dict) and \ | |
sts_credentials.get('Code') == 'Success': | |
print('Successfully retrieved temp AWS credentials.') | |
return sts_credentials |
This file contains 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
variable "role_name" {} | |
variable "role_policy_file" {} | |
resource "aws_iam_role" "role" { | |
name = "${var.role_name}" | |
assume_role_policy = "${file("${path.module}/policies/${var.role_policy_file}")}" | |
} | |
output "role_arn" { | |
value = "${aws_iam_role.role.arn}" |
This file contains 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 akka.actor.Actor | |
import akka.actor.Props | |
import akka.event.Logging | |
class MyActor extends Actor { | |
val log = Logging(context.system, this) | |
var myMutatedVar: Int = 0 | |
def receive = { | |
case "test" => log.info("received test") | |
case "mutate" => myMutatedVar += 1; log.info(s"Mutated var to: $myMutatedVar") |
This file contains 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
trait Actor { | |
// to make type Receive known in subclasses without import | |
type Receive = Actor.Receive | |
// [...] | |
//#receive | |
def receive: Actor.Receive | |
// [...] | |
} |