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
@authenticate | |
@log_request | |
def get_employees(user): | |
... |
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 authenticate(request): | |
def decorator(*args, **kwargs): | |
add_auth_headers() | |
request(*args, **kwargs) | |
def add_auth_headers(): | |
... | |
return decorator | |
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
@authenticate(user) | |
def get_employees(): | |
... | |
get_employees() |
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 authenticate(user): | |
def decorator(request): | |
add_auth_headers() | |
request() | |
def add_auth_headers(): | |
... | |
return decorator |
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 | |
review_text = 'The service was terrible! The food was cold and the staff was rude. Def not recommended' | |
client = boto3.client('comprehend') | |
response = client.detect_sentiment(Text=review_text, LanguageCode="en") | |
print(response['Sentiment']) |
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
from aws_cdk import (aws_s3, aws_s3_notifications, core, aws_sns) | |
# create S3 bucket | |
s3 = aws_s3.Bucket(self, "s3bucket_cdk") | |
# define SNS topic ans assign it | |
sns_topic = aws_sns.Topic(self, "CDK Notification") | |
sns_notification = aws_s3_notifications.SnsDestination(sns_topic) | |
# assign notification for the s3 event type when new object created |
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
var source = new EventSource('/updates'); | |
source.addEventListener('time_update', function(event) { | |
console.log(event.data); | |
}); | |
... | |
source.close(); |
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 UpdatesController < ApplicationController | |
include ActionController::Live | |
def updates | |
response.headers["Content-Type"] = "text/event-stream" | |
sse = SSE.new(response.stream, retry: 1000, event: "time_update") | |
sse.write(Time.now) | |
ensure | |
sse.close | |
end |
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
city_companies = { | |
apple: ["Boston", "Seattle", "San Francisco"], | |
uniliver: ["London", "Sussex"], | |
microsoft: ["Seattle", "Austin", "Denver"], | |
amazon: ["Portland", "Denver", "Washington"], | |
starbucks: ["Beijing", "Seattle", "Munich"] | |
} | |
tech_giants = [:apple, :microsoft, :amazon] |
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
@print_address("Munich, Germany") | |
def ship_package(): | |
print("Package Shipped") |
NewerOlder