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
ratings = {"Namaste": 3.8, "At Luigi": 3.7, "Peruvian": 4.4, "Hannes": 3.9, "Creperie": 4.2} | |
top_rated = {name: rating for name, rating in ratings.items() if rating > 4.0} | |
print(top_rated) |
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
input_string = "Lorem ipsum" | |
content = read_characters(input_string) | |
for item in content: | |
print(f"Current char {item}") |
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 print_address(address): | |
def decorator(original_function): | |
print(f"Sending to {address}") | |
original_function() | |
return decorator |
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
@print_address("Munich, Germany") | |
def ship_package(): | |
print("Package Shipped") |
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
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 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 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 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
var source = new EventSource('/updates'); | |
source.addEventListener('time_update', function(event) { | |
console.log(event.data); | |
}); | |
... | |
source.close(); |
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
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 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 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 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 authenticate(user): | |
def decorator(request): | |
add_auth_headers() | |
request() | |
def add_auth_headers(): | |
... | |
return decorator |