Skip to content

Instantly share code, notes, and snippets.

View DavidFricker's full-sized avatar
👽

David DavidFricker

👽
View GitHub Profile
from tqdm import tqdm
from time import sleep
import psutil
with tqdm(total=100, desc='cpu%', position=1) as cpubar, tqdm(total=100, desc='ram%', position=0) as rambar:
while True:
rambar.n=psutil.virtual_memory().percent
cpubar.n=psutil.cpu_percent()
rambar.refresh()
cpubar.refresh()
from keras import backend
from keras.backend import numpy_backend
import numpy as np
import tensorflow as tf
class NPTF(object):
def __getattr__(self, name):
if name in dir(numpy_backend) and name in dir(backend):
@DavidFricker
DavidFricker / tcpproxy.js
Created April 4, 2019 19:32 — forked from kfox/tcpproxy.js
A basic TCP proxy written in node.js
var net = require("net");
process.on("uncaughtException", function(error) {
console.error(error);
});
if (process.argv.length != 5) {
console.log("usage: %s <localport> <remotehost> <remoteport>", process.argv[1]);
process.exit();
}
@DavidFricker
DavidFricker / (terrible) simple python loading bar
Created October 1, 2018 11:08
Displays progress in 1% steps with a big loading bar
import sys
def print_loading_bar(complete, total):
complete_percentage = round((complete/total * 100), 2)
if complete_percentage % 1 == 0:
loading_bar = (['='] * int(complete_percentage)) + (['>']) + (['-'] * (100 - 1 - int(complete_percentage)))
sys.stdout.write("\r" + str(complete_percentage) + "%: "+ ''.join(loading_bar))
sys.stdout.flush()
def classification_report(y_true, y_pred, labels):
'''Similar to the one in sklearn.metrics, reports per classs recall, precision and F1 score'''
y_true = numpy.asarray(y_true).ravel()
y_pred = numpy.asarray(y_pred).ravel()
corrects = Counter(yt for yt, yp in zip(y_true, y_pred) if yt == yp)
y_true_counts = Counter(y_true)
y_pred_counts = Counter(y_pred)
report = ((lab, # label
corrects[i] / max(1, y_true_counts[i]), # recall
corrects[i] / max(1, y_pred_counts[i]), # precision
@DavidFricker
DavidFricker / gist:67319b82b822246f0a1f2c2e60b17b05
Created February 6, 2018 20:11
Puppeter (Chrome) dependencies on Ubuntu 16 LTS
sudo apt-get update
sudo apt-get install libxcomposite-dev -y
sudo apt-get install libxcursor1 -y
sudo apt-get install libxi6 libgconf-2-4 -y
sudo apt-get install libxtst6 -y
sudo apt-get install libnss3-dev -y
sudo apt-get install libcups -y
sudo apt-get install libxss1
sudo apt-get install libxrandr2
@DavidFricker
DavidFricker / large raw binary base conversion php
Created March 21, 2017 23:28
large raw binary base conversion php
/**
Enables alphanumeric encoding and decoding of binary data for easy transportation over any medium
Works using the GMP extension to avoid PHP's base_convert loss of preceision when working with large numbers e.g. a 256 bit key
converts the binary to hex then to an arbitrary base, 62 is best in my experince
*/
class BinaryBaseChanger {
const STORAGE_BASE = 16;
public static function changeTo($binary_data, $base_to) {
$hexadecimal = bin2hex($binary_data);