Skip to content

Instantly share code, notes, and snippets.

@nir9
nir9 / NoteServer.py
Last active January 8, 2024 05:51
Notes server in python
import socket
import datetime
"""
Instead of header+stuff
just make a function that adds that
"""
def list_to_html(l):
html = ""
@nir9
nir9 / beep.cpp
Last active December 4, 2023 03:43
Beep with a ioctl
#include <stdio.h>
#include <cstdint>
#include <Windows.h>
struct Beep
{
uint32_t freq;
uint32_t duration;
};
@nir9
nir9 / server.c
Created November 25, 2023 16:50
Minimalist C Web Server - not for production use, only for fun :)
#include <sys/socket.h>
#include <string.h>
#include <fcntl.h>
#include <sys/sendfile.h>
#include <unistd.h>
#include <netinet/in.h>
void main() {
int s = socket(AF_INET, SOCK_STREAM, 0);
struct sockaddr_in addr = {
@nir9
nir9 / editor.c
Last active April 21, 2024 01:08
Minimalist Text Editor Written in C for Linux - Just for fun, not for production use :) -- Notice: This editor will truncate files that are bigger than 1024 bytes --
#include <stdio.h>
#include <string.h>
void edit_line(char* buffer, int current_line) {
for (int i = 0; i < current_line; i++) {
buffer = strchr(buffer, '\n') + 1;
}
char* line_end = strchr(buffer, '\n');
char saved[1024] = { 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 = {
@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 / 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 / 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 / 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 / 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,