Skip to content

Instantly share code, notes, and snippets.

View cr0hn's full-sized avatar

cr0hn cr0hn

View GitHub Profile
@cr0hn
cr0hn / Results.txt
Created April 22, 2020 08:53
Analysis of resulting size for different Python data types: dict, classes, classes with __slots__, namedtuples and dataclasses
Number of elements: 10
-----------------------
Dict: 360 bytes # 636 bytes
Namedtuple: 120 bytes # 396 bytes
Class: 48 bytes # 1202 bytes
Class Slots: 48 bytes # 556 bytes
Dataclass: 48 bytes # 468 bytes
@cr0hn
cr0hn / Analysis-results.txt
Created April 24, 2020 13:01
Analysis of performance and memory consumption of pickle vs json
Number of elements: 10
-----------------------
Json Size: 0.02715015411376953 MB
Json time: 0.006659951999999997 sec
UJson time: 0.0030970319999999996 sec
Pickle Size Proto 5: 0.02531909942626953 MB
Pickle time Proto 5: 0.003745575000000001 sec
Pickle Size Proto 4: 0.02531909942626953 MB
Pickle time Proto 4: 0.0031195769999999984 sec
@cr0hn
cr0hn / Serializable.py
Created November 5, 2021 09:20
Superclass that allows to serialise any Python Dataclass
class Serializable:
def _clean_dict_(self,
data = None,
clean_or_raw: str = "clean") -> dict:
# DICT
if type(data) is dict:
ret = {}
@cr0hn
cr0hn / scapy_http_flow.example.py
Last active December 9, 2021 15:41
Scapy HTTP flow builder from a packet list
# Usage example
from scapy.all import *
from scapy.layers.http import *
sport, dport = detect_http_ports(rdpcap(pcap_file))
if sport:
scapy.packet.bind_layers(TCP, HTTP, dport=dport)
scapy.packet.bind_layers(TCP, HTTP, sport=sport)
@cr0hn
cr0hn / mongo_serializable.py
Created October 4, 2022 07:39
Serializable Python class interfaces for MongoDB
class MetaMongo(type):
def __call__(cls, *args, **kwargs):
if "_id" in kwargs:
_id = kwargs.pop("_id")
o = super().__call__(*args, **kwargs)
return o
@cr0hn
cr0hn / openai.py
Last active October 8, 2022 07:59
Python OpenAI API Client WITHOUT ANY external dependency
"""
This file contains code for consuming the OpenAI API without depencies
This code is released under MIT License.
"""
import json
from typing import List
import urllib.request as rq
name: Create Unstable Release
on:
push:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps: