Skip to content

Instantly share code, notes, and snippets.

View husanpy's full-sized avatar

Khusan Turdiev husanpy

  • Tashkent, Uzbekistan
View GitHub Profile
@husanpy
husanpy / upsert_df.py
Last active October 17, 2023 13:00 — forked from pedrovgp/upsert_df.py
Allow upserting a pandas dataframe to a postgres table (equivalent to df.to_sql(..., if_exists='update')
# Upsert function for pandas to_sql with postgres
# https://stackoverflow.com/questions/1109061/insert-on-duplicate-update-in-postgresql/8702291#8702291
# https://www.postgresql.org/docs/devel/sql-insert.html#SQL-ON-CONFLICT
import pandas as pd
from sqlalchemy import create_engine, text, engine
import uuid
from settings import DB_STR
from sqlalchemy.engine.base import Connection
from sqlalchemy.sql.elements import TextClause
@husanpy
husanpy / vm_containers.md
Created January 21, 2024 21:10 — forked from ziritrion/vm_containers.md
Cheatsheet for various container and VM thingies

Multipass

Tool to run Ubuntu VM's easily with command-line interface.

List available instances

  • multipass list

Create and launch a new instance using the latest LTS release

@husanpy
husanpy / duckdb_bq_storage_api.py
Created March 17, 2024 16:53 — forked from ML-engineer/duckdb_bq_storage_api.py
Read BQ table to DuckDB directly from storage read api
import duckdb
from google.cloud import bigquery
bqclient = bigquery.Client()
table = bigquery.TableReference.from_string(
"bigquery-public-data.utility_us.country_code_iso"
)
rows = bqclient.list_rows(table)
country_code_iso = rows.to_arrow(create_bqstorage_client=True)
cursor = duckdb.connect()