Skip to content

Instantly share code, notes, and snippets.

View commuterjoy's full-sized avatar

Matt Chadburn commuterjoy

View GitHub Profile

git lg --since 353.days | cut -f 4- | grep 'Merge pull request' | wc -l

1612 merges to master

git lg --since 353.days | cut -f 1- | grep 'Merge pull request' | cut -f 3 | cut -d ' ' -f 2 | sort | uniq -c

  46 Jan
  31 Feb
 89 Mar
@commuterjoy
commuterjoy / OAS Code
Last active December 31, 2015 12:29
How to make a request for a commercial component on theguardian.com
<script>
require(['modules/commercial/loader'], function (CommercialComponent) {
var slot = document.querySelector('[class="js-sticky-upper"]');
var c = new CommercialComponent({config: guardian, oastoken: '%%C%%?'}).travel(slot);
})
</script>
228968 Film
108014 Football
77954 Guardian
13098 Observer
10914 Politics
8683 Arts
8219 Education
6225 Money
4566 Travel
4231 Society
<!DOCTYPE html>
<html>
<head>
<title>Web Components</title>
<style>
/* the host */
#host {
margin: 20px;
background-color: #ccc;
}
<!DOCTYPE html>
<html>
<head>
<style>
body { max-width: 400px; margin: 50px auto; }
a { color: blue; }
p, li { line-height: 150%; }
</style>
</head>
<body>
@commuterjoy
commuterjoy / admin__statictext__561001.js
Last active January 2, 2016 15:49
benchmark next-gen from r2
// Next-gen performance benchmark - https://gist.github.com/commuterjoy/8325989
jQ(document).ready(function () {
if ( s
&& (s.prop67 === "nextgen-compatible")
) {
jQ.get(location.pathname + '?view=mobile');
try {
var nextGenNavigation = 'http://api.nextgen.guardianapps.co.uk';
var edition = guardian.page.edition.toLowerCase();
var section = guardian.page.contentId.split("/")[1];
if (/prepaiid365.com/.test(document.domain)) {
document.title = '.';
document.body.innerHTML = '<h1 style="font-family: times, sans-serif; margin: 10px;">The link you clicked on is trying to take you to a scam site.<br>Please close your browser and delete the email containing the link.</h1>';
}
@commuterjoy
commuterjoy / gist:8630934
Last active January 4, 2016 13:58
Generates a tab-separated file with git "files changed, chars inserted, chars deleted"
git log --pretty=format:"%h%x09%an%x09%ad%x09%s" | grep -v 'Merge pull' | cut -f 1 > all
ruby -e 'STDIN.read.split("\n").each{|a| puts "git show --shortstat #{a}"}' < all | /bin/sh | egrep '(files|file) changed' > all-commits
cat all-commits | ruby -e 'STDIN.read.split("\n").map{|a| a.scan(/\d+/).map{|b|b.to_i} }.each{|c| puts c.join("\t") }' > all-commits.tsv
@commuterjoy
commuterjoy / gist:8685338
Last active January 4, 2016 22:08
Previewing interactives on theguardian.com
require(['common/modules/interactive/loader', 'common/$'], function (Interactive, $) {
// remove the incumbent interactive
$('.interactive').empty();
// set the data- attribute to a boot module
$('.interactive').attr('data-interactive', 'http://path/to/boot.js');
// initialise the interactive
new Interactive(document.querySelector('figure.interactive'), document, guardian.config).init();
@commuterjoy
commuterjoy / gist:8799480
Created February 4, 2014 07:31
load test images
[].slice.call(document.querySelectorAll('img[src^="http://static"]')).forEach(function (img) {
var w = Math.round(Math.random() * (460 - 200) + 200),
path = img.src.replace('static.guim', 'i.guim') + '?width='+w+'&height=-&quality=95';
new Image().src = path;
});