Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Goddard chrisgoddard

View GitHub Profile
@chrisgoddard
chrisgoddard / udfs.sql
Created Sep 23, 2020
BigQuery Custom UDFs
View udfs.sql
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 Jul 25, 2019
Delete liked tweets
View delete-likes.js
// 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 Aug 1, 2019
Google Tag Manager Utility Library
View gtm-utilities.js
function(){
"use strict";
/**
* Constants
*/
var VERSION = '2.1';
@chrisgoddard
chrisgoddard / code.js
Created Jun 24, 2018
object to query string
View code.js
function buildQueryParams(params){
return Object.keys(params).map(function(key) {
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]);
}).join('&');
}
@chrisgoddard
chrisgoddard / regex-reference.txt
Created Jun 21, 2018
domain filter regex reference
View regex-reference.txt
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 Oct 25, 2016
Useful regex patterns
View patterns
Extract domain from string (with or without protocol)
[?:http(s)?:\/\/]?([a-z0-9\-]+\.?[a-z0-9\-]+\.[a-z]{2,3})
View json-ld-gtm.html
<script>
(function(){
var data = {
"@context": "http://schema.org",
"@type": "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": {{Page URL}}
},
"headline": {{SCHEMA - Article Headline}},
View detect-mobile.js
/**
* Simple regex/user agent mobile checker
* about 99% accurate when compared to 175k sessions in GA
*/
function isMobile()
{
return window.navigator.match(/Mobi|Touch|OperaMini|Android/)
}
@chrisgoddard
chrisgoddard / find-overflow.js
Created Oct 12, 2015
Find unintended body overflow
View find-overflow.js
var docWidth = document.documentElement.offsetWidth;
[].forEach.call(
document.querySelectorAll('*'),
function(el) {
if (el.offsetWidth > docWidth) {
console.log(el);
}
}
);
View Useful Utility Functions
function getUrlParam(url, param) {
var match = url.match('(?:\\?|&)' + param + '=([^&#]*)');
return (match && match.length == 2) ? decodeURIComponent(match[1]) : '';
}
You can’t perform that action at this time.