Skip to content

Instantly share code, notes, and snippets.

@nir9
nir9 / server.c
Last active March 27, 2024 21:58
Minimalist Web Server in C on Windows (using winsock) - only for fun, not for production use
#include <winsock2.h>
#include <Windows.h>
#include <stdio.h>
int main()
{
WSADATA wsadata;
WSAStartup(MAKEWORD(2, 2), &wsadata);
SOCKET s = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in addr;
@nir9
nir9 / snake.asm
Created March 2, 2024 19:01
Boot Sector Snake Game in Assembly (MBR Game)
org 0x7c00
video = 0x10
set_cursor_pos = 0x02
write_char = 0x0a
system_services = 0x15
wait_service = 0x86
keyboard_int = 0x16
@nir9
nir9 / client.c
Last active February 15, 2024 23:14
Simple Memory Mapped File Chat in C (Not for production since there is no cleanup and error handling, code is only for fun)
#include <Windows.h>
#include <stdio.h>
int main() {
HANDLE handle = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 256, L"ChatSyncFileMap");
LPVOID address = MapViewOfFile(handle, FILE_MAP_ALL_ACCESS, 0, 0, 0);
HANDLE event = CreateEventW(NULL, FALSE, FALSE, L"ChatSyncEvent");
for (;;) {
@nir9
nir9 / chat-client.c
Created January 14, 2024 00:17
Minimalist Chat Server and Client in C - just for fun, not suitable for production
#include <sys/socket.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <poll.h>
#include <unistd.h>
int main() {
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in address = {
@nir9
nir9 / gui_win.c
Created January 8, 2024 20:54
Simple GUI Window App for Windows - not for production, only for fun
#include <Windows.h>
LRESULT WinProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch (uMsg) {
case WM_PAINT:
HDC hDc = GetDC(hWnd);
RECT rect = {
75,
75,
250,
@nir9
nir9 / gui.c
Created January 7, 2024 15:16
Simple X11 Window Creation in C - Not for production, only for fun (gcc gui.c -lX11)
#include <X11/Xlib.h>
int main() {
XEvent event;
Display* display = XOpenDisplay(NULL);
Window w = XCreateSimpleWindow(display, DefaultRootWindow(display), 50, 50, 250, 250, 1, BlackPixel(display, 0), WhitePixel(display, 0));
XMapWindow(display, w);
XSelectInput(display, w, ExposureMask);
for (;;) {
@nir9
nir9 / server.c
Created December 20, 2023 18:38
Minimalist HTTPS Web Server in C - not for production use, only for fun :)
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <openssl/ssl.h>
#include <stdio.h>
#include <string.h>
void main() {
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
@nir9
nir9 / hexeditor.c
Last active December 24, 2023 17:49
Minimalist C Hex Editor - Not for production use, just for fun :) -- Notice: This editor will truncate files that are bigger than 1024 bytes --
#include <stdio.h>
#include <stdbool.h>
void print_hex(unsigned char* buffer, int num) {
for (int i = 0; i < num; i++) {
if (i % 10 == 0) {
printf("\n");
}
printf("%.2X ", buffer[i]);
@nir9
nir9 / snake.c
Created December 10, 2023 22:34
Minimalist C Snake Game (using ncurses lib) - Not for production, just for fun :)
#include <curses.h>
#include <stdlib.h>
#include <unistd.h>
void main() {
WINDOW* win = initscr();
keypad(win, true);
nodelay(win, true);
int posX = 0;
int posY = 0;
@nir9
nir9 / https-client.c
Created December 5, 2023 10:11
Minimalist C HTTPS Client - Not for production use, only for fun :)
#include <sys/socket.h>
#include <netinet/in.h>
#include <openssl/ssl.h>
#include <string.h>
#include <stdio.h>
void main() {
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in addr = {