Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / LocateFirstEmptySlotInMap.cpp
Created April 20, 2020 14:09
Get the first empty key in map<int, TValue>
#include <iostream>
#include <map>
template<typename TValue>
int locateFirstAvailableSlot(std::map<int, TValue> my_map)
{
typename std::map<int, TValue>::iterator it;
int expected_value=1;
@abdalmoez
abdalmoez / .bashrc
Last active April 27, 2020 15:39
My config for bashrc
export HISTIGNORE=$'[ \t]*:&:[fb]g:exit' # Don't put duplicate lines in the history.
alias grep='grep --color=always' # show differences in colour
alias ls='ls -h --color=tty' # Dispaly size unit, classify files in colour
alias ll='ls -l' # long list
alias la='ls -A' # all but . and ..
alias l='ls -CF' #
alias cd.='cd ..'
alias cd..='cd ../..'
alias cd...='cd ../../..'
alias cd....='cd ../../../..'
CMD:listbugs(playerid, params[])
{
if(GetFactionType(playerid) != FACTION_FEDERAL)
{
SendClientMessage(playerid, COLOR_GREY, "You can't use this command as you aren't a federal agent.");
return 1;
}
SendClientMessage(playerid, COLOR_GREEN, "Online Bugged players:");
{
...
"problemMatcher": {
"base": "$gcc",
"fileLocation": ["relative", "${workspaceRoot}/builddir"]
}
}
ls -d */ | awk '{print "cd "$0" && git config core.filemode false && cd .."}' > script.sh
chmod +x script.sh
./script.sh
@abdalmoez
abdalmoez / .bashrc
Created July 1, 2020 08:47
cygwin terminal in vsc
[[ ! -z $CWD ]] && cd $CWD
@abdalmoez
abdalmoez / linux-monitoring.sh
Created March 16, 2021 12:15
Display memory, network, CPU and disk usage.
#!/bin/bash
echo CPU_USAGE,TOTAL_MEM,USED_MEM,FREE_MEM,DISK_USAGE,RX-OK,RX-ERR,RX-DRP,RX-OVR,TX-OK,TX-ERR,TX-DRP,TX-OVR,Flg
while true
do
TOTAL_MEM=$(free -m | grep Mem | sed 's/ \+/\t/g' | cut -f2)
USED_MEM=$(free -m | grep Mem | sed 's/ \+/\t/g' | cut -f3)
FREE_MEM=$(free -m | grep Mem | sed 's/ \+/\t/g' | cut -f4)
DISK_USAGE=$(df | grep ploop44294p1 | sed 's/ \+/\t/g' | cut -f5)
CPU_USAGE=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')