Skip to content

Instantly share code, notes, and snippets.

View robhammond's full-sized avatar

Rob Hammond robhammond

View GitHub Profile
@robhammond
robhammond / ping-amp-cdn.pl
Last active April 6, 2017 12:06
Quick script to ping the AMPProject CDN and refresh cache
#!/usr/bin/env perl
use strict;
use Modern::Perl;
use Mojo::UserAgent;
# Add list of URLs into @urls array
my @urls = qw();
my $ua = Mojo::UserAgent->new;
for my $u (@urls) {
$u =~ s!^http://!!;
@robhammond
robhammond / bulk-amp-validator.pl
Created April 12, 2017 09:46
Bulk AMP URL validation
#!/usr/bin/env perl
use strict;
use Modern::Perl;
use Mojo::UserAgent;
use Mojo::JSON qw(decode_json);
use Excel::Writer::XLSX;
use Data::Dumper;
my $in_file = 'bhm.txt';
my $output = 'bhm.xlsx';
const util = require('util');
var url = 'http://localhost:3000/test'; // should be set over cli
const chrome = require('chrome-remote-interface');
function onPageLoad(Runtime) {
const href = "document.querySelectorAll('a')";
return Runtime.evaluate({
expression: href
@robhammond
robhammond / google-analytics-batch-add-users.py
Last active January 22, 2018 13:23
Add Google Analytics users in batch for a list of specified properties and views using the Python Management API
"""A simple example of Google Analytics batched user permissions."""
"""https://developers.google.com/analytics/devguides/config/mgmt/v3/user-management#batching"""
import argparse
from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials
import httplib2
from oauth2client import client
@robhammond
robhammond / verify-client-ids.js
Last active December 14, 2022 06:58
Puppeteer script to check that Google Analytics Client ID is consistent across different platforms
'use strict';
const puppeteer = require('puppeteer');
// Test scenarios
// 4 different entrypoints
// ~8 different cookie setting scenarios (ie every page has at least 1 video)
// 2 different pre-set options - cookies and cookie-less
const reqUrls = [
@robhammond
robhammond / redirect.pl
Last active February 16, 2018 15:43 — forked from Logioniz/redirect.pl
Redirect from http to https with mojolicious
#!/usr/bin/perl
# To run need listen two ports: 80, 443
# sudo morbo 12.pl -l https://*:443?cert%3D%2Fhome%2Flogioniz%2Fcert%2Fserver.crt%26key%3D%2Fhome%2Flogioniz%2Fcert%2Fserver.key%26verify%3D0x00 -l http://*:80
# go to url in browser http://your_ip/qwe/asd
use Mojo::Base -strict;
use Mojolicious::Lite;
@robhammond
robhammond / extract-monthly-data.pl
Created February 20, 2018 17:29
Extract monthly data from Adobe Analytics to a Google BigQuery table. Once completed, use `cat *.json >> all.json` to combine files for import into BQ
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
use DateTime;
use FindBin qw($Bin);
use Getopt::Long;
use Modern::Perl;
use Mojo::JSON qw(encode_json);
@robhammond
robhammond / evergreen-regex.pl
Created March 2, 2018 14:47
Create a regular expression to identify evergreen content in Google Analytics
#!/usr/bin/env perl
use Modern::Perl;
use DateTime;
my $past = DateTime->now->subtract(months => 6);
my $past_year = $past->year();
my $past_month = $past->month();
my $past_2_year = $past->subtract(years => 1)->format_cldr('yy');
my $y_str;
@robhammond
robhammond / convert-decimal-to-fraction.pl
Created June 8, 2018 17:01
Convert decimal numbers to fractions
sub float2rat {
my $x = shift;
my $tolerance = 1.0E-6;
my $h1 = 1;
my $h2 = 0;
my $k1 = 0;
my $k2 = 1;
my $b = $x;
do {
@robhammond
robhammond / grab-image-info.pl
Created June 8, 2018 17:04
Grab metadata from images contained in URLs
#!/usr/bin/env perl
use Modern::Perl;
use Mojo::UserAgent;
use Mojo::JSON qw(decode_json);
use Image::Size qw(imgsize);
use POSIX;
my $urls = [...];