Skip to content

Instantly share code, notes, and snippets.

⚔️
Fighting off bugs with a sword

Jonathan Mackenzie JonnoFTW

⚔️
Fighting off bugs with a sword
Block or report user

Report or block JonnoFTW

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@JonnoFTW
JonnoFTW / mnist.py
Created Jun 26, 2019
mnist with pygame
View mnist.py
#!/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 Feb 25, 2019 — forked from alojzije/connectHTMLelements_SVG.png
Connect two elements / draw a path between two elements with SVG path (using jQuery)
View trie.py
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
View results
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
View shuffle.cl
__kernel void shuffle_data(
const __global float* data, // array to be shuffled
const __global uint2* swaps // array of swaps to perform
) {
const int gid = get_global_id(0);
const int field = get_global_id(1);
const int num_fields = get_global_size(1);
// swap row r1 with r2 from swaps[gid]
uint2 swap = swaps[gid];
const int r1 = num_fields* swap.x + field;
@JonnoFTW
JonnoFTW / eye_eeg.py
Created Aug 31, 2018
Predicting Eye Open/Closed State Using Keras LSTM
View eye_eeg.py
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)]
View dota2_liquid_analyser.py
#!/usr/bin/env python
import os
import json
import time
import pandas as pd
import requests
from mlxtend.preprocessing import TransactionEncoder
from mlxtend.frequent_patterns import apriori
@JonnoFTW
JonnoFTW / img2term.py
Created Aug 10, 2018
Convert images to terminal colours
View img2term.py
#!/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 / _Running.md
Last active Jul 21, 2018
Simple image/show hide on button press
View _Running.md
  1. Make a folder for the app
  2. Put app.py in the folder
  3. Make a static folder and put index.html in it
  4. Should look like:
lamp/
  app.py
  static/
    index.html
@JonnoFTW
JonnoFTW / __init__.py
Last active Jul 12, 2018
Pymongo Tab for pyramid debugtoolbar
View __init__.py
from pyramid.authentication import AuthTktAuthenticationPolicy
from pyramid.authorization import ACLAuthorizationPolicy
from pyramid.config import Configurator
from pyramid.csrf import CookieCSRFStoragePolicy
from pyramid.security import unauthenticated_userid
from urllib.parse import urlparse
from pymongo import MongoClient
from flex.mongo_toolbar import MongoToolbar, DebugMongo
def main(global_config, **settings):
You can’t perform that action at this time.