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 / sync_to_async.py
Created November 27, 2022 15:19
minimalistic asyncio on synchronous functions that do not support it
import asyncio
def static_hi(this):
"""this function is not asynchronous"""
return this
async def printer():
"""notice arguments are not passed directly"""
"D:\Hry\steamcmd\steamcmd.exe" +login anonymous +app_update 1110390 +exit
start "" "%~dp0ServerHelper.bat" +InternetServer/Ostrava
from numpy.random import seed
from numpy.random import normal
import matplotlib.pyplot as plt
def get_ndist_list(loc=0, scale=1, size=100):
return list(normal(loc=loc, scale=scale, size=size))
def define_x_axis(y_axis):
x_axis = []
@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()