Skip to content

Instantly share code, notes, and snippets.

View tommorris's full-sized avatar

Tom Morris tommorris

View GitHub Profile
@tommorris
tommorris / coauthored-by.el
Created December 21, 2021 12:00
A craptastic elisp function I wrote for inserting Git co-authored-by statements in Git commit messages in Emacs Evil mode
(defun add-git-coauthor-string (name email)
"Insert git coauthor string into commit message"
#'(lambda ()
(interactive)
(insert (format "Co-authored-by: %s <%s>" name email))
(message (format "Added coauthor: %s <%s>" name email))))
(setq colleagues '(
("JS" "Jean Smith" "jean.smith@yourcompany.com")
;; Add your frequent collaborators here
@tommorris
tommorris / LetterIntersperser.java
Created November 10, 2020 09:11
A minimal example of modern Java: type inference, streams, static methods as arguments etc.
package org.example;
import java.util.Arrays;
import java.util.Random;
import java.util.function.Function;
import java.util.stream.Collectors;
public class LetterIntersperser {
private boolean def;
@tommorris
tommorris / ast-modify.py
Created May 19, 2020 10:56
supporting code for IAM blog post
def modify_policy(filename, queue_name):
with open(filename, "r") as fh:
policy = json.load(policy)
allowed_queue = [f"arn:aws:sqs:*:*:{queue_name}"]
for idx, statement in enumerate(policy["Statement"])
services = list(set([x.split(":")[0] for x in statement["Action"]]))
if services == ['sqs']:
policy[idx]['Action'] = allowed_queue
return policy
@tommorris
tommorris / JSON-LineOriented.json.groovy
Last active November 29, 2019 15:54
a really hacky version of DataGrip's JSON-Groovy.json.groovy to emit "line-oriented" JSON
/*
* Available context bindings:
* COLUMNS List<DataColumn>
* ROWS Iterable<DataRow>
* OUT { append() }
* FORMATTER { format(row, col); formatValue(Object, col) }
* TRANSPOSED Boolean
* plus ALL_COLUMNS, TABLE, DIALECT
*
* where:
@tommorris
tommorris / query_tubes.sparql
Created November 1, 2019 14:47
SPARQL query to extract all London Underground lines (not Overground or Crossrail etc.)
SELECT DISTINCT ?item ?itemLabel ?adj ?adjLabel ?line ?lineLabel
WHERE
{
?item wdt:P31 wd:Q14562709 .
?item wdt:P197 ?adj .
?item p:P197 ?adjStmt .
?adjStmt pq:P81 ?line .
?line wdt:P361 wd:Q20075 .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
from functools import reduce
import operator
nums = [1, 2, 3, 4, 5]
reduce(operator.add, nums)
@tommorris
tommorris / prefix_check.py
Last active June 15, 2019 12:17
Little code sample for blog post
PREFIXES = ["https://tommorris.org"]
def prefix_check(url):
for prefix in PREFIXES:
if url.startswith(prefix):
return url
return ""
@tommorris
tommorris / qr_function.py
Created June 7, 2019 20:42
Google Cloud Function for creating QR codes
import io
from flask import send_file
import qrcode
def make_qr(data, box_size=10, border=2):
qr = qrcode.QRCode(version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=box_size,
border=border)
qr.add_data(data)
@tommorris
tommorris / issue.md
Created March 6, 2019 21:56
An issue with GitHub Pages settings

I have a site that uses GitHub Pages - offlineapps.info. It used to not serve an HTTPS certificate, but I moved the DNS around today so it is now pointing to GitHub Pages using an ANAME.

The SSL certificate works fine (and Let's Encrypt is a great addition to GitHub Pages), but the UI has a slight issue. I go to the repos Settings page and see this...

screenshot 2019-03-06 at 21 52 14

So I tick the box. A green tick appears.

screenshot 2019-03-06 at 21 53 09

@tommorris
tommorris / function.py
Created January 31, 2019 18:27
Sample Google Cloud function
import nexmo
from flask import jsonify
def send_sms(request):
data = request.get_json()
# NEXMO_API_KEY and NEXMO_API_SECRET are in env vars
# which are set in the Google Cloud function
client = nemxo.Client()