Skip to content

Instantly share code, notes, and snippets.

Avatar
⛰️
Making mountains out of mole hills

Matt Seymour mattseymour

⛰️
Making mountains out of mole hills
View GitHub Profile
@mattseymour
mattseymour / decorators.py
Created Dec 30, 2019
Python timed logger decorator
View decorators.py
import logging
import time
from functools import wraps
from typing import (
Callable,
Optional,
)
@mattseymour
mattseymour / build-instructions
Created May 1, 2017
Build Python 3.6 from source for Ubuntu and Debian
View build-instructions
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 / energy_plan_rate_calculator.py
Created Mar 16, 2016
A small script to calculate energy costs per year
View energy_plan_rate_calculator.py
# 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
View 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();
View Test pac file
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 / xor.py
Created Aug 5, 2015
Python XOR encryption
View xor.py
# Simple XOR encyption
def xor(self, string, key):
return ''.join(chr(ord(x) ^ ord(y)) for x, y in zip(string, cycle(key)))
@mattseymour
mattseymour / gist:25d86505ff46729de5cf
Created Nov 22, 2014
Python - 100 lightbulbs problem
View gist:25d86505ff46729de5cf
"""
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 / gunicorn-initd-script
Last active Aug 14, 2019
Debian gunicorn init.d script
View gunicorn-initd-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 / django-secret-keygen.py
Last active Sep 8, 2022
Django secret key generator
View django-secret-keygen.py
"""
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