Skip to content

Instantly share code, notes, and snippets.

View dkhmelenko's full-sized avatar

Dmytro Khmelenko dkhmelenko

View GitHub Profile
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)
input_string = "Lorem ipsum"
content = read_characters(input_string)
for item in content:
print(f"Current char {item}")
def print_address(address):
def decorator(original_function):
print(f"Sending to {address}")
original_function()
return decorator
@print_address("Munich, Germany")
def ship_package():
print("Package Shipped")
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]
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
var source = new EventSource('/updates');
source.addEventListener('time_update', function(event) {
console.log(event.data);
});
...
source.close();
@dkhmelenko
dkhmelenko / cdk_example.py
Last active October 12, 2021 21:19
AWS CDK example
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
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'])
@dkhmelenko
dkhmelenko / decorator_declaration.py
Created September 18, 2023 21:01
Decorator declaration
def authenticate(user):
def decorator(request):
add_auth_headers()
request()
def add_auth_headers():
...
return decorator