Skip to content

Instantly share code, notes, and snippets.

View robhammond's full-sized avatar

Rob Hammond robhammond

View GitHub Profile
@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
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 / 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';
@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://!!;
upstream myapp {
server 127.0.0.1:8082;
}
server {
listen 80;
server_name example.com;
location / {
proxy_set_header X-Request-Base https://$host/myapp;
@robhammond
robhammond / http-status-checker-async.pl
Last active October 1, 2015 21:29
Non-blocking HTTP status checker script using Mojolicious. Accepts text file 'urls.txt' and writes to 'http-status.csv'
#!/usr/bin/env perl
use strict;
use utf8;
use warnings qw(all);
use Modern::Perl;
use Mojo::Util qw(decode encode html_unescape xml_escape);
use Mojo::DOM;
use Mojo::Log;
use Mojo::Asset::File;
@robhammond
robhammond / 0_reuse_code.js
Created July 30, 2014 16:42
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
package Apis::Reddit;
use strict;
use warnings;
use Mojo::Log;
use DateTime;
use Mojo::UserAgent;
my $log = Mojo::Log->new();
sub new {

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@robhammond
robhammond / search-metrics-charts.pl
Last active June 26, 2018 10:58
Get date and chart x-axis values from the JSON created when generating a SEO visibility chart in SearchMetrics. Makes it easier to plot YoY growth etc.
#!/usr/bin/env perl
use strict;
use Modern::Perl;
use Mojo::JSON qw(decode_json);
# seo-paid-visibility
my $raw = <<EOF;
{"data":{...}}
EOF