Skip to content

Instantly share code, notes, and snippets.

View BenjaminEHowe's full-sized avatar

Benjamin Howe BenjaminEHowe

View GitHub Profile
@BenjaminEHowe
BenjaminEHowe / speedtest-csv.sh
Created March 16, 2022 21:51
A shell script to be regularly invoked to monitor the speed of an internet connection using https://www.speedtest.net/apps/cli
#!/bin/bash
OUTPUT_FILE=/home/ben/speedtest-results.csv
HEADER='"timestamp","server name","server id","latency","jitter","packet loss","download","upload","download bytes","upload bytes","share url","download server count"'
START_TS=$(date --iso-8601=s)
SPEEDTEST_LINE=$(/usr/local/bin/speedtest --format=csv)
if [ ! -f "$OUTPUT_FILE" ]; then
echo "$HEADER" > $OUTPUT_FILE
@BenjaminEHowe
BenjaminEHowe / send-gmail.py
Created March 21, 2019 20:29
A Python function to send email using gmail.
#!/usr/bin/env python3
import email
import os
import smtplib
import ssl
import uuid
from email import encoders
from email.mime.base import MIMEBase
/*
* Copyright Benjamin Howe 2018
* This code is released under the CC0 license
* See: https://creativecommons.org/publicdomain/zero/1.0/
*/
package uk.bh96;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Graphics2D;
import re
import requests
import shutil
magazine_url = "https://loopwifi.co.uk/magazines/magazine_assets/TopGear_1801"
# below: from the source of the magazine on the loop website (line 29)
pages = """ <li>publication/ff5d7f958ccbaee04c5757444271f48e/459cf714845df91869e46745465b55f8.jpg</li>
<li>publication/ff5d7f958ccbaee04c5757444271f48e/684b60c1160f9edf97f0f562a5118347.jpg</li>
<li>publication/ff5d7f958ccbaee04c5757444271f48e/419c95840894cd32fe7f3bea098c5e7c.jpg</li>
<li>publication/ff5d7f958ccbaee04c5757444271f48e/45aa32e2261e865d74c8d01aa41e24cc.jpg</li>
@BenjaminEHowe
BenjaminEHowe / perf_transmaths.py
Created November 21, 2017 20:57
A Python script to test the performance of the `transmaths` module.
import operator # https://stackoverflow.com/a/18591859
from fractions import Fraction
from time import time
from transmaths import Transreal
def timed_op(a, op, b, repetitions):
start = time()
for i in range(repetitions):
op(a, b)
@BenjaminEHowe
BenjaminEHowe / isic.php
Created September 18, 2017 21:15
Checks if an ISIC card number is valid.
<?php
function check_isic($number) {
$url = 'https://www.isic.org/verify/';
$data = array('verify_card_number' => $number);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data),
)
@BenjaminEHowe
BenjaminEHowe / protext_decoder.py
Last active November 21, 2017 20:59
This Python code solves a challenge that Bhaskar Tiwari of HackerRank published at http://protext.herokuapp.com/.
#!/usr/bin/python3
import re
import requests
import urllib.parse
print("Setting up...")
ascii_printable = []
for i in range(32, 127): # source: https://stackoverflow.com/a/5891478
ascii_printable += chr(i)
@BenjaminEHowe
BenjaminEHowe / download-theactuary.py
Last active June 3, 2017 22:51
Downloads the PDF archive copies of "The Actuary" magazine - see http://www.theactuary.com/archive/
#!/usr/bin/python3
import re
import requests
import sys
from datetime import datetime
def download_file(url, filename): # source: https://stackoverflow.com/a/16696317
r = requests.get(url, stream=True)
@BenjaminEHowe
BenjaminEHowe / resize-for-android.py
Last active April 23, 2017 12:19
Resizes drawables for Android - this was found to provide ~30% more FPS for a 2nd year Android project I worked on. Place source images in a directory labelled "source". Images will be output into appropriate drawable-* directories for Android. Copyright (c) 2017 Benjamin Howe, released under the MIT license.
import os, shutil
from PIL import Image
outputs = {
"drawable-mdpi": 1,
"drawable-hdpi": 1.5,
"drawable-xhdpi": 2,
"drawable-xxhdpi": 3}
for directory in outputs:
@BenjaminEHowe
BenjaminEHowe / parseLinxData.py
Created February 9, 2017 06:33
Parse LINX Data v1.0 - a script to parse statistical data from the London Internet Exchange
#!/usr/bin/python3
# Parse LINX Data v1.0
# Designed for use with Get LINX Data v1.0
# A script to parse statistical data from the London Internet Exchange
# (C) Benjamin Howe 2017, licensed under the MIT License
# https://opensource.org/licenses/MIT
from datetime import datetime