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 / 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")
@hclivess
hclivess / jazyk_lasky.py
Created December 14, 2021 20:25
jazyk_lasky
# coding=utf-8
odpovedi = []
def pokracuj():
print("")
print(input("*Pokračujte stisknutím libovolné klávesy*"))
class Drak:
def __init__(self):
self.hp = 100
class RybiKosik:
def __init__(self):
self.pocet = 0
drak = Drak()
kosik = RybiKosik()
from threading import Thread
import threading
lock = threading.Lock()
import glob
import os.path
#import cookielib
import http.cookiejar
import re
import time
import os
import time
import tweepy
import logging
import glob
import json
import random
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"