Skip to content

Instantly share code, notes, and snippets.

View nocturn9x's full-sized avatar
:octocat:
Coding...

Mattia nocturn9x

:octocat:
Coding...
View GitHub Profile
@nocturn9x
nocturn9x / bubble.py
Created June 10, 2022 09:53
I was bored, so I optimized bubble sort to run around ~2/2.5x faster
from typing import List, TypeVar, Optional
from operator import gt, lt
T = TypeVar("T") # type: ignore
def is_sorted(l: List[T], *, reversed: Optional[bool] = False) -> bool:
if reversed:
op = gt
@nocturn9x
nocturn9x / mizip_util.py
Last active March 20, 2024 19:30
A simple tool to tinker with MiZip Mifare tags. It can generate sector(s) decryption keys as well as modified dump files to alter a tag's balance. If you know what you're doing, you can even use this tool to transform any Mifare 1K/4K tag (and probably others using the same scheme) into a "MiZip-compatible" tag recognizable by vending machines
#!/usr/bin/env python
# Copyright 2021 Mattia Giambirtone & All Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@nocturn9x
nocturn9x / collatz.py
Created August 1, 2021 10:12
A simple script to compute the Collatz sequence (aka the 3n+1 problem), bending the rules a bit to let real numbers into the game
#!/usr/bin/env python3
## This looks like a fun problem
import argparse
from typing import Optional, Union
def gen(n: Union[int, float]) -> Union[int, float]:
"""
Handy generator for the 3n+1
sequence
@nocturn9x
nocturn9x / thread_local.py
Created February 21, 2021 16:00
A naive implementation of thread-local space in pure Python
from threading import RLock, get_native_id
class ThreadSpace:
"""
A naive implementation of thread-local
space in pure Python. All operations on
this object are thread-safe as they internally
acquire and release a thread lock when needed

Keybase proof

I hereby claim:

  • I am nocturn9x on github.
  • I am nocturn9x (https://keybase.io/nocturn9x) on keybase.
  • I have a public key ASC8LRMIpeVf9O8RG9kDpgPCCYpNC7DqyCZAf9cU_o8DRAo

To claim this, I am signing this object: