Skip to content

Instantly share code, notes, and snippets.

View geryxyz's full-sized avatar

Gergő Balogh geryxyz

View GitHub Profile
@geryxyz
geryxyz / coverage matrix.tex
Last active November 24, 2023 07:43
LaTeX rendering of a test-coverage matrix for scientific papers
\usepackage{nicematrix} % https://ctan.org/pkg/nicematrix?lang=en
\begin{NiceMatrixBlock}[auto-columns-width]
\[
\begin{array}{cccc}
& n\text{ source code items} & & m\text{ tests} \\
C = &
\begin{bNiceMatrix}
c_{1,1} & c_{1,2} & \cdots & c_{1,n} \\
c_{2,1} & c_{2,2} & \cdots & c_{2,n} \\
import httpx as httpx
from fastapi import FastAPI
app = FastAPI()
async def _get_security_score():
url = "https://google.com"
async with httpx.AsyncClient() as client:
response = await client.get(url)
return response.text
@geryxyz
geryxyz / _logging_decorators.py
Last active January 5, 2023 15:38
Logging decorators
import logging
import os
from subprocess import CompletedProcess
import subprocess
def uvicorn_logger():
return logging.getLogger('uvicorn')
def _get_similar_ones(data: pandas.DataFrame, x_name, y_name, index):
return data[(data[x_name] == data.iloc[index][x_name]) & (data[y_name] == data.iloc[index][y_name])]
def circular_layout(data: pandas.DataFrame, x_name, y_name, x_offset, y_offset, radius):
data[x_offset] = None
data[y_offset] = None
for index, row in data.iterrows():
if not pandas.isnull(data.iloc[index][x_offset]) and not pandas.isnull(data.iloc[index][y_offset]):
continue
from textwrap import TextWrapper
class LineSafeTextWrapper(TextWrapper):
def fill(self, text: str) -> str:
return '\n'.join(['\n'.join(self.wrap(line)) for line in text.splitlines() if line.strip() != ''])
import logging
from typing import Callable
class LambdaFormatter(logging.Formatter):
def __init__(
self,
fmt,
pre_format_func: Callable[[logging.LogRecord], logging.LogRecord] = lambda text: text,
post_format_func: Callable[[str, logging.LogRecord], str] = lambda text, _: text
<script src="https://momentjs.com/downloads/moment-with-locales.js"></script>
<script src="https://momentjs.com/downloads/moment-timezone-with-data-10-year-range.js"></script>
<script type="text/javascript">
let my_zone = moment.tz.guess(true);
function my(date, duration_text) {
let conf_date = moment.tz(date, "CET");
let my_date = moment(conf_date).tz(my_zone);
let duration = moment.duration(duration_text);
@geryxyz
geryxyz / production.py
Created February 28, 2022 19:07
Decouple test cases from system under test
import pytest
class ClassA(object):
def apply(self, *args):
return 42
class ClassB(object):
def apply(self, *args):
@geryxyz
geryxyz / main.py
Created February 7, 2022 08:06
Hinting system skeleton/proof of concept/demo for pytest
import pytest
import typing
# add more hint properties as you wish...
def hint(id: str, name: typing.Optional[str] = None):
def _hint(fn: typing.Callable):
fn.hint_id = id
fn.hint_name = name if name is not None else id
return fn
@geryxyz
geryxyz / wtf-abbr.py
Created November 3, 2021 17:01
WTF Abbreviation Finder
import argparse
import sys
def main():
"""
python wtf-abbr.py --abbr WTF --long "would you like to find the perfect abbreviation"
WTF abbreviation found!
Would you like To Find the perfect abbreviation
^ ^ ^