Skip to content

Instantly share code, notes, and snippets.

View nottrobin's full-sized avatar

Robin Winslow nottrobin

View GitHub Profile
@nottrobin
nottrobin / upload-assets.py
Last active February 17, 2017 21:28
A script for uploading assets in bulk to the Ubuntu assets server (assets.ubuntu.com)
#! /usr/bin/env python3
"""
A command-line tool for uploading assets to the assets server.
The only dependency is `requests`:
$ pip install requests
$ wget https://gist.githubusercontent.com/nottrobin/bad4d1b8f880bbb23ed10f5457d976bc/raw/707305dbd616dc46f38d0524e2f6248415173f57/upload-assets.py
@nottrobin
nottrobin / isSubset.js
Created February 17, 2017 16:47
Check if an array is a subset of another array or nodeList
isSubset = function(subset, superset) {
for (var index = 0; index < subset.length; index++) {
var item = subset[index];
var isInSet = false;
if (
('contains' in superset && !superset.contains(item)) ||
(! 'contains' in superset && superset.indexOf(item) == -1)
) {
return false;
@nottrobin
nottrobin / documentation-builder-format.py
Created February 13, 2017 12:17
Format vanilla documentation files for documentation-builder
#! /usr/bin/env python3
"""
A script to reformat the existing vanilla-framework documentation
(at present: https://github.com/ubuntudesign/vanilla-framework/tree/c3c4d20094da10dff2fe0bf7d52f4a56ecafeaf4/docs)
to be built with documentation-builder.
"""
from glob import glob
import frontmatter
@nottrobin
nottrobin / generate-maas-api-docs.md
Last active February 8, 2017 23:36
Generate MAAS API docs

Generate MAAS API docs

MAAS_BRANCH=trunk

lxc launch ubuntu:16.04 maas

lxc exec maas -- apt update
lxc exec maas -- apt install -y bzr build-essential
@nottrobin
nottrobin / git-force-clone.sh
Created November 8, 2016 09:57
git force-clone: clone a repository; if it already exists locally, reset it to a clone of the remote.
#! /usr/bin/env bash
set -euo pipefail
_usage() {
echo "
Usage:
git-force-clone -b branch remote_url destination_path
Example:
@nottrobin
nottrobin / find-links-with-slash.sh
Created October 4, 2016 18:15
Find internal links in templates that end with a slash
@nottrobin
nottrobin / remove-unmentioned-files.py
Created October 4, 2016 15:32
Remove unmentioned template files on ubuntu.com
"""
A script to be run in the `templates` directory of https://github.com/ubuntudesign/www.ubuntu.com
It will find and remove template includes (_*.html) that aren't mentioned in any other templates.
"""
from os import path, remove
import glob
import re
@nottrobin
nottrobin / parse-markdown-with-frontmatter.py
Created September 23, 2016 09:49
Parse a Markdown file into HTML, which has YAML frontmatter data at the top
import frontmatter # https://pypi.org/project/python-frontmatter/
import markdown # https://pypi.org/project/markdown/
def parse_markdown(filepath):
markdown_parser = markdown.Markdown(extensions=markdown_extensions)
file_parts = frontmatter.load(filepath)
return {
'html': markdown_parser.convert(file_parts.content),
'metadata': file_parts.metadata
@nottrobin
nottrobin / convert-markdown-meta-to-frontmatter.py
Last active September 22, 2016 12:21
Convert metadata from Multimarkdown format into frontmatter format
# This will convert MultiMarkdown metadata at the top of markdown files
# (http://fletcher.github.io/MultiMarkdown-5/metadata.html)
# into the YAML Frontmatter format used by Jekyll and GitHub
# (https://jekyllrb.com/docs/frontmatter/)
# E.g.:
#
# # my-file.md
# 1. Title: MAAS | Metal As A Service
#
mkdir docs-build
pip3 install ubuntudesign.documentation-builder
documentation-builder --destination-folder docs-build --source-repository https://github.com/CanonicalLtd/maas-docs.git
cd docs-build/en
xdg-open index.html # Look at the wonderful HTML documents