Skip to content

Instantly share code, notes, and snippets.

@colmjude
colmjude / iCal.js
Last active August 29, 2015 14:22
iCal dataURL links
window.iCal = function($el) {
var ical = [""];
ical.push("BEGIN:VCALENDAR");
ical.push("VERSION:2.0");
ical.push("PRODID:HTML");
if ( $el.attr("itemtype") === "http://microformats.org/profile/hcalendar#vevent" ) {
ical.push("BEGIN:VEVENT");
@colmjude
colmjude / .babelrc
Last active September 3, 2018 16:12
Base files for static sites/projects
{
"presets": [
["es2015", { "loose":true }]
]
}
@colmjude
colmjude / file-name-clean.py
Created June 27, 2018 08:12
Script to rename files (E.g. 01 - A Travel Shot.jpg to 01-a-travel-shot.jpg)
import os
import sys
import re
import argparse
def cleanFilename(name):
# rremove spaces from " - ", to "-"
name = re.sub(r'\s+\-\s+', '-', name)
name = re.sub(r'\s+', '-', name)
return name.lower()
@colmjude
colmjude / bounce.scss
Last active July 22, 2018 14:44
Scss to show element in landscape orientation. And a bounce animation.
.bounce {
animation: bounce 2s 3;
}
@keyframes bounce {
0% { transform: translateY(0); }
20% { transform: translateY(0); }
30% { transform: translateY(-10px); }
40% { transform: translateY(-5px); }
50% { transform: translateY(5px); }
@colmjude
colmjude / Fetch-govuk-frontend.py
Created September 20, 2018 04:13
Python script to fetch and extract helpful files from alphagov/govuk-frontend
# -*- coding: utf-8 -*-
import sys
import glob
import os
import shutil
from tempfile import TemporaryDirectory
from urllib.request import urlopen, URLError, HTTPError
import zipfile
import pprint
@colmjude
colmjude / sentence_case.html
Last active October 16, 2019 09:36
Jinja macro to capitalise first letter of a string.
{% macro sentence_case(text) %}
{{ text[0]|upper}}{{text[1:] }}
{% endmacro %}
<p>{{ sentence_case(comment) }}</p>
@colmjude
colmjude / pluralise_filter.py
Created October 31, 2019 14:50
Pluralise filter for Jinja
# e.g. pluralise("country", "y", "ies", "2") = "countries"
def pluralise(str, str_off, str_on, count):
strip_count = -1*len(str_off) if len(str_off) > 0 else len(str)
if count > 1:
return str[:strip_count]+str_on
else:
return str
def patch_remote_dataset(name, key):
url="https://github.com/digital-land/boundary-collection/raw/master/index/local-authority-boundary.csv"
try:
# create tmp location
tmp_dir = "data/tmp"
if not os.path.exists(tmp_dir):
os.makedirs(tmp_dir)
tmp_path = csv_path(tmp_dir, "local-authority-boundary")
# fetch file
response = requests.get(url)
@colmjude
colmjude / requirements.txt
Created May 13, 2020 21:39
Python script to take screenshot of webpage and annotate with URL
appdirs==1.4.4
asyncio==3.4.3
Pillow==7.1.2
pyee==7.0.1
pyppeteer==0.2.2
tqdm==4.46.0
urllib3==1.25.9
websockets==8.1
@colmjude
colmjude / twitter.py
Created May 22, 2020 15:11
Loop through list of local authority sites and list links to twitter
#!/usr/bin/env python3
import os
import json
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup
import pandas as pd
def parse_page_for_twitter_links(url):