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)
@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
@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 / 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://"
import re
import praw
import prawcore.exceptions
from collections import defaultdict
from itertools import product
from tqdm import tqdm
from pymongo import MongoClient
client = praw.Reddit(client_id='client id', client_secret='client secret', user_agent='gender scraper')
subs = 'askmen','askwomen'
@JonnoFTW
JonnoFTW / mnist.py
Created June 26, 2019 13:55
mnist with pygame
#!/usr/bin/env python
"""
pip install -U pygame numpy tensorflow keras opencv-python
"""
from datetime import datetime
import pygame
import os
import sys
import cv2
@JonnoFTW
JonnoFTW / connectHTMLelements_SVG.png
Created February 25, 2019 05:07 — forked from alojzije/connectHTMLelements_SVG.png
Connect two elements / draw a path between two elements with SVG path (using jQuery)
connectHTMLelements_SVG.png
from pydotplus import graphviz as pydot
class TrieNode:
__slots__ = ('text', 'children', 'is_end')
def __init__(self, letter, is_end=False):
self.text = letter
self.children = {}
self.is_end = is_end
@JonnoFTW
JonnoFTW / results
Last active September 7, 2018 08:30
Rows: 11, cols=1 44 Bytes
CL Took: 0:00:00.003606
NP Took: 0:00:00.000021
Rows: 10, cols=3 120 Bytes
CL Took: 0:00:00.000312
NP Took: 0:00:00.000012
Rows: 10000, cols=1000 40.0 MB
CL Took: 0:00:00.005533
NP Took: 0:00:00.017710
Rows: 50000, cols=1200 240.0 MB