Skip to content

Instantly share code, notes, and snippets.

View horvatha's full-sized avatar

Árpád Horváth horvatha

View GitHub Profile
I've just returned from EuroPython Conference, and there was a good presentation: "From Jupyter Notebooks to a Python Package: The Best of Both Worlds". If I'm correct the video is not (yet?) on youtube, but the repo and the slides are here.
https://github.com/sesise0307/europython2023-package
I've used to use a similar setup, but I'll do the same (just w/ PyCharm instead of VSCode).
Creating packag(es) from frequently used functionalities.
%load_ext autoreload%autoreload 2
in Jupyter, and then from Jupyter (starting with !) or from commandline
pip install --editable <path>
import fnmatch
import os
import sys
from pathlib import Path
eleresi_ut = Path.home() / "Documents"
minta = 'Co*t*.*'
# good old walk
for root, dirs, files in os.walk(eleresi_ut):
from test_cases import cases
from irish_possessive_golf import f
def test_all():
for i, (x, y, result) in enumerate(cases):
my_result = f(x, y)
assert my_result == result, f"{x}, {y} should give {result}, not {my_result} ({i+1})"
print("All succeeded")
import argparse
from pathlib import Path
import os
def get_latest_file(directory: Path) -> Path:
"""
Finds the most recently modified file in a directory and its subdirectories.
Args:
"""
Solution for
https://adventofcode.com/2022/day/2
first and second half
"""
from typing import List, Callable
RESULT_SCORES = {"draw": 3, "win": 6, "loose": 0}
from functools import partial
import turtle
window = turtle.Screen()
def draw_polygon(sides, color):
turtle.color(color)
angle = 360/sides
for i in range(sides):
@horvatha
horvatha / mozgas_egyenlo_o_haromszog.py
Last active September 2, 2022 19:38
Egy egyenlő oldalú háromszöget nagyít. Az egyik oldalfelező van mindig középen, és két csúcs az egyik átló mentén helyezkedik el. Egy olyan koordinátarendszert használok, ahol a közepe az origó, a tengelyek -1-től egyig mennek. A háromszög csúcsa 1-szeres nagyítás esetén: [(1, 1), (-1, -1), (-sqrt(3), sqrt(3))]. A nagyítást 0.01 és 1.21 között v…
from math import sqrt
from microbit import *
s3 = sqrt(3)
pattern0 = [(1, 1), (-1, -1), (-s3, s3)]
def magnify_by(n):
def transf(x, y):
@horvatha
horvatha / eredmeny.txt
Last active August 6, 2022 13:08
A földhivatal fájljából adatok kinyerése
Ebből indulva https://pastebin.com/raw/nPbzGFmu
az eredmény:
Szakasz: Tulajdonosi adatok
{'Tul.hányad': '1/2', 'Szerz.jogcím': 'adásvétel', 'Név': 'Gipsz Csaba', 'Anyja neve': 'Próba Katalin', 'Jogállás': 'tulajdonos', 'Cím': '4965 MINTA, Kölcsey utca 105'}
{'Tul.hányad': '1/2', 'Szerz.jogcím': 'adásvétel', 'Név': 'Gipsz Csabáné', 'Szül.név': 'Gipsz Éva', 'Anyja neve': 'Minta Borbála', 'Jogállás': 'tulajdonos', 'Cím': '4965 MINTA, Kölcsey utca 105'}
Szakasz: Jogok-tények jogosultjai
{'Jog-tény neve': 'Önálló szöveges bejegyzés', 'Szöveg': 'Lakcímváltozás átvezetése.'}
{'Jog-tény neve': 'Jelzálogjog', 'Név': 'MAGYAR ÁLLAM', 'Cím': '-,'}
{'Jog-tény neve': 'Elidegenítési és terhelési tilalom', 'Név': 'MAGYAR ÁLLAM', 'Cím': '-,', 'Utalások': 'III/14'}
@horvatha
horvatha / loose_transform.py
Last active July 26, 2022 07:45
Loose transformation for pyrsistent. Similar to the transform method, but it works even if there are missing keys.
from typing import List, Callable, Union
from pyrsistent import PVector, PMap, ny, freeze
def loose_transform(structure: Union[PVector,PMap], path: List, command: Callable):
if not path:
return command(structure) if callable(command) else command
key_spec = path[0]
if not callable(key_spec):
def ones(num: int, number_of_bytes: int = 4) -> int:
num_ones = 0
for i in range(number_of_bytes * 8):
if (2 ** i) & num:
num_ones += 1
return num_ones
def ones(num: int) -> int:
bin_string = f"{num:b}"