Skip to content

Instantly share code, notes, and snippets.

Tom Morris tommorris

Block or report user

Report or block tommorris

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
tommorris /
Created May 19, 2020
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 / JSON-LineOriented.json.groovy
Last active Nov 29, 2019
a really hacky version of DataGrip's JSON-Groovy.json.groovy to emit "line-oriented" JSON
View JSON-LineOriented.json.groovy
* Available context bindings:
* COLUMNS List<DataColumn>
* ROWS Iterable<DataRow>
* OUT { append() }
* FORMATTER { format(row, col); formatValue(Object, col) }
* where:
tommorris / query_tubes.sparql
Created Nov 1, 2019
SPARQL query to extract all London Underground lines (not Overground or Crossrail etc.)
View query_tubes.sparql
SELECT DISTINCT ?item ?itemLabel ?adj ?adjLabel ?line ?lineLabel
?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 /
Last active Jun 15, 2019
Little code sample for blog post
def prefix_check(url):
for prefix in PREFIXES:
if url.startswith(prefix):
return url
return ""
tommorris /
Created Jun 7, 2019
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,
tommorris /
Created Mar 6, 2019
An issue with GitHub Pages settings

I have a site that uses GitHub Pages - 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 /
Created Jan 31, 2019
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()
tommorris / 7segment.scala
Last active Nov 22, 2018
A Scala implementation of tomscott's 7-segment display problem
View 7segment.scala
import scala.util.matching.Regex
val matcher: Regex = "[gkmqvwxzio]".r
def displayableOn7SegmentDisp(str: String) = matcher.findAllIn(str).isEmpty
val filename = "/Users/tom/Desktop/words_alpha.txt"
val words = Source.fromFile(filename).getLines.toStream
val longestWord = words.filter(displayableOn7SegmentDisp).sortWith(_.length > _.length).head
tommorris /
Last active Nov 2, 2018
An example of how to retrieve API keys from 1Password vault
eval $(op signin <yoursubdomain>) # this will prompt you to log in
export NEXMO_API_KEY=$(op get item Nexmo | jq '.details.sections[]? | select(.fields) | .fields[] | select(.t == "key").v')
export NEXMO_API_SECRET=$(op get item Nexmo | jq '.details.sections[]? | select(.fields) | .fields[] | select(.t == "secret").v')
You can’t perform that action at this time.