Skip to content

Instantly share code, notes, and snippets.

@Oshawk
Created January 10, 2018 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Oshawk/ce70816ac135fb3dfa48e1e2212d6313 to your computer and use it in GitHub Desktop.
Save Oshawk/ce70816ac135fb3dfa48e1e2212d6313 to your computer and use it in GitHub Desktop.
HT
import hashlib
password = input("Enter password: ").encode()
salt = input("Enter salt: ").encode()
print(hashlib.pbkdf2_hmac('sha512', password, salt, 65536).hex())
import json
class JSONHandler:
def __init__(self, path):
self.path = path
try:
with open(self.path, "r") as f:
json.load(f)
except (FileNotFoundError, ValueError):
with open(self.path, "w") as f:
json.dump([], f)
def __enter__(self):
with open(self.path, "r") as f:
self.json = json.load(f)
return self.json
def __exit__(self, type, value, traceback):
with open(self.path, "w") as f:
json.dump(self.json, f)
jh = JSONHandler("test.json")
with jh as j:
j.append("Test")
import csv
data = [["TESEEET", "TEST2", "TEST3"], ["Test", "Tewst2", "Test3"], ["Test", "Test2", "Test3eee"]]
def print_table(data):
maximums = [max([len(c) for c in r]) for r in data]
formatted = [[c.ljust(maximums[i]) for i, c in enumerate(r)] for r in data]
print(" {} ".format(" | ".join(formatted[0])))
print(" {} ".format("-+-".join(["-" * i for i in maximums])))
[print(" {} ".format(" | ".join(r))) for r in formatted[1:]]
def csv_file(data):
with open("test.csv", "w", newline="") as f:
w = csv.writer(f)
w.writerow(data[0])
w.writerows(data[1:])
def html_file(data):
with open("test.html", "w") as f:
f.write("<table style=\"width:100%\">")
f.write("<tr>")
for i in data[0]:
f.write("<th>{}</th>".format(i))
f.write("</tr>")
for r in data[1:]:
f.write("<tr>")
for c in r:
f.write("<td>{}</td>".format(c))
f.write("</tr>")
f.write("</table>")
print_table(data)
csv_file(data)
html_file(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment