Skip to content

Instantly share code, notes, and snippets.

View hclivess's full-sized avatar
🏠
Working from home

Jan Kučera hclivess

🏠
Working from home
View GitHub Profile
@hclivess
hclivess / montequanto.py
Created July 7, 2022 12:47
bitmap quantum montecarlo dirty code
import time
import matplotlib.pyplot as plt
import numpy as np
import scipy.stats as stats
import math
import cairo
class TexasRanger:
@hclivess
hclivess / client.py
Created July 3, 2022 00:54 — forked from nephics/client.py
Test of experimental Tornado feature for a streaming request body handler
#
# Test of experimental Tornado feature for a streaming request body handler, see
# https://github.com/nephics/tornado/commit/1bd964488926aac9ef6b52170d5bec76b36df8a6
#
#
# Client sending file to server
#
import tornado.httpclient as httpclient
@hclivess
hclivess / wm.py
Last active July 2, 2022 18:28
word miner
import random
import requests
import re
def fetch(max_length=12, min_length=6):
title = None
while not title or min_length < len(title) > max_length:
url = "https://en.wikipedia.org/wiki/Special:Random"
mashup = requests.get(url).text
@hclivess
hclivess / check.py
Created June 30, 2022 16:59
check if a specific dictionary entry is within a list of dictionaries
target_list = [{"ip": 1, "ad": 0}, {"ip": 2, "ad": 0}]
s2 = {"ip": 2}
s3 = {"ip": 3}
if s2["ip"] not in [x["ip"] for x in target_list]:
print(f"{s2['ip']} is new")
if s3["ip"] not in [x["ip"] for x in target_list]:
print(f"{s2['ip']} is new")
@hclivess
hclivess / process_termination.py
Created June 28, 2022 21:40
process_termination.py
import signal
import time
import readchar
def handler(signum, frame):
msg = "Ctrl-c was pressed. Do you really want to exit? y/n "
print(msg, end="", flush=True)
res = readchar.readchar()
if res == 'y':
print("")
@hclivess
hclivess / dice_probability.py
Created June 25, 2022 20:47
dice_probability.py
import random
a = [3, 3, 3, 3, 3, 3]
b = [6, 5, 2, 2, 2, 2]
c = [4, 4, 4, 4, 1, 1]
a_wins = 0
b_wins = 0
c_wins = 0
@hclivess
hclivess / Curve25519.py
Created June 21, 2022 01:30
Curve25519.py keygen and signing
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey, Ed25519PublicKey
from cryptography.hazmat.primitives import serialization
def unhex(hexed):
return b''.fromhex(hexed)
def sign(private_key, message):
private_bytes = unhex(private_key)
private_key_raw = Ed25519PrivateKey.generate().from_private_bytes(private_bytes)
signature = private_key_raw.sign(message.encode()).hex()
@hclivess
hclivess / async_url_tester.py
Last active June 30, 2022 16:05
async url tester
import aiohttp
import asyncio
async def test(ip):
async with aiohttp.ClientSession() as session:
async with session.get(ip) as response:
print(f"Running test for: {ip}")
html = await response.text()
@hclivess
hclivess / para.py
Last active June 20, 2022 01:05
Simplest parallel asyncio
import asyncio
import time
async def function1():
await asyncio.sleep(2)
print("a")
async def function2():
print("b")
@hclivess
hclivess / tornado_threaded.py
Last active June 19, 2022 23:32
Simplest possible threaded Tornado server
import tornado.ioloop
import tornado.web
import threading
import time
class ReadHandler(tornado.web.RequestHandler):
def get(self):
self.write("hello world")