Skip to content

Instantly share code, notes, and snippets.

View EteimZ's full-sized avatar

Youdiowei Eteimorde EteimZ

View GitHub Profile
@EteimZ
EteimZ / multiconn-client.py
Created December 29, 2023 10:15
Code snippet demeonstrating multi connection with python sockets.
import sys
import socket
import selectors
import types
# Create you selector that will
# be used for IO multiplexing
sel = selectors.DefaultSelector()
# Client messages
messages = [b"Message 1 from client", b"Message 2 from client"]
@EteimZ
EteimZ / incr.c
Created November 27, 2023 12:16
Demonstraing passing by reference in C.
#include <stdio.h>
void incr(int *x){
*x += 1;
}
int main(){
// initialize i to be equal to 6
int i = 6;
printf("i = %d\n", i);
# CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(EchoServerClient)
# Server executable
add_executable(server server.c)
# Client executable
add_executable(client client.c)
@EteimZ
EteimZ / http_client.c
Created November 25, 2023 15:27
A simple http client with C.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#define MAX_BUFFER_SIZE 1024
//Function prototypes:
@EteimZ
EteimZ / snprintf.c
Created November 25, 2023 11:29
Example program showing how to use the snprintf
#include <stdio.h>
int main() {
// Create a buffer
char helloBuffer[50];
// Using snprintf to create the "Hello, World" string
snprintf(helloBuffer, sizeof(helloBuffer), "Hello, %s!\n", "World");
printf("%s", helloBuffer);
@EteimZ
EteimZ / pipe.c
Created November 24, 2023 22:07
A simple example demonstratin piping in C
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
int main() {
int pipefd[2]; // File descriptors for the pipe
// Create the pipe
@EteimZ
EteimZ / fork.c
Created November 24, 2023 21:57
Simple example of using fork in C.
#include <stdio.h>
#include <unistd.h>
int main() {
pid_t pid = fork();
if (pid == -1) {
perror("Fork failed");
return 1;
}
@EteimZ
EteimZ / dom.py
Created November 11, 2023 17:44
Experimenting with the DOM in python
from html.parser import HTMLParser
class SimpleHTMLParser(HTMLParser):
def __init__(self):
super().__init__()
self.dom_tree = []
def handle_starttag(self, tag, attrs):
element = {'tag': tag, 'attributes': dict(attrs), 'content': []}
if not self.dom_tree:
@EteimZ
EteimZ / simple_async_webserver.py
Created November 10, 2023 20:39
A simple webserver built with asyncio
import asyncio
async def handle_request(reader, writer):
data = await reader.readuntil(separator=b"\r\n\r\n")
message = data.decode()
addr = writer.get_extra_info('peername')
print(f"Received request from {addr}")
print(f"Send response.")
@EteimZ
EteimZ / index.js
Created November 6, 2023 21:33
Cookie based Authentication in vanilla node js
const http = require('http');
const fs = require('fs');
const url = require('url');
// Simulated user data
const users = [
{ id: 1, username: 'john_doe', password: 'password123' },
{ id: 2, username: 'jane_smith', password: 'example456' }
];