Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mattm
mattm / dbt-source.sql
Created June 11, 2018 13:54
dbt source macro
{% macro source(table_name) %}
{% if target.name == 'prod' %}
{{ return("preceden_heroku." ~ table_name) }}
{% else %}
{{ return(table_name) }}
{% endif %}
{% endmacro %}
@mattm
mattm / base-model.sql
Created June 11, 2018 13:50
dbt base model
select
id,
email
from {{ var('base.users') }}
@mattm
mattm / base-table.yml
Created June 11, 2018 13:48
dbt base table name
vars:
"base.users" : "users"
@mattm
mattm / available-marketing-domains.txt
Created May 24, 2018 19:25
Available Marketing Domains
AANDG
AAS
ABILENE
ABRASIVE
ACCOMPLICE
ACENTO
ACTIONSPORTS
ADAGE
ADAIR
ADAY
@mattm
mattm / com.zone
Created May 18, 2018 17:12
.com Zone File, First 100 Lines
; The use of the Data contained in Verisign Inc.'s aggregated
; .com, and .net top-level domain zone files (including the checksum
; files) is subject to the restrictions described in the access Agreement
; with Verisign Inc.
$ORIGIN COM.
$TTL 900
@ IN SOA a.gtld-servers.net. nstld.verisign-grs.com. (
1526140941 ;serial
1800 ;refresh every 30 min
@mattm
mattm / com.zone.txt
Created May 18, 2018 17:10
Zone File
; The use of the Data contained in Verisign Inc.'s aggregated
; .com, and .net top-level domain zone files (including the checksum
; files) is subject to the restrictions described in the access Agreement
; with Verisign Inc.
$ORIGIN COM.
$TTL 900
@ IN SOA a.gtld-servers.net. nstld.verisign-grs.com. (
1526140941 ;serial
1800 ;refresh every 30 min
@mattm
mattm / standardize-url.sql
Created May 15, 2018 13:13
Standardize URL
SELECT
current_url,
CASE
WHEN STRPOS(current_url, "?") > 0 THEN SUBSTR(current_url, 0, STRPOS(current_url, "?") - 1)
WHEN STRPOS(current_url, "#") > 0 THEN SUBSTR(current_url, 0, STRPOS(current_url, "#") - 1)
ELSE current_url
END AS url
FROM (
SELECT 'https://www.helpscout.net/blog/beacon-preview-ui/' AS current_url
UNION ALL SELECT 'https://www.helpscout.net/blog/beacon-preview-ui/?utm_content=1234&utm_medium=social&utm_source=twitter' AS current_url
@mattm
mattm / page-views.sql
Created May 15, 2018 13:01
Page Views
SELECT
current_url,
COUNT(*) AS page_views
FROM mp.event
GROUP BY 1
@mattm
mattm / problematic-query.sql
Created May 15, 2018 13:00
Problematic Query
SELECT
current_url,
MIN(TIMESTAMP_TRUNC(time, DAY)) AS published_at
FROM mp.event
WHERE
current_url like "https://www.helpscout.net/blog/%"
GROUP BY 1
HAVING
COUNT(*) > 200 AND
MIN(time) >= "2018-04-04"
@mattm
mattm / unique-visitors.lookml
Created May 11, 2018 17:48
Unique Visitors LookML
view: mp_events {
sql_table_name: mp.event ;;
# ...
measure: unique_visitors {
type: count_distinct
sql: ${distinct_id} ;;
}
}