Skip to content

Instantly share code, notes, and snippets.

View cr0hn's full-sized avatar

cr0hn cr0hn

View GitHub Profile
name: Create Unstable Release
on:
push:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
@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
@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 / 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 / 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 / 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 / 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 / PyInstaller_vs_Nuitka_for_kapow.rst
Created August 5, 2019 13:58
PyInstaller vs Nuitka for Kapow!

Compilations was made in a Docker Ubuntu x64 image. There the results:

Nuikta

Command v1

python3 -m nuitka --follow-imports -j 4 --plugin-enable=multiprocessing kapow.py

@cr0hn
cr0hn / install_docker_ubuntu.sh
Created July 20, 2016 14:00
Bash for install Docker in Ubuntu 16
sudo apt-get update && apt-get -y install linux-image-extra-$(uname -r)
sudo apt-get -y install apt-transport-https ca-certificates
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo deb https://apt.dockerproject.org/repo ubuntu-xenial main > /etc/apt/sources.list.d/docker.list
sudo apt-get update -y
sudo apt-get purge -y lxc-docker
sudo apt-get install -y docker-engine docker-compose
sudo service docker start
init 6
@cr0hn
cr0hn / pub_sub.py
Created June 21, 2016 14:05
Simple producer / consumer using native asyncio Python >= 3.3 module, using non-blocking Queues and non-blocking system commands calls
# -*- coding: utf-8 -*-
import asyncio
@asyncio.coroutine
def cmd_runner(cmd):
# cmd = "ls"
print(cmd)