Skip to content

Instantly share code, notes, and snippets.

View Harduim's full-sized avatar

Arthur Harduim Harduim

View GitHub Profile
@Harduim
Harduim / tsql_datetime_10min_rounder_udf.sql
Last active October 4, 2023 20:13
Datetime 10min based rounder for SQL Server
IF OBJECT_ID (N'[ts_round_base]', N'FN') IS NOT NULL
DROP FUNCTION ts_round_base;
GO
CREATE FUNCTION [dbo].[ts_round_base](@ts datetime, @secs_delta int)
RETURNS DATETIME
AS
-- =============================================
-- Author: Arthur Harduim
-- Description: DATETIME rounding function
--
@Harduim
Harduim / import_submodules.py
Created December 22, 2022 19:28
Import all submodules of a module, recursively, including subpackages
def import_submodules(package, recursive=True):
"""Import all submodules of a module, recursively, including subpackages
:param package: package (name or actual module)
:type package: str | module
:rtype: dict[str, types.ModuleType]
"""
if isinstance(package, str):
package = importlib.import_module(package)
results = {}
@Harduim
Harduim / task_decorator.py
Last active October 28, 2022 13:58
Templated Docker Taskflow Operator
from pendulum import datetime
from airflow.decorators import dag, task
from platform import node
from typing import Optional, Callable, Sequence
from airflow.providers.docker.decorators.docker import _DockerDecoratedOperator
from airflow.decorators.base import task_decorator_factory
class DockerDecoratedOperator(_DockerDecoratedOperator):
from typing import List, Dict
def vaquinha(lista_de_compras: List[list], emails: List[str]) -> Dict[str, int]:
"""Esta função recebe uma lista de compras e uma lista de e-mails e divide de forma
justa o valor total da lista de compras entre os e-mails.
Args:
lista_de_compras (List[list]):
Lista de compras como matriz:
[
@Harduim
Harduim / sonarqube-docker-compose.yml
Created July 14, 2022 14:04 — forked from Warchant/sonarqube-docker-compose.yml
docker-compose file to setup production-ready sonarqube
version: "3"
services:
sonarqube:
image: sonarqube
expose:
- 9000
ports:
- "127.0.0.1:9000:9000"
networks:
@Harduim
Harduim / lsb.py
Created July 1, 2022 17:56
LSB using python, naive implementation vs bitwise black magic.
flags_bytes = ["00000000", "00000001", "00000110", "00000011", "01001100", "10001000"]
flags = [0, 1, 6, 3, 76, 136]
lsb_expected = [0, 1, 2, 1, 4, 8]
def naive_lsb(num):
for i, bit in enumerate(bin(num)[2:][::-1]):
if int(bit) == 1:
return 2**i
from itertools import combinations
from functools import cache
NOTAS = [50, 20, 10, 5, 2]
@cache
def int_div(a, b):
return a // b
from itertools import combinations
def diminishing_combinations(arr: list):
for i in range(len(arr)):
for c in combinations(arr, i):
if len(c) < 1:
continue
yield c
@Harduim
Harduim / patternfly_svgs.py
Last active January 14, 2022 11:03
Prepare PatternFly Design-Kit SVGs to Lucidchart
"""
The PatternFly design-kit symbols are organized is a deep nested folder structure.
In order to create a custom Lucidchart shapes library, one must have all SVG files in a single directory.
This script copies all SVGs to a new folder called "svg" appending the original path to the new filename.
PatternFly design-kit => https://github.com/patternfly/patternfly-design-kit
Linux and Mac only.
"""
@Harduim
Harduim / first.py
Last active December 26, 2022 20:11
from typing import Iterable, TypeVar
T = TypeVar("T")
def first(items: Iterable[T], pred: callable) -> T | None:
return next((i for i in items if pred(i)), None)