Skip to content

Instantly share code, notes, and snippets.

@alexnorton
alexnorton / 0_reuse_code.js
Created February 10, 2016 11:32
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
{"head":["<style media=\"screen\">\n .error-message {\n margin-top: 2rem;\n margin-bottom: 2rem;\n padding-top: 2rem;\n padding-right: 32px;\n padding-bottom: 2rem;\n padding-left: 32px;\n background: #f7f7f5;\n border: 1px solid #dbdbdb\n }\n\n .error-message__link {\n color: inherit\n }\n\n .error-message__link:hover,\n .error-message__link:focus {\n color: #255aa9\n }\n\n .gill-sans {\n font-family: 'Gill Sans', 'Gill Sans MT', Calibri, sans-serif;\n font-weight: 300\n }\n\n .gel-trafalgar,\n .trafalgar {\n font-size: 2.25rem;\n line-height: 2.5rem\n }\n\n .no-touch .gel-trafalgar,\n .no-touch .trafalgar {\n font-size: 2rem;\n line-height: 2.25rem\n }\n\n .gel-mb\\+ {\n margin-bottom: 1rem !important\n }\n\n @media (min-width: 37.5em) {\n .gel-pica,\n .pica,\n .cps-include p,\n .cross-promo-footer--ukfs .cross-promo-footer__header-text,\n .vote-message,\n .vote-detail__title,\n .vote-button,\n .sp-story-body .sp-s
@alexnorton
alexnorton / 1-header.json
Last active October 26, 2015 21:44
Example Mozart components
{
"head": [
"<style>body { font-family: \"Helvetica\", \"Arial\", sans-serif; margin: 0; } #header { background-color: #bb1919; color: white; font-size: 48px; padding: 10px 0; font-family: \"Gill Sans\"; text-align: center; }</style>"
],
"bodyInline": "<div id=\"header\">BBC NEWS</div>",
"bodyLast": []
}
@alexnorton
alexnorton / find-orphan-torrents.md
Last active September 23, 2023 05:07
Find Transmission "ophan" torrents

This script will list files and folders in the specified directories that don't belong to torrents currently being managed by Transmission.

This is useful for finding torrents that have been removed from Transmission but haven't had their files deleted from the downloads folder.

#!/bin/bash

DIRECTORIES="/mnt/Disk1/Downloads /mnt/Disk2/Downloads"

grep -Fxv -f \
@alexnorton
alexnorton / gist:66607fe7cca74df3582f
Created February 9, 2015 09:23
Sanitise object keys for insertion into MongoDB

I wanted to store the response from an API call in a MongoDB document collection.

However, some of the keys present in the object hierarchy started with a $ character, which MongoDB doesn't allow.

Therefore I needed a function to recursively iterate through the object hierarchy and replace all instance of $ at the start of key names with a different character – I chose @.

This is what I came up with:

var replaceDollarsAtStartOfKeys = function(obj) {

for (var property in obj) {

@alexnorton
alexnorton / leaflet-bing-ordnance-survey.js
Created August 5, 2014 20:44
Use Bing Maps Ordnance Survey tiles as a Leaflet TileLayer
var BingLayer = L.TileLayer.extend({
getTileUrl: function (tilePoint) {
this._adjustTilePoint(tilePoint);
return L.Util.template(this._url, {
s: this._getSubdomain(tilePoint),
q: this._quadKey(tilePoint.x, tilePoint.y, this._getZoomForUrl())
});
},
_quadKey: function (x, y, z) {
var quadKey = [];