Skip to content

Instantly share code, notes, and snippets.

View bdnf's full-sized avatar
Somewhere in the Clouds

Oleh Bodunov bdnf

Somewhere in the Clouds
  • TU Dresden
View GitHub Profile
@bdnf
bdnf / start-kafka-cli.sh
Last active July 6, 2019 12:40
Setting up Kafka on Linux
# install Java
apt-get install openjdk-8-jdk -y
# download and extract Kafka
mkdir ~/Downloads
curl "https://www.apache.org/dist/kafka/2.1.1/kafka_2.11-2.1.1.tgz" -o ~/Downloads/kafka.tgz
mkdir ~/kafka && cd ~/kafka
tar -xvzf ~/Downloads/kafka.tgz --strip 1
# test installation with:
@bdnf
bdnf / python_inheritance.py
Created August 9, 2019 17:52
Simple example of multiple inheritance syntax in python
class First(object):
def __init__(self):
super(First, self).__init__()
print("first")
class Second(First):
def __init__(self):
super(Second, self).__init__()
print("second")
@bdnf
bdnf / redis_conn.py
Last active August 12, 2019 21:07
Creating Redis client and queue and enqueue items
from rq import Queue as RedisQueue
from redis import Redis
from rq.job import Job
from urllib.request import urlopen, Request
from xml.etree import ElementTree
def get_news():
headers = {'User-Agent': 'Mozilla/5.0'}
url = 'https://news.yahoo.com/rss/all'
@bdnf
bdnf / multiple_apps.py
Last active August 31, 2020 10:26
Logging across multiple modules
#app.py
import logging
from logging.handlers import TimedRotatingFileHandler
from flask import Flask
import new_module1
import new_module2
def create_app():
app = Flask(__name__)
@bdnf
bdnf / setting_java_in_docker
Last active October 9, 2019 13:12
Set JAVA_HOME in docker container
RUN apt-get update && \
apt-get install -y openjdk-8-jdk && \
apt-get install -y ant && \
apt-get clean && \
rm -rf /var/lib/apt/lists/ && \
rm -rf /var/cache/oracle-jdk8-installer;
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
RUN export JAVA_HOME
@bdnf
bdnf / cloudwatch_reporter.js
Created January 30, 2020 09:38
A starter code that enables AWS Lambda to send data to Cloud Watch
const AWS = require('aws-sdk')
const axios = require('axios')
// Name of a service, any string
const serviceName = process.env.SERVICE_NAME
// URL of a service to test
const url = process.env.URL
// CloudWatch client
@bdnf
bdnf / airflow-s3-hook.py
Last active January 29, 2022 23:10
Creating an S3 hook in Apache Airflow
import datetime
import logging
from airflow import DAG
from airflow.models import Variable
from airflow.operators.python_operator import PythonOperator
from airflow.hooks.S3_hook import S3Hook
def list_keys():
@bdnf
bdnf / Cargo.toml
Created March 12, 2020 17:46
Steps on how to organize a library in Rust
[package]
name = "graph"
version = "0.1.0"
authors = ["me"]
edition = "2020"
[lib]
name = "service"
path = "src/lib.rs"
@bdnf
bdnf / doctstrings-example.py
Created June 11, 2020 11:25
An example of proper docstrings for Python
class Pants:
"""The Pants class represents an article of clothing sold in a store
"""
def __init__(self, color, waist_size, length, price):
"""Method for initializing a Pants object
Args:
color (str)
waist_size (int)
@bdnf
bdnf / heartrate.sh
Created June 27, 2020 10:56
Simulate heart rate data from sensor and stream it to AWS Kinesis Stream
#!/bin/sh
while true
do
deviceID=$(( ( RANDOM % 10 ) + 1 ))
heartRate=$(jot -r 1 60 140)
echo "$deviceID,$heartRate"
aws kinesis put-record --stream-name <your_stream_name> --data "$deviceID,$heartRate"$'\n' --partition-key $deviceID --region us-east-1
done