Skip to content

Instantly share code, notes, and snippets.

View chrisgoddard's full-sized avatar

Chris Goddard chrisgoddard

View GitHub Profile
@chrisgoddard
chrisgoddard / udfs.sql
Created September 23, 2020 14:21
BigQuery Custom UDFs
create or replace function dataset.array_int_least(x array<int64>) as
((select min(y) from unnest(x) as y));
create or replace function dataset.array_int_greatest(x array<int64>) as
((select max(y) from unnest(x) as y));
create or replace function dataset.array_timestamp_least(x array<timestamp>) as
((select min(y) from unnest(x) as y));
create or replace function dataset.array_timestamp_greatest(x array<timestamp>) as
@chrisgoddard
chrisgoddard / delete-likes.js
Last active July 25, 2019 12:22
Delete liked tweets
// run in console at twitter.com/username/likes (replace username with your username)
(function(document,window) {
function clearlikes(){
    window.scrollTo(0,document.body.scrollHeight);
    Array.from(document.querySelectorAll('[data-testid="unlike"]')).forEach(function(el){
     el.click();
    })
    setTimeout(clearlikes, 5000);
}
clearlikes();
@chrisgoddard
chrisgoddard / gtm-utilities.js
Last active August 1, 2019 09:13
Google Tag Manager Utility Library
function(){
"use strict";
/**
* Constants
*/
var VERSION = '2.1';
@chrisgoddard
chrisgoddard / code.js
Created June 24, 2018 16:36
object to query string
function buildQueryParams(params){
return Object.keys(params).map(function(key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
}).join('&');
}
@chrisgoddard
chrisgoddard / regex-reference.txt
Created June 21, 2018 15:34
domain filter regex reference
www.domain.com | ^www\.resmed\.com$
www.domain.com | ^www\d?\.resmed\.com$
www3.domain.com |
www.domain.com | ^(www\d?\.)?resmed\.com$
www3.domain.com |
domain.com |
@chrisgoddard
chrisgoddard / patterns
Created October 25, 2016 17:28
Useful regex patterns
Extract domain from string (with or without protocol)
[?:http(s)?:\/\/]?([a-z0-9\-]+\.?[a-z0-9\-]+\.[a-z]{2,3})
@chrisgoddard
chrisgoddard / json-ld-gtm.html
Last active July 23, 2023 16:52
JSON-LD GTM Tag
<script>
(function(){
var data = {
"@context": "http://schema.org",
"@type": "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": {{Page URL}}
},
"headline": {{SCHEMA - Article Headline}},
/**
* Simple regex/user agent mobile checker
* about 99% accurate when compared to 175k sessions in GA
*/
function isMobile()
{
return window.navigator.match(/Mobi|Touch|Opera\ Mini|Android/)
}
@chrisgoddard
chrisgoddard / find-overflow.js
Created October 12, 2015 22:48
Find unintended body overflow
var docWidth = document.documentElement.offsetWidth;
[].forEach.call(
document.querySelectorAll('*'),
function(el) {
if (el.offsetWidth > docWidth) {
console.log(el);
}
}
);
function getUrlParam(url, param) {
var match = url.match('(?:\\?|&)' + param + '=([^&#]*)');
return (match && match.length == 2) ? decodeURIComponent(match[1]) : '';
}