Skip to content

Instantly share code, notes, and snippets.

View gmyrianthous's full-sized avatar

Giorgos Myrianthous gmyrianthous

View GitHub Profile
@gmyrianthous
gmyrianthous / select_rentals.sql
Last active September 4, 2022 14:01
Rows in example rental table
SELECT * FROM rental;
/*
|id |customer_id|store_id|amount|status |notes|rental_date |return_date |
|---|-----------|--------|------|------------|-----|----------------------|----------------------|
| 1 | 100 | 4 | 12.49| "completed"| | "2021-05-01 12:45:39"| "2021-05-03 15:10:02"|
| 3 | 100 | 4 | 5.68 | "on_rental"| | "2022-10-01 12:45:39"| |
| 2 | 58 | 2 | 9.32 | "on_rental"| | "2022-09-01 08:21:32"| |
| 4 | 100 | 4 | 1.67 | "completed"| | "2022-09-01 08:21:32"| "2022-09-02 09:21:22"|
| 5 | 100 | 6 | 2.67 | "completed"| | "2022-05-01 08:21:32"| "2022-05-02 09:21:22"|
@gmyrianthous
gmyrianthous / insert_rows.sql
Last active September 4, 2022 14:00
Add sample rows in rental table
INSERT INTO rental VALUES (1, 100, 4, 12.49, 'completed', NULL, '2021-05-01 12:45:39'::timestamp, '2021-05-03 15:10:02'::timestamp)
INSERT INTO rental VALUES (3, 100, 4, 5.68, 'on_rental', NULL, '2022-10-01 12:45:39'::timestamp, NULL)
INSERT INTO rental VALUES (3, 100, 4, 5.68, 'on_rental', NULL, '2022-10-01 12:45:39'::timestamp, NULL)
INSERT INTO rental VALUES (4, 100, 4, 1.67, 'completed', NULL, '2022-09-01 08:21:32'::timestamp, '2022-09-02 09:21:22'::timestamp)
INSERT INTO rental VALUES (5, 100, 6, 2.67, 'completed', NULL, '2022-05-01 08:21:32'::timestamp, '2022-05-02 09:21:22'::timestamp)
INSERT INTO rental VALUES (6, 100, 6, 0.49, 'completed', NULL, '2022-05-03 08:21:32'::timestamp, '2022-05-04 09:21:22'::timestamp)
@gmyrianthous
gmyrianthous / create_rental_table.sql
Created September 4, 2022 12:49
Example rental_table
DROP TABLE IF EXISTS rental;
CREATE TABLE rental (
id INTEGER PRIMARY KEY,
customer_id INTEGER NOT NULL,
store_id INTEGER NOT NULL,
amount FLOAT NOT NULL,
status VARCHAR(255) NOT NULL,
notes VARCHAR(255),
rental_date TIMESTAMP,
return_date TIMESTAMP
if __name__ == '__main__':
print('Hello World!')
@gmyrianthous
gmyrianthous / postgres_to_bq.py
Created July 8, 2022 14:26
Apache Airflow DAG for load data from Postgres database into Google Cloud BigQuery (through Google Cloud Storage)
from datetime import timedelta
from airflow.models import DAG
from airflow.utils.dates import days_ago
from airflow.providers.google.cloud.operators.gcs import GCSDeleteObjectsOperator
from airflow.providers.google.cloud.transfers.gcs_to_bigquery import GCSToBigQueryOperator
from airflow.providers.google.cloud.transfers.postgres_to_gcs import PostgresToGCSOperator
BQ_DS = 'my_dataset'
@gmyrianthous
gmyrianthous / iterable_example.py
Last active May 21, 2022 18:37
Example User-Defined Iterable and Iterator in Python
class Student:
def __init__(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name
def __str__(self):
return f'Student Name: {self.first_name} {self.last_name}'
class Lecturer:
def __init__(self, first_name, last_name, subject):
@gmyrianthous
gmyrianthous / asymptotic_plot.py
Created April 20, 2022 21:17
Asymptotic Time Complexity - Plot
import matplotlib.pyplot as plt
x = [1, 10]
y = [3, 6]
ax = plt.subplot(111)
ax.plot(x, y, '--')
@gmyrianthous
gmyrianthous / topic_detection.py
Created February 8, 2022 16:02
Topic Detection with Python - Full Code
import os
import sys
import requests
from time import sleep
API_KEY = <your AssemblyAI API key goes here>
AUDIO_FILE = '/path/to/your/audio/file.mp3'
UPLOAD_ENDPOINT = 'https://api.assemblyai.com/v2/upload'
TRANSCRIPT_ENDPOINT = 'https://api.assemblyai.com/v2/transcript'
@gmyrianthous
gmyrianthous / response.json
Created February 8, 2022 15:33
Topic Detection with Python - Output
{
...
"id": "audio-transcription-id",
"status": "completed",
"text": "Ted Talks are recorded live at Ted Conference..."
"iab_categories_result": {
"status": "success",
"results": [
{
"text": "Ted Talks are recorded live at Ted Conference...",
@gmyrianthous
gmyrianthous / topic_detection.py
Created February 8, 2022 15:29
Topic Detection with Python - Part 5
OUTPUT_TRANSCRIPT_FILE = 'speech-to-text-tutorial.txt'
with open(OUTPUT_TRANSCRIPT_FILE, 'w') as f:
f.write(res_result.json()['text'])
print(f'Transcript file saved under {OUTPUT_TRANSCRIPT_FILE}')