Skip to content

Instantly share code, notes, and snippets.

View HacKanCuBa's full-sized avatar
⛷️
Also in gitlab.com/hackancuba

Iván || HacKan HacKanCuBa

⛷️
Also in gitlab.com/hackancuba
View GitHub Profile
@HacKanCuBa
HacKanCuBa / blake2signer.py
Last active December 6, 2022 00:04
Blake2Signer: use BLAKE2 in keyed hashing mode to sign and verify data. DEPRECATED BY https://blake2signer.hackan.net | https://gitlab.com/hackancuba/blake2signer | https://pypi.org/project/blake2signer
# ---
# DEPRECATED BY: https://gitlab.com/hackancuba/blake2signer
# ---
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# by HacKan (https://hackan.net), 2020.
# This software is provided as-is. You are free to use, share, modify
# and share modifications under the terms of that license, even with
@HacKanCuBa
HacKanCuBa / minisign.pub
Last active September 20, 2020 22:51
My minisign public key (cross posted as a snippet https://gitlab.com/-/snippets/2017082 )
untrusted comment: HacKan minisign public key 8FE49E3814424F5C
RWRcT0IUOJ7kj6AFLyI3pHmT6dhr+WN8C2FR6HguMmEK0MnsSImqSmjg
@HacKanCuBa
HacKanCuBa / encoder.py
Last active January 20, 2022 15:01
Encode with custom alphabet
def encode_int(number: int, *, alphabet: bytes) -> bytes:
"""Encode given number using the characters from the alphabet."""
if number < 0:
raise ValueError('number must be positive')
if len(alphabet) != len(set(alphabet)):
raise ValueError('characters in the alphabet must be unique')
if number == 0:
return alphabet[0:1]
@HacKanCuBa
HacKanCuBa / logo_turtle.py
Last active July 17, 2023 20:11
Logo (programming language) turtle excercise
"""Logo (programming language) turtle exercise."""
import typing
import unittest
from dataclasses import dataclass
from enum import Enum
from itertools import zip_longest
from unittest import TestCase
@HacKanCuBa
HacKanCuBa / pickle_deal.py
Created March 1, 2022 21:54
How pickle changes according to how the interpreter gets called
"""Pickle dumps test.
When pickle dumps a class, it will include the FQDN for the module. In this example,
we see how an imported class gets dumped including its module information, whereas
a local one has the current module name, which could be `__main__` or other depending
on how the interpreter was called!
If you save this file as `pickle_deal.py` and then in a python terminal you import it
`import pickle_deal`, you will see the following printed:
b'\x80\x04\x95)\x00\x00\x00\x00\x00\x00\x00\x8c\x0bpickle_deal\x94\x8c\x07Decimal\x94\x93\x94\x8c\x07123.456\x94\x85\x94R\x94.'
@HacKanCuBa
HacKanCuBa / sqlalchemy_helpers.py
Last active March 17, 2024 07:04
SQLAlchemy handy helper functions
import functools
from contextlib import asynccontextmanager, contextmanager
from time import monotonic
from typing import Annotated, Any, AsyncGenerator, Generator, Hashable, Iterable, Literal, Optional, Sized, Union, overload
from sqlalchemy import event
from sqlalchemy.dialects.mysql.asyncmy import AsyncAdapt_asyncmy_cursor
from sqlalchemy.engine import URL, Connection, Engine, Row, create_engine
from sqlalchemy.ext.asyncio import AsyncEngine, AsyncSession, async_sessionmaker, create_async_engine
from sqlalchemy.orm import Session, sessionmaker
@HacKanCuBa
HacKanCuBa / cache_helpers.py
Last active March 17, 2024 07:04
Cache handy helpers
"""Handy cache helpers.
These are not yet production ready, as I haven't toroughly tested them, but close.
---
Mandatory license blah blah:
Copyright (C) 2023 HacKan (https://hackan.net)
This Source Code Form is subject to the terms of the Mozilla Public