Skip to content

Instantly share code, notes, and snippets.

View rlapz's full-sized avatar
👀

Arthur Lapz rlapz

👀
View GitHub Profile
@rlapz
rlapz / hello.c
Last active May 31, 2021 22:40
Hello world example in C
#include <stdio.h>
int
main(void)
{
puts("Hello World!");
return 0;
}
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* WARNING!
*
* Horrible linked list :p
*/
@rlapz
rlapz / maxnum.c
Created September 28, 2021 00:28
Finding the biggest number
int
max(int a, int b, int c, int d)
{
int tmp1, tmp2;
tmp1 = (a > b) ? a : b;
tmp2 = (c > d) ? c : d;
return (tmp1 > tmp2) ? tmp1 : tmp2;
}
static int
add_to_pfds(struct server *s, struct sockaddr_storage *addr, const int new_fd)
{
struct pollfd *new_pfd;
struct client *new_cl;
if (s->cl_count > MAX_CLIENTS)
goto err;
/* Resize pdfs and client array */
@rlapz
rlapz / moeproj.c
Created March 8, 2022 08:42
moproj -- Moe Projector
/* moeproj -- Moe Projector
*
* # Example (file contents):
*
* -[ This is title 1 ]-
* This is the body
*
* -[ Title 2 ]-
* boooodyyy
*
@rlapz
rlapz / netsp.c
Last active October 13, 2022 10:02
A simple bandwidth monitor (can monitor multiple network interfaces)
/* netsp - A simple bandwidth monitor (can monitor multiple network interfaces)
*
* Arthur Lapz <rlapz@gnuweeb.org>
*
* MIT License
*/
#include <errno.h>
#include <dirent.h>
#include <fcntl.h>
#include <stddef.h>
@rlapz
rlapz / auto_queue.h
Last active October 19, 2022 10:58
Ring buffer
/*
* Arthur Lapz <rlapz@gnuweeb.org>
*/
#ifndef ___AUTO_QUEUE_H___
#define ___AUTO_QUEUE_H___
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
@rlapz
rlapz / buffer_queue.zig
Last active November 24, 2022 17:52
BufferQueue
const std = @import("std");
const Allocator = std.mem.Allocator;
const Thread = std.Thread;
const Mutex = Thread.Mutex;
const Condition = Thread.Condition;
pub fn BufferQueue(comptime T: type, comptime size: usize) type {
return struct {
allocator: Allocator,
is_alive: bool,
const std = @import("std");
const fmt = std.fmt;
const mem = std.mem;
const io = std.io;
const net = std.net;
const os = std.os;
const log = std.log;
const time = std.time;
const linux = os.linux;
@rlapz
rlapz / fturing.c
Last active April 4, 2023 19:43
liburing exercise
/* compile: cc fturing.c -o fturing -luring -DNDEBUG -O3 */
#include <endian.h>
#include <errno.h>
#include <error.h>
#include <liburing.h>
#include <libgen.h>
#include <netdb.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>