Skip to content

Instantly share code, notes, and snippets.

View wheresrhys's full-sized avatar

Rhys Evans wheresrhys

View GitHub Profile
Install
- We'll never know which resources to cache
- ... apart from (maybe) shared js bundle
- ... but only if the shared js bundle is tied to the sw version
@wheresrhys
wheresrhys / app_head.scss
Last active May 17, 2016 07:45
Critical + all the rest css generation
@import 'n-ui/configure';
@include nUiConfigure((
preset: complete,
buttons: critical,
forms: critical
grid: critical
));
One-way ticket to the http gulag
The app follows the pub/sub model - fastly instances are subscribed to types of surrogate-key
e.g.
Purger.subscribe({
service: process.env.MYFT_PAGE_FASTLY_ID,
types: ['capi3Concept', 'myftApiUserUpdate']
})
for i in $(heroku apps -o financial-times | grep next) ; do echo "$i $(heroku config:get RAVEN_URL --app $i 2> /dev/null)"; done | grep -E 'https.*sentry\.com/(3|4|5|6)'
npm install -g keen-query && kq tsv 'page:view->count()->filter(page.location.type=curated)->group(page.location.path)->filter(page.location.path!~special-reports)->sortDesc()->cutoff(5)' | grep / | sed -E s/' [0-9]+'// | sed -E s/'^\/'/'https:\/\/next.ft.com\/'/ | xargs -n 1 curl -L -H 'Cookie: FT_SITE=NEXT' -s | grep 'sub-header__page-title'
// create template.html in each subdir
ls -f | grep -ve '\.' | grep -v bower | sed -E s/$/'\/template.html'/ | xargs touch
@wheresrhys
wheresrhys / beacon.md
Last active February 24, 2016 09:03
Beacon v2 architecture

How beacon v2 is put together (for maintainers and interested parties)

Beacon v2 has 3 main ideas at its core

keen-query

In Beacon v1 any data analysis involving anything other than `get an event collection, filtered and grouped' involved a lot of complex code. keen-query aims to abstract away the common patterns into a relatively simple syntax. It's worth understanding how it works (see keen-query.md in his gist), but for the purposes of this document it's sufficient to know that

  • Given a string which passes a set of parsing rules (see https://github.com/Financial-Times/keen-query/blob/master/lib/parser.js) an object (kq) is generated which encapsulates either a single call to the keen API, or multiple calls with one or more rules for aggregating them. It may also define post-processing actions to perform on the data once it's fetched from keen.
  • There is an equivalent JavaScript API to the above which can either be used to construct a kq instance from scratch or to create a modified copy of a
@wheresrhys
wheresrhys / logger.js
Last active February 5, 2016 10:40
console.log in legacy devices
// app.js
app.get('/article/log', function (req, res, next) {
console.log.apply(console, ['------------------------------\nClient log:'].concat(JSON.parse(req.query.messages), ['\n------------------------------']));
});
// client.js
window.console = window.console || {};
window.console.log = function (...messages) {
fetch && fetch(`/article/log?messages=${JSON.stringify(messages)}`);
}
@wheresrhys
wheresrhys / keen-query.md
Last active February 3, 2016 21:01
Keen Query architecture (aka what the hell was I thinking)

The keen-query object

This has a number of methods which construct query parameters for keen e.g. .group(), .filter(). These are all shorthands for the various bits of keen urls In addition there are a handful of special methods, the most significant of which are

  • clone, doing exactly as you'd expect
  • getInstance, returns either a clone (if the kq is already populated with data) or this if still constructing an unexecuted query. keen-query objects are immutable once they've fetched data from keen
  • getTable, gets the data retrieved by the keen-query instance
  • print(method) - converts the keen-query to a variety of things e.g a url to query keen directly. Most significantly, for some of the methods (e.g. ascii, json) it will fetch data from keen and render it appropriately
@wheresrhys
wheresrhys / spec.md
Last active January 25, 2016 16:07
keen-query data structure

KeenQuery.wrapData(opts)

Properties of opts

name

Name to give the query. If listed in the alias spreadsheet this will be read from there

interval

For the purposes of formatting dates it's useful to say what the interval bewteen the data points is (e.g. minute, day). Not essential

@wheresrhys
wheresrhys / gist:8aad8d1d9746b94c69be
Created December 5, 2015 16:42
a bit like emmet
describe.only('getDomPath', function () {
function jadeify(string) {
let out = '';
let indent = 0;
string.split('').forEach(char => {
if (char === '|') {
out += `\n${Array(indent + 1).join(' ')}`
} else if (char === '>') {
indent++
@wheresrhys
wheresrhys / promise-log.js
Last active December 1, 2015 11:06
Promise log
/* Example usage
myBuggyPromiseEmitter()
.then(log, log)
.then(followUpCode)
myOtherBuggyPromiseEmitter()
.then(v => log(typeof v, v), log)
.then(followUpCode)
*/