Skip to content

Instantly share code, notes, and snippets.

View mattseymour's full-sized avatar
⛰️
Making mountains out of mole hills

Matt Seymour mattseymour

⛰️
Making mountains out of mole hills
View GitHub Profile
@mattseymour
mattseymour / django-secret-keygen.py
Last active September 8, 2022 23:47
Django secret key generator
"""
Pseudo-random django secret key generator.
- Does print SECRET key to terminal which can be seen as unsafe.
"""
import string
import random
from __future__ import print_function
@mattseymour
mattseymour / gunicorn-initd-script
Last active August 14, 2019 06:50
Debian gunicorn init.d script
#!/bin/sh
### BEGIN INIT INFO
# Provides: webapp
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: gunicorn init.d script for ubuntu and debian
# Description: gunicorn init.d script for running gunicorn on ubuntu or debian based systems
# start script using `/etc/init.d/webapp start`
@mattseymour
mattseymour / gist:25d86505ff46729de5cf
Created November 22, 2014 13:13
Python - 100 lightbulbs problem
"""
This is a simple bit of code which solves the 100 lightbulbs problem.
Its not the most efficient but it does the job.
"""
def switch(list_length, iterations):
switches_on = []
switches = { i:False for i in range(1,list_length+1)}
@mattseymour
mattseymour / xor.py
Created August 5, 2015 09:17
Python XOR encryption
# Simple XOR encyption
def xor(self, string, key):
return ''.join(chr(ord(x) ^ ord(y)) for x, y in zip(string, cycle(key)))
function FindProxyForURL(url, host) {
if (dnsDomainIs(host, ".localhost"))
return "DIRECT";
if (url.substring(0, 6)=="https:")
return "DIRECT";
return "PROXY 192.168.100.202:9999";
}
@mattseymour
mattseymour / canvas cloud
Created October 3, 2015 16:28
HTML canvas cloud
canvas = document.getElementById('cloud');
var ctx = cloud.getContext("2d");
ctx.beginPath();
// left
ctx.arc(40,65,40,0,2*Math.PI)
ctx.fillStyle = "rgb(255,255,255)";
ctx.fill();
@mattseymour
mattseymour / energy_plan_rate_calculator.py
Created March 16, 2016 15:29
A small script to calculate energy costs per year
# Cost per units and standard day charge
ELEC_PKWH = 12.2
ELEC_DAILY = 11.420
GAS_PKWH = 2.973
GAS_DAILY = 12.910
# Number of units i use
ELEC_USAGE = 4000
@mattseymour
mattseymour / build-instructions
Created May 1, 2017 06:58
Build Python 3.6 from source for Ubuntu and Debian
Prerequisties install:
- sudo apt-get install build-essential checkinstall
These are the dependancies required by python:
- sudo apt-get install libbz2-dev libc6-dev libgdbm-dev libncursesw5-dev libreadline-gplv2-dev libssl-dev libsqlite3-dev tk-dev
Download the tar source file from python.org (at the time of writing 3.6.1 is the latest release):
- wget -O ~/Downloads/python3.6.1.tgz https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
Via command line navigate to the downloaded file directory:
@mattseymour
mattseymour / decorators.py
Created December 30, 2019 10:59
Python timed logger decorator
import logging
import time
from functools import wraps
from typing import (
Callable,
Optional,
)