Skip to content

Instantly share code, notes, and snippets.

View NHellFire's full-sized avatar

Nathan Rennie-Waldock NHellFire

  • United Kingdom
View GitHub Profile

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@NHellFire
NHellFire / boolparser.py
Created August 27, 2019 19:44 — forked from leehsueh/boolparser.py
Python Boolean Expression Parser/Evaluator
"""
Grammar:
========
Expression --> AndTerm { OR AndTerm}+
AndTerm --> Condition { AND Condition}+
Condition --> Terminal (>,<,>=,<=,==) Terminal | (Expression)
Terminal --> Number or String or Variable
Usage:
======
@NHellFire
NHellFire / copyfileobj.py
Created December 22, 2016 03:20
Python copyfileobj with progress bar
from time import time
import sys
def mksize (bytes):
suffixes = ("B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
suffixesLen = len(suffixes)
for i in range(suffixesLen):
if bytes < pow(1000, i + 1) or i + 1 == suffixesLen:
return "%.2f %s" % (float(bytes) / pow(1024, i), suffixes[i])