Skip to content

Instantly share code, notes, and snippets.

View danthelion's full-sized avatar
🔫
Wait, it's all data?

Daniel Palma danthelion

🔫
Wait, it's all data?
View GitHub Profile
@danthelion
danthelion / download.js
Created June 20, 2024 16:06
Google Apps Script to download images from a Google Doc into a Google Drive folder
function saveGoogleDocsImages() {
// Define the folder name where the extracted images will be saved
const folderName = 'Document Images';
// Check if a folder with the specified name already exists
const folders = DriveApp.getFoldersByName(folderName);
// If the folder exists, use it; otherwise, create a new folder
const folder = folders.hasNext() ? folders.next() : DriveApp.createFolder(folderName);
set -e
DB_FILE_FULL_PATHG=$1
DB_FILE_PARENT_FOLDER=$(dirname $DB_FILE_FULL_PATHG)
DB_FILE_NAME=$(basename $DB_FILE_FULL_PATHG)
ngrok http file://$DB_FILE_PARENT_FOLDER --log=stdout >/dev/null &
sleep 1
@danthelion
danthelion / updated-schema-producer.py
Created October 20, 2022 12:04
Updated schema to produce
client = SchemaRegistryClient(url="http://127.0.0.1:8081")
class User(BaseModel):
ts: str
name: str
country: str
date_of_birth: str
for i in range(100):
data = User(
@danthelion
danthelion / check-schema-before-prod.py
Last active October 20, 2022 11:55
check schema before producing
client = SchemaRegistryClient(url="http://127.0.0.1:8081")
class User(BaseModel):
ts: str
name: str
country: str
age: int
for i in range(100):
data = User(
@danthelion
danthelion / register-sr.py
Last active October 20, 2022 11:40
Register schema registry
client = SchemaRegistryClient(url="http://127.0.0.1:8081")
class User(BaseModel):
ts: datetime.datetime
name: str
country: str
age: int
@danthelion
danthelion / producer-dob.py
Created October 20, 2022 11:10
dob producer
for i in range(100):
data = {
"ts": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"),
"name": fake.name(),
"country": fake.country(),
"date-of-birth": str(fake.date_of_birth(tzinfo=None, minimum_age=0, maximum_age=100)),
}
producer.send(topic=TOPIC, key=str(i).encode("utf-8"), value=json.dumps(data).encode("utf-8"))
print(f"Sent message {i} -> {data}")
sleep(2)
@danthelion
danthelion / avg_age.py
Created October 20, 2022 11:05
average age consumer
import json
import json
import os
from kafka import KafkaConsumer
BOOTSTRAP_SERVERS = (
"kafka:9092" if os.getenv("RUNTIME_ENVIRONMENT") == "DOCKER" else "localhost:9092"
)
@danthelion
danthelion / fake_user_prod.py
Created October 20, 2022 10:55
fake user producer
TOPIC = "USERS"
def push_messages():
producer = KafkaProducer(
bootstrap_servers=BOOTSTRAP_SERVERS,
)
fake = Faker()
for i in range(100):
data = {
@danthelion
danthelion / cc.yaml
Created October 20, 2022 10:52
Confluent Kafka + Schema registry
version: '3'
services:
broker:
image: confluentinc/cp-kafka:7.2.1
hostname: broker
container_name: broker
ports:
- "9092:9092"
- "9101:9101"
@danthelion
danthelion / iceberg.sql
Created July 4, 2022 19:32
Iceberg table creation via Trino
USE iceberg;
CREATE SCHEMA IF NOT EXISTS iris
WITH (location = 's3a://iris/');
CREATE TABLE IF NOT EXISTS iceberg.iris.iris_parquet
(
sepal_length DOUBLE,
sepal_width DOUBLE,
petal_length DOUBLE,