Skip to content

Instantly share code, notes, and snippets.

Avatar

Aden Forshaw AdenForshaw

View GitHub Profile
@AdenForshaw
AdenForshaw / create-or-replace-bigquery-table-with-partition.sql
Created Aug 17, 2021
Create or Replace BigQuery table with partition
View create-or-replace-bigquery-table-with-partition.sql
create or replace table my_dataset.my_new_partitioned_table PARTITION BY date_column
as
(
select *
from my_dataset.my_table
)
View buigquery-angle-of-intersection.sql
SELECT
gislib.sp.ST_InitialBearing( ST_GeogPoint(45,35), ST_GeogPoint(135,35) ),
gislib.sp.ST_InitialBearing( ST_GeogPoint(-94.58, 39.1), ST_GeogPoint(-90.2, 38.63) )
View percentiles-in-bigquery.sql
select
percentiles[offset(10)] as p10,
percentiles[offset(25)] as p25,
percentiles[offset(50)] as p50,
percentiles[offset(75)] as p75,
percentiles[offset(90)] as p90,
from (
select approx_quantiles(char_length(text), 100) percentiles
@AdenForshaw
AdenForshaw / bigquery-use-parameterised-query.sql
Created Jan 25, 2021
[BigQuery using parameterised query in the console]
View bigquery-use-parameterised-query.sql
DECLARE ORG_NAME STRING;
SET ORG_NAME = "AFL";
EXECUTE IMMEDIATE """
WITH x as
(
select
country
, category
, subcategory
, organisation
@AdenForshaw
AdenForshaw / first_last_date_current_month_bigquery.sql
Created Jan 8, 2021
[how to find first and last date of last, current and next month in BigQuery]
View first_last_date_current_month_bigquery.sql
How to find FIRST_DAY, LAST_DAY of current month, next month, previous month in Google Bigquery
Using #Standard SQL
First day of the current month:
```SQL
SELECT DATE_TRUNC(CURRENT_DATE(), MONTH)
```
Last day of the current month (first day next month minus 1):
@AdenForshaw
AdenForshaw / bigquery-row-for-each-date-in-range.sql
Last active Sep 8, 2020
[BigQuery row for each date in range] Generates a row for every date in a range with day of week #bigquery
View bigquery-row-for-each-date-in-range.sql
with dates as (
SELECT day,
FORMAT_DATE('%A', day) AS dow
FROM UNNEST(
GENERATE_DATE_ARRAY(DATE('2020-02-01'), DATE('2020-02-29'), INTERVAL 1 DAY)
) AS day
)
@AdenForshaw
AdenForshaw / handler.js
Created Oct 8, 2019
AWS Lambda function to post SES mail updates from SNS and an SES configuration set
View handler.js
var https = require('https');
var util = require('util');
const SLACK_URI = process.env.SLACK_URI || 'XXXX/XXXX/XXXXXXXXXXXXXXXX'
const SLACK_CHANNEL = process.env.SLACK_CHANNEL || 'YOUR-SLACK-CHANNEL'
exports.handler = async (event, context) => {
console.log(JSON.stringify(event, null, 2));
View Service downtime report - template
Executive summary
- brief paragraph that anyone can understand & apology for those affected.
The rest of the report should be purely factual with no emotion & or blame.
Issue Summary
- short summary (5 sentences)
- list the duration along with start and end times (include timezone)
- state the impact (most user requests resulted in 500 errors, at peak 100%)
- close with root cause