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
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
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". }
}
View operator.py
from functools import reduce
import operator
nums = [1, 2, 3, 4, 5]
reduce(operator.add, nums)
@tommorris
tommorris / prefix_check.py
Last active Jun 15, 2019
Little code sample for blog post
View prefix_check.py
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 Jun 7, 2019
Google Cloud Function for creating QR codes
View qr_function.py
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 Mar 6, 2019
An issue with GitHub Pages settings
View issue.md

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 Jan 31, 2019
Sample Google Cloud function
View function.py
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
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
import scala.io.Source
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
println(longestWord)
@tommorris
tommorris / get_nexmo_keys.sh
Last active Nov 2, 2018
An example of how to retrieve API keys from 1Password vault
View get_nexmo_keys.sh
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')
View encoded.txt
SGFwcHkgYmlydGhkYXksIGNVUkwuIFlvdSBhcmUgYW4gZXNzZW50aWFsIHRvb2wuIFdlIGxvdmUgeW91IHRvIGJpdHMuIEtlZXAgYmVpbmcgYW1hemluZy4K
@tommorris
tommorris / lns.pm
Created Aug 30, 2017
Perl source code for lns utility (archived)
View lns.pm
#!/usr/bin/perl
# desc{ a friendly program for making symbolic links }
$VERSION = '2.01'; # Time-stamp: "2008-08-19 19:26:35 AKDT sburke@cpan.org"
=head1 NAME
lns -- a friendly program for making symbolic links
=head1 SYNOPSIS
You can’t perform that action at this time.