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
__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 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)]
#!/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 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 / _Running.md
Last active July 21, 2018 04:26
Simple image/show hide on button press
  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 July 12, 2018 07:50
Pymongo Tab for pyramid debugtoolbar
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):
@JonnoFTW
JonnoFTW / __init__.py
Created June 23, 2018 09:08
Pyramid 304 bug
from pyramid.config import Configurator
def main(global_config, **settings):
config = Configurator(settings=settings)
config.add_static_view('static', 'static', cache_max_age=3600)
return config.make_wsgi_app()
@JonnoFTW
JonnoFTW / pqstat.py
Created April 5, 2018 03:07
A python curses script to interactively view SGE qstat output
#!/usr/bin/env python
import curses
import subprocess
import sys
from datetime import datetime
AUTHOR = "Jonathan Mackenzie"
NAME = "pqstat"
def get_qstat(args):
return subprocess.Popen(['qstat']+args,stdout=subprocess.PIPE).communicate()[0]
def main(scr):
@JonnoFTW
JonnoFTW / config.py
Last active February 4, 2018 12:22 — forked from SmashT/config.py
Reddit Dev Flair Bot
# Subreddit to check
subreddit = 'subreddit'
# Mod flair name
mod_flair = 'Developer'
# Credentials, subreddit management required
user_agent = 'UserAgent'
client_id = 'ClientID'
client_secret = 'ClientSecret'
username = 'Username'
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.jonathan.obd_bt.MainActivity"
tools:showIn="@layout/activity_main">