Skip to content

Instantly share code, notes, and snippets.

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
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,
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
@diogoaurelio
diogoaurelio / emr_boto3_example.py
Last active November 23, 2017 13:24
emr_boto3_example.py
applications = [
{'Name': 'Spark'},
{'Name': 'Hive'},
{'Name': 'Tez'},
{'Name': 'Hadoop'},
{'Name': 'Ganglia'},
{'Name': 'Presto'},
{'Name': 'Zeppelin'}
]
release_label = "emr-5.9.0"
@diogoaurelio
diogoaurelio / aws_assume_role_sample.py
Created November 23, 2017 20:54
aws_assume_role_sample.py
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')
"""
@diogoaurelio
diogoaurelio / assume-role-policy.json
Created November 25, 2017 17:05 — forked from clstokes/assume-role-policy.json
Example: Terraform IAM Role
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
@diogoaurelio
diogoaurelio / aws_instance_temp_credentials.py
Created December 1, 2017 11:11
aws_instance_temp_credentials.py
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
@diogoaurelio
diogoaurelio / iam.tf
Created December 3, 2017 15:31 — forked from clstokes/iam.tf
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}"
@diogoaurelio
diogoaurelio / basicActorClass.scala
Created December 20, 2017 13:42
Basic Scala Actor Class
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")
@diogoaurelio
diogoaurelio / scalaActorTrait.scala
Created December 20, 2017 13:45
summaryScalaActorTrait
trait Actor {
// to make type Receive known in subclasses without import
type Receive = Actor.Receive
// [...]
//#receive
def receive: Actor.Receive
// [...]
}