Skip to content

Instantly share code, notes, and snippets.

View JonnoFTW's full-sized avatar
⚔️
Fighting off bugs with a sword 🤺

Jonathan Mackenzie JonnoFTW

⚔️
Fighting off bugs with a sword 🤺
View GitHub Profile
@JonnoFTW
JonnoFTW / large-file-hash.py
Last active August 23, 2023 07:01 — forked from aunyks/large-file-hash.py
Hash a large file in Python
import hashlib as hash
# Specify how many bytes of the file you want to open at a time
BLOCKSIZE = 1024 * 1024 * 8 # 8mb
def hash_file(fname: str):
sha = sha256()
with open(fname, 'rb') as fh:
while buff := fh.read(BLOCKSIZE):
sha.update(buff)
#!/usr/bin/python2
#####################################NOTICE######################################
### This program is free software: you can redistribute it and/or modify ###
### it under the terms of the GNU General Public License as published by ###
### the Free Software Foundation, either version 3 of the License, or ###
### (at your option) any later version. ###
### This program is distributed in the hope that it will be useful, ###
### ###
### but WITHOUT ANY WARRANTY; without even the implied warranty of ###
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ###
@JonnoFTW
JonnoFTW / index.html
Created December 21, 2022 00:33
aigame
<html>
<head>
<title>AI vs Old Master</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<style>
@import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap');
body {
@JonnoFTW
JonnoFTW / environment.yaml
Created August 23, 2022 00:02
Stable-Diffusion environment
name: sdm
channels:
- pytorch
- conda-forge
- defaults
dependencies:
- _libgcc_mutex=0.1=conda_forge
- _openmp_mutex=4.5=2_kmp_llvm
- abseil-cpp=20211102.0=h27087fc_1
- absl-py=1.2.0=pyhd8ed1ab_0
from PIL import Image
import numpy as np
import pyprind
import random
import os
import pygame
from collections import defaultdict, Counter
class MarkovChain(object):
@JonnoFTW
JonnoFTW / s3-sane.js
Created November 11, 2021 06:18
Somewhat saner aws sdk
const s3 = require('@aws-sdk/client-s3')
class SaneS3 {
constructor(...args) {
this.client = new s3.S3Client(...args)
}
}
Object.entries(s3).forEach((entry) => {
let [name, fn] = entry
@JonnoFTW
JonnoFTW / img2term.py
Created August 10, 2018 02:45
Convert images to terminal colours
#!/usr/bin/python
# -*- coding: utf-8 -*-
from PIL import Image
mem = {}
cols = {0:(0, 0, 0),1:(128, 0, 0),2:(0, 128, 0),3:(128, 128, 0),4:(0, 0, 128),5:(128, 0, 128),6:(0, 128, 128),7:(192, 192, 192),8:(128, 128, 128),
9:(255, 0, 0),10:(0, 255, 0),11:(255, 255, 0),12:(0, 0, 255),13:(255, 0, 255),14:(0, 255, 255),15:(255, 255, 255),216:(0, 0, 0, 0),16:(0, 0, 0),
17:(0, 0, 95),18:(0, 0, 135),19:(0, 0, 175),20:(0, 0, 215),21:(0, 0, 255),22:(0, 95, 0),23:(0, 95, 95),24:(0, 95, 135),25:(0, 95, 175),26:(0, 95, 215),
27:(0, 95, 255),28:(0, 135, 0),29:(0, 135, 95),30:(0, 135, 135),31:(0, 135, 175),32:(0, 135, 215),33:(0, 135, 255),34:(0, 175, 0),35:(0, 175, 95),
36:(0, 175, 135),37:(0, 175, 175),38:(0, 175, 215),39:(0, 175, 255),40:(0, 215, 0),41:(0, 215, 95),42:(0, 215, 135),43:(0, 215, 175),44:(0, 215, 215),
45:(0, 215, 255),46:(0, 255, 0),47:(0, 255, 95),48:(0, 255, 135),49:(0, 255, 175),50:(0, 255, 215),51:(0, 255, 255),52:(95, 0, 0),53:(95, 0, 95),
@JonnoFTW
JonnoFTW / eye_eeg.py
Created August 31, 2018 04:57
Predicting Eye Open/Closed State Using Keras LSTM
import pandas as pd
from keras import Sequential
from keras.layers import LSTM, Dense, Dropout, Activation
import numpy as np
from matplotlib import pyplot
def get_data():
data = pd.read_csv('eeg_data.csv')
return data[data.apply(lambda x: np.abs(x - x.median()) / x.std() < 4).all(axis=1)]
@JonnoFTW
JonnoFTW / en_au_dict.js
Last active January 21, 2021 19:18
Australian English Dictionary javascript dictionary with no proper nouns
var Dictionary = new Set([
"a",
"aah",
"aardvark",
"aardvarks",
"ab",
"aback",
"abacus",
"abacuses",
"abaft",
@JonnoFTW
JonnoFTW / main.py
Created February 21, 2020 02:45
sqlalchemy has no base
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
from models import User
def create_app(config=None):
app = Flask("testing")
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite://"