Skip to content

Instantly share code, notes, and snippets.

View mattstibbs's full-sized avatar

Matt Stibbs mattstibbs

  • Digi-M Ltd
  • Kent, UK
View GitHub Profile
@mattstibbs
mattstibbs / validate_nhs_number.py
Last active January 7, 2022 14:51
Validates a given NHS number to ensure it is valid according to the specification
"""
This code checks that an NHS number is of valid format based on the specified calculation and check digit.
It does NOT check that the NHS number is an active, valid NHS number according to the national NHS number database.
Requires: Python 3.6+
"""
# NHS numbers must be ten numerical digits long
nhs_number = "1354554531"
@mattstibbs
mattstibbs / Duplicacy pre-backup script
Last active December 29, 2022 20:48
A pre-backup script for using with Duplicacy backups
#!/bin/bash
# Gather current power status
AC_POWER=`ioreg -l | grep ExternalConnected | cut -d"=" -f2 | sed -e 's/ //g'`
# Gather details about current wifi network
WIFI_NETWORK=`networksetup -getairportnetwork en0 | grep 'Current Wi-Fi Network' | cut -c 24-`
# Specify the name of your home / office wifi network here
HOME_WIFI=my_home_wifi
@mattstibbs
mattstibbs / put_colon_in_offset.py
Created August 17, 2019 16:00
Add a colon to timezone offset when using datetime.strftime
import datetime
original_timestamp = datetime.datetime.now()
# Convert datetime object to a string representation
timestamp_string = original_timestamp.strftime("%Y-%m-%dT%H:%M:%S%z")
print(timestamp_string)
# OUTPUT: 2019-08-17T00:00:00+0000
# Add a colon separator to the offset segment
@mattstibbs
mattstibbs / test_mock_log.py
Created May 21, 2018 07:07
Mocking log line test
def test_log_line_written_ods_code():
u = User('test-username', 'test-password')
client = RestApiClient(u)
identifier = 'A91547'
data = {
'success':
{
'serviceCount': 1,
'services':
[
@mattstibbs
mattstibbs / rul.py
Created October 29, 2017 17:07
RecentyUsedList - code
class RecentlyUsedList():
def __init__(self):
self.list_of_items = []
def __len__(self):
return len(self.list_of_items)
def insert(self, item):
if item in self.list_of_items:
self.list_of_items.remove(item)
@mattstibbs
mattstibbs / tests.py
Created October 29, 2017 17:06
RecentlyUsedList-tests
import unittest
from recently_used_list import RecentlyUsedList
class RULTests(unittest.TestCase):
def setUp(self):
self.rul = RecentlyUsedList()
def test_new_RUL_gives_empty_list(self):
def str2bool(v):
return v.lower() in ("yes", "true", "t", "1")
@mattstibbs
mattstibbs / auth.py
Created March 14, 2017 00:12
A sample basic auth module for Flask
import config as config
from flask import Response, request
from functools import wraps
def check_auth(username, password):
"""This function is called to check if a username /
password combination is valid.
"""
result = (username == config.API_USER and password == config.API_PASS)
@mattstibbs
mattstibbs / keybase.md
Created February 2, 2016 07:19
Keybase Proof

Keybase proof

I hereby claim:

  • I am mattstibbs on github.
  • I am mattstibbs (https://keybase.io/mattstibbs) on keybase.
  • I have a public key ASAkSpGkBuKpwuVmRjuIvRYp5gUC2mRO8iMRRm87hlaGZAo

To claim this, I am signing this object:

Verifying that +mstibbs is my blockchain ID. https://onename.com/mstibbs