Skip to content

Instantly share code, notes, and snippets.

View horvatha's full-sized avatar

Árpád Horváth horvatha

View GitHub Profile
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}"
@horvatha
horvatha / szoszamlalo.py
Last active March 25, 2021 07:43
Szóstatisztikát készít
from collections import Counter
with open('szavak.txt', encoding="utf-8") as f:
szavak = f.read().split()
ossz = len(szavak)
szamlalo = Counter(szo for szo in szavak)
for szo, darab in szamlalo.most_common(8):
print(f"{darab/ossz*100:5.2f}% {szo} ")
@horvatha
horvatha / loader_factory.py
Last active December 30, 2020 09:22
Decorator for registering a function with key. It was wrong (until version 3), but now it works, thanks Real Python and Kryssz90
import functools
import unittest
from typing import Callable
class LoaderFactory:
def __init__(self) -> None:
self.registered_functions = dict(
)
with open("naplo.txt") as f:
lines = f.readlines()
hi = []
for l in lines:
if l[0] != '#':
hi.append(l)
print(f'A naplóban {len(hi)}')
# Ugyanezt csinálja, list comprehension néven kereshetsz rá
@horvatha
horvatha / kvarcora4.py
Last active November 18, 2020 11:11
IT megmérettetés 2020, Nyelvfüggetlen programozás és adatbáziskezelés (SAP), 4. forduló feladata
import unittest
def clock():
maxdiff_ = 90
for h in range(12):
for m in range(60):
for s in range(60):
current_diffs = diffs(h, m, s)
current_maxdiff = maxdiff(current_diffs)
@horvatha
horvatha / kvarcora4.py
Last active November 18, 2020 11:12
Hibás változat IT megmérettetés 2020, Nyelvfüggetlen programozás és adatbáziskezelés (SAP), 4. forduló feladata
import unittest
def clock():
maxdiff_ = 90
for h in range(12):
for m in range(60):
for s in range(60):
current_diffs = diffs(h, m, s)
current_maxdiff = maxdiff(current_diffs)
@horvatha
horvatha / A1_WikiTable_Composers_21st_century.ipynb
Last active October 20, 2020 05:32
Fetching from wikipedia
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@horvatha
horvatha / composers_21_century.csv
Created October 20, 2020 05:28
Fetching data from wikipedia article's table
article name birth death nationality notable_21_century_works era
Cassandra_Miller Cassandra Miller 1976 Canadian About Bach (string quartet) 21st-century classical
Caio_Fac%C3%B3 Caio Facó 1992 Brazilian Diário das Narrativas Fantásticas: Uma fantasia sobre a história da América do Sul (for chamber orchestra)[1] 21st-century classical
Rolf_Riehm Rolf Riehm 1937 German Sirenen (opera) 21st-century classical
Hiro_Fujikake Hiro Fujikake 1949 Japan Pastoral Fantasy (1975),The Rope Crest (1977), Symphony Japan(1993), Symphony IZUMO(2005) 21st-century classical
Ann_Cleare Ann Cleare 1983 Irish Claustrophobia (orchestra) 21st-century classical
Sarah_Hutchings Sarah Hutchings 1984 American 21st-century classical
Peter_Seabourne Peter Seabourne 1960 English Steps piano cycle series – 6 volumes 21st-century classical
Eric_Salzman Eric Salzman 1933 2017 American The True Last Words of Dutch Schultz (opera) 21st-century classical
Johannes_Kreidler Johannes Kreidler 1980 German Fremdarbeit 21st-century classic
@horvatha
horvatha / TSplit.txt
Created September 9, 2020 07:40
TSplit results comparison
This file has been truncated, but you can view the full file.
uloc=RTP, NC & around the world
new TSplit: ['rtp', 'nc', '&', 'around', 'the', 'world']
old TSplit: ['rtp,', '&', 'around', 'nc & around the world', 'world', 'rtp', 'the', 'nc']
uloc=SOUTHERN CAMEROONS
new TSplit: ['southern', 'cameroons']
old TSplit: ['cameroons', 'southern', 'southern cameroons']
uloc=Bhopal, Madhya pradesh, India
new TSplit: ['bhopal', 'madhya', 'pradesh', 'india']
old TSplit: ['bhopal,', 'india', 'pradesh,', 'madhya pradesh', 'bhopal', 'madhya']
uloc=Malibu, CA
for root, _, files in os.walk("."):
print('root: ', root)
for file in files:
if file.endswith(".py"):
with open(os.path.join(root, file)) as f:
b = f.read()
print(file, b.count('\n'))