Skip to content

Instantly share code, notes, and snippets.

# Python
__pycache__
*.pyc
*.pyo
*.pyd
.Python
.pytest_cache
# Others
env
#!/bin/bash
PYTHONPATH=$PYTHONPATH:/home/src jupyter notebook \
--ip=0.0.0.0 \
--port=8085 \
--allow-root
version: '3'
services:
jupyter_service:
build: .
entrypoint: "scripts/docker-entrypoint.sh"
user: root
ports:
- 8085:8085
env_file:
FROM jupyter/pyspark-notebook
WORKDIR /home/src
ADD requirements.txt .
RUN pip install -r requirements.txt
pandas==1.4.1
psycopg2-binary==2.9.3
plotly==5.6.0
sqlfluff==0.11.1
@ericabertan
ericabertan / lead_lag_syntax.sql
Last active April 15, 2022 16:48
LEAD and LAG syntax
LEAD | LAG(expression [,offset [,default_value]])
OVER (
[PARTITION BY partition_expression, ... ]
ORDER BY sort_expression [ASC | DESC], ...
)
@ericabertan
ericabertan / top_terms_lag_lead_example.sql
Created April 15, 2022 16:09
Previous and Next weeks top terms from Amazonas
SELECT
week,
array_agg(term) as top_terms,
LAG(array_agg(term), 1) OVER (ORDER BY week) as previous_week_top_terms,
LEAD(array_agg(term), 1) OVER (ORDER BY week) as next_week_top_terms
FROM `bigquery-public-data.google_trends.international_top_terms`
WHERE
region_code = 'BR-AM'
AND extract(year from week) = 2022
AND rank = 1
@ericabertan
ericabertan / top_terms_example.sql
Created April 15, 2022 15:57
What is the top terms from Amazonas BR by week in 2022?
SELECT
week,
array_agg(term) as top_terms
FROM `bigquery-public-data.google_trends.international_top_terms`
WHERE
region_code = 'BR-AM'
AND extract(year from week) = 2022
AND rank = 1
GROUP BY week
ORDER BY week
@ericabertan
ericabertan / materialised_path.sql
Created April 3, 2022 17:37
Materialised Path model to represent tree structures
create table teste3 (
id integer unique,
category_name varchar(100) not null,
breadcrumb integer array[3] null,
parent_id integer null,
primary key (id),
constraint fk_parent_id foreign key (parent_id) references teste3(id)
)
insert into teste3(id, category_name, breadcrumb, parent_id) values(1, 'Automoveis e veiculos', null, null);
@ericabertan
ericabertan / analyze_ppd.txt
Last active March 22, 2022 18:17
Analyze PPD
from promiseland.process_deadline import analyze_sorting_record
from promiseland.switch_names import PromiselandSwitches as PromSw
sw_macro_processes = PromSw.ENABLE_PROCESS_DEADLINE_BY_MACRO_PROCESS.get_enabled_values()
sr = SortingRecord.objects.get(id=831095197)
sr.__dict__
mp_xd_routing_code_list = (PromSw.ENABLE_PROCESS_DEADLINE_MACRO_PROCESS_XD_BY_ROUTING_CODE.get_enabled_values())