Skip to content

Instantly share code, notes, and snippets.

# https://danielms.site/blog/requirements-txt-to-poetry-pyproject-toml/
# requirements.txt to pyproject.toml
cat requirements.txt | grep -E '^[^# ]' | cut -d= -f1 | xargs -n 1 poetry add
@Arqentum
Arqentum / bq_sql_back_forward_fill.sql
Created May 6, 2025 19:37
#BiqQuery #SQL back and forward fill
with tt1 as (select 1 as time, null as val union all
select 2, 1 union all
select 3, null union all
select 4, null union all
select 5, null union all
select 6, 0 union all
select 7, null union all
select 8, null
)
select *
@Arqentum
Arqentum / bq_pipe_notation.sql
Last active March 7, 2025 21:59
#BigQuery #SQL Pipe notation
-- https://cloud.google.com/bigquery/docs/reference/standard-sql/pipe-syntax
from etl.ripley_invoice_lines_insight rili
|> where project_id = '6733cbe25336c776feafa158'
|> aggregate sum(net_fcy_rfv) as total_amount
group by project_id, invoice_id, invoice_action, transaction_currency, functional_currency
-- /*debug*/ |> select *;
|> EXTEND current_timestamp() as current_timestamp
@Arqentum
Arqentum / dynamic_array_agg_bq.sql
Created December 10, 2024 22:04
#BigQuery Dynamic array_agg grouping
-- https://stackoverflow.com/questions/64043166/aggregate-same-row-groups-into-one-row
with tt1 as (
select invoice_id, project_id, invoice_action, ll.line_item_id, ll.line_item_action
from api.invoice_lines_lifecycle ll
where true
and ll.plan_type = 'domain'
and ll.invoice_lifecycle = 'AccountingInvoiceFinalizedEvent'
and ll.project_id = '6670e53320098f4e87e5dd50'
)
-- select t, (SELECT AS STRUCT * EXCEPT(line_item_id, line_item_action) FROM UNNEST([t]))
@Arqentum
Arqentum / gsheets_alternate_color_range.txt
Created June 4, 2024 18:48
Google #Sheet alternating range based on cell value
# Example for 'banding' value in column A2+
# Format, Conditional formatting:
Custom Formula
Apply to range: A2:U50
Formula: =ISODD(MATCH($A2, UNIQUE($A$2:$A2),0))
# ArrayFormula:
={"gg";ARRAYFORMULA(
@Arqentum
Arqentum / sublime_fix_alias_git_commit_editor.sh
Last active May 9, 2024 18:23
#Sublime set alias and fix #Git commit editor
# 1) Run in Terminal:
# This adds a subl alias to /usr/local/bin/ pointing to Sublime Text 3 app’s binary file.
# Now running subl in Terminal will launch Sublime Text 3 app.
sudo ln -s /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
# 2) Run in Terminal:
git config --global core.editor "subl -n -w"
@Arqentum
Arqentum / pandas_to_gcs_gzipped.py
Created April 4, 2024 19:42
#Pandas to #GCS gzipped
csv_file_name = get_file_name(execution_date=context['execution_date'], ripley_table_name=self.ripley_table_name)
LOGGER.info('Uploading %s to %s' % (csv_file_name, self.gcs_bucket_name))
# Ensure that we properly encode and escape the JSON string
pandas_df['payload'] = pandas_df['payload'].apply(json.dumps)
pandas_df['schema'] = pandas_df['schema'].apply(json.dumps)
correct_csv = pandas_df.to_csv(encoding='utf-8', header=False, index=False, doublequote=True, quoting=csv.QUOTE_ALL)
blob = bucket.blob(csv_file_name)
blob.content_encoding = "gzip"
@Arqentum
Arqentum / airflow_debugging_dag.py
Created January 31, 2024 22:09
#Airflow allow debugging dag #Python
# add at the end of dag file
if __name__ == "__main__":
from airflow.utils.state import State
dag.clear()
dag.run()
@Arqentum
Arqentum / epic7.bat
Created January 24, 2024 16:22
#Adb headless batch
adb connect 127.0.0.1:5555 && cd /d s:\git\headless_adb && .\venv\Scripts\python.exe epic7.py
@Arqentum
Arqentum / bigquery_table_ddl_as_json.sh
Created November 9, 2023 00:24
#BigQuery get table DDL as json schema
# Activate console to run "bq" commands:
# https://console.cloud.google.com/bigquery?cloudshell=true
# bq show --format=prettyjson bigquery-public-data:samples.wikipedia | jq '.schema.fields'
bq show --format=prettyjson <project>:<bucket>.<table> | jq '.schema.fields'