Skip to content

Instantly share code, notes, and snippets.

@abdalmoez
abdalmoez / EventCallBackForAllObjectsOfAClass.cpp
Created April 20, 2020 11:03
Creating Event call back for all instance of a class
#include <iostream>
#include <unordered_set>
class TestEvent {
private:
static std::unordered_set<TestEvent*> objects;
std::string m_title;
public:
TestEvent(const std::string& title):m_title (title)
@abdalmoez
abdalmoez / get-enum-string.cpp
Last active February 20, 2020 10:38
Usefull macro to convert enum to string
#include <iostream>
#define STR(p) #p
enum {
Tool,
Main
};
int main()
@abdalmoez
abdalmoez / python-udp-server.py
Created January 12, 2020 12:06
Start udp server and log received packets using python
import logging
import socket
log = logging.getLogger('udp_server')
def udp_server(host='127.0.0.1', port=1234):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@abdalmoez
abdalmoez / python-udp-send-packet.py
Last active January 19, 2024 07:25
Send udp packet using python
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 1234
MESSAGE = "Hello, World!"
print ("UDP target IP:", UDP_IP)
print ("UDP target port:", UDP_PORT)
print ("message:", MESSAGE)
@abdalmoez
abdalmoez / nanoseconds.converter.py
Created January 7, 2020 11:59
Python convert nano seconds to string (hour, minute, seconds, ...)
def nsToStr(nanoseconds):
h=3.6e+12
m=h/60
s=m/60
return str(int(d/h)) +':'+str(int((d%h)/m))+':'+ str(int((d%h)%m/s)) + '.' + str(int((d%h)%m%s))