Skip to content

Instantly share code, notes, and snippets.

@GrantTrebbin
GrantTrebbin / si470x_log_processor.py
Created May 10, 2015 09:20
Create a series of images to demonstrate weather related events using python and matplotlib
#!/usr/bin/python
import csv
import sys
from datetime import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.image as image
import matplotlib.lines as mlines
import os.path
@GrantTrebbin
GrantTrebbin / imCompress.py
Created May 21, 2015 13:16
Compressing Similar PNG Images
#!/usr/bin/python
from PIL import Image
import numpy
import argparse
import os
import sys
#Configure argument parser to take input arguments
@GrantTrebbin
GrantTrebbin / MagField.py
Created November 3, 2015 13:18
A quick demonstration of the magnetic field of a circular current loop
import numpy as np
import matplotlib.pyplot as plt
import scipy.special as sp
a = 1.55
current = 1
mu = 4 * np.pi / 10000000
# equal to sqrt(4ra(z^2 + (a+r)^2)^(-1))
def k_val (R, Z):
@GrantTrebbin
GrantTrebbin / orderGraph.py
Created February 28, 2016 14:18
Visualizing Periodic Order Schedules
import random
import math
import sqlite3
import numpy
import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
def order_trajectory(base, colours, trajectory):
scale = 500
day_trajectory = trajectory / 24
@GrantTrebbin
GrantTrebbin / DirHash.ps1
Created October 15, 2016 13:34
Create fingerprints of directories and files that incorporate name and directory structure
function Hex_To_Bytes($hex){
# Takes a string with an even number of hexadecimal characters and
# converts it two characters at a time to an array of bytes half as long
# Initialize ouput byte array
$hexLength = $hex.Length
$byteLength = $hexLength / 2
$bytes = ,0 * ($byteLength)
# generate bytes by taking 2 hexadecimal characters at a time
@GrantTrebbin
GrantTrebbin / Backup.ps1
Last active October 30, 2016 01:19
Create encrypted and compressed backups only when warranted
<#
.SYNOPSIS
Backs up and encrypts a directory or file
.DESCRIPTION
Backs up files or directories by adding it them a tar file and then
encrypting it with a public key. Becuase public key encryption is used
there are no passwords stored anywhere.
gpg must be installed and the public key you want to use must be imported.
@GrantTrebbin
GrantTrebbin / MailStat.py
Created October 19, 2015 09:50
Crudely analyse the emails in an mbox file to generate statistics
import mailbox
from email.header import decode_header
import re
import itertools
regex = re.compile('[^a-zA-Z0-9]')
words = []
for message in mailbox.mbox('Inbox.mbox'):
subject, encoding = decode_header(message['subject'])[0]
@GrantTrebbin
GrantTrebbin / IndexingDemo_BinaryVersion.py
Created March 16, 2017 12:59
Rendering Animations for Hilbert Curves - Undocumented Scratch Code
import svgwrite
import math
# mogrify -format gif *.svg
# gifsicle --scale 0.2 --delay=5 --loop --optimize=2 --colors=256 --multifile *.gif > OutGIF/out.gif
order = 3
number_of_index_bits = order * 2
number_of_elements = pow(2, number_of_index_bits)
x_offset = 130
@GrantTrebbin
GrantTrebbin / LockBox.py
Created May 19, 2017 10:23
Generate sequences to brute force locks with mechaincal pin codes. Works for locks where order of numbers in PIN doesn't matter and numbers can't be repeated.
from itertools import combinations, chain
# https://stackoverflow.com/questions/5920643/add-an-item-between-each-item-already-in-the-list
def intersperse(lst, item):
result = [item] * (len(lst) * 2)
result[0::2] = lst
return result
pins = []
@GrantTrebbin
GrantTrebbin / QRBackup.sh
Last active December 20, 2023 17:54
How to encode and decode a file backed up as a series of printed QR codes
# How to encode and decode a file backed up as a series of printed QR codes
# Install the required tools
sudo apt-get update
sudo apt-get install zbar-tools imagemagick qrencode
################################################################################
# Convert the file to a base 64 encoded format. Probably not needed as QR codes