This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# loads the result of a query on Tinybird to a Pandas DataFrame | |
import pandas as pd | |
import urllib.parse | |
def build_tinybird_query_url(query: str, token: str) -> str: | |
url = f"https://api.tinybird.co/v0/sql?q={urllib.parse.quote(query + ' FORMAT CSVWithNames')}&token={token}" | |
return url | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION public.regexp_quote(IN TEXT) | |
RETURNS TEXT | |
LANGUAGE plpgsql | |
STABLE | |
AS $$ | |
/******************************************************************************* | |
* Function Name: regexp_quote | |
* In-coming Param: | |
* The string to decoded and convert into a set of text arrays. | |
* Returns: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF EXISTS events; | |
CREATE TABLE events | |
( | |
date timestamp, | |
product_id text, | |
user_id bigint, | |
event text, | |
extra_data json | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://vega.github.io/schema/vega-lite/v5.json", | |
"data": {"url": "data/stocks.csv"}, | |
"width": 400, | |
"height": 300, | |
"encoding": {"x": {"field": "date", "type": "temporal"}}, | |
"layer": [ | |
{ | |
"encoding": { | |
"color": {"field": "symbol", "type": "nominal"}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import io | |
from fastapi.responses import StreamingResponse | |
from fastapi import Request, Response | |
from fastapi import FastAPI | |
app = FastAPI() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# full process. Ingests data from postgres to tb, calculates duplicates, inserts them to a new datasource and removes the rows from that datasource that appear in the original one. | |
source $(pwd)/.env | |
# related, to ingest data from postgres: https://blog.tinybird.co/2019/10/14/the-one-cron-job-that-will-speed-up-your-analytical-queries-in-postgres-a-hundred-fold/ | |
echo 'Ingesting most recently update jobs' | |
psql $HEROKU_POSTGRES_URL -c "COPY (SELECT id, url, job_title, company, description, description_cleaned, date_posted, now() FROM job WHERE COALESCE(description, '') <> '' AND updated_at > now() - interval '70 minutes') TO STDOUT WITH (FORMAT CSV)" | curl -F csv=@- "https://api.tinybird.co/v0/datasources?name=jobs&mode=append&token=$TINYBIRD_ADMIN_TOKEN"; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- s1 is not used | |
WITH s1 AS ( | |
SELECT | |
linkedin_slug | |
, count(*) OVER (PARTITION BY 1) | |
, max(updated_at) max_updated_at | |
FROM person | |
GROUP BY linkedin_slug | |
HAVING count(*) > 1 | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"name": "Twitter", | |
"url": "twitter.com", | |
"industry": "internet", | |
"country": "United States", | |
"employee_count": 8200, | |
"linkedin_url": "http://www.linkedin.com/company/twitter", | |
"technology_names": [ | |
"4D", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Source: https://github.com/sqlalchemy/sqlalchemy/wiki/Query-Plan-SQL-construct | |
# This adds the last function, to print the query plan | |
# Caveats: stmt has to be built using sqlalchemy.select(...). If you use session.query(...) it'll fail. | |
# This is Postgres-only | |
# Guide to migrate to SQLAlchemy 2.0-style (from session.query() to select(...) ): https://docs.sqlalchemy.org/en/14/changelog/migration_20.html#migration-orm-usage | |
from sqlalchemy.ext.compiler import compiles | |
from sqlalchemy.sql.expression import ClauseElement | |
from sqlalchemy.sql.expression import Executable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# if .env, source .env | |
if test -f .env; then | |
source .env && | |
echo `date`: sourcing .env | |
fi | |
# mkdir if not exists | |
mkdir -p data/script_invoices | |
# download invoices created later or on this date (yyyy-mm-dd) |