Skip to content

Instantly share code, notes, and snippets.

View AdriDevelopsThings's full-sized avatar
🎯
Focusing

AdriDevelopsThings AdriDevelopsThings

🎯
Focusing
View GitHub Profile
@AdriDevelopsThings
AdriDevelopsThings / check_zero_filled_mmap.c
Created June 28, 2024 09:25
Check if a new memory page is zero filled
#include <sys/mman.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define PAGESIZE sysconf(_SC_PAGE_SIZE)
int main() {
uint8_t* ptr = (uint8_t*) mmap(NULL, PAGESIZE, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
@AdriDevelopsThings
AdriDevelopsThings / unlimited-download.zig
Created June 21, 2024 20:54
A simple http server that answers all requests with an infinite big file
const std = @import("std");
pub const std_options = .{
.log_level = .info,
};
fn handle_connection(connection: std.net.Server.Connection, filename: []u8) !void {
std.log.info("Client {} connected", .{connection.address});
defer {
connection.stream.close();
@AdriDevelopsThings
AdriDevelopsThings / find.zig
Last active June 20, 2024 19:23
Find a pattern in a file and mark the position
const std = @import("std");
const COLOR_RED = "\x1b[0;31m";
const COLOR_RESET = "\x1b[0m";
fn print_usage(exec: [*:0]u8) void {
std.debug.print("Usage: {s} FILE PATTERN\n", .{exec});
}
fn string_contains_substring(allocator: std.mem.Allocator, string: []u8, substring: []u8) !std.ArrayList([2]usize) {
@AdriDevelopsThings
AdriDevelopsThings / follow.c
Last active June 10, 2024 19:46
This program will print the content of a file and then waits for a change of the file and prints the added content.
/*
* This program will print the content of a file and then waits for a change of the file and prints the added content.
* Author: AdriDoesThings <adri@adridoesthings.com>
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@AdriDevelopsThings
AdriDevelopsThings / su.c
Created May 10, 2024 08:36
Simple su implementation
#include <stdio.h>
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
if (argc < 3) {
fprintf(stderr, "Usage: %s USER COMMAND [ARGS]...\n", argv[0]);
return -1;
}
@AdriDevelopsThings
AdriDevelopsThings / du.c
Created March 1, 2024 00:03
My du implementation
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <sys/stat.h>
off_t* count_filesize_of_directory(char *path) {
DIR *dir = opendir(path);
if (dir == NULL) {
perror("error while reading directory");
@AdriDevelopsThings
AdriDevelopsThings / cat.c
Created February 29, 2024 22:17
My self written cat implementation
#include <stdint.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
int file_index = 0; // index of the current file
while (file_index + 1 < argc || file_index == 0) {
FILE *file; // contains the pointer to the file
if (file_index + 1 == argc) { // no file path is given, use stdin
file = stdin;
} else { // file path is given, argv[file_index + 1] is file path
@AdriDevelopsThings
AdriDevelopsThings / unlimited_download.c
Created February 4, 2024 01:18
A http server written in c that responds to any request with a infinitely large file
#include <asm-generic/errno-base.h>
#include <asm-generic/errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
@AdriDevelopsThings
AdriDevelopsThings / ssh_usernames.txt
Last active December 14, 2023 14:14
A list of usernames that bots used to try authenticate to my ssh server
!root
.log
.syslog
.test
0
000
0000
000000
02
09
@AdriDevelopsThings
AdriDevelopsThings / get_all_vbb_lines.ts
Created September 2, 2023 15:46
Get all VBB lines from vbb.de
import { DOMParser } from "https://deno.land/x/deno_dom@v0.1.38/deno-dom-wasm.ts";
const url = "https://www.vbb.de/fahrinformation/zug-um-zug-mehr-schiene/{LINE}/"
async function checkLine(line: string) {
const response = await fetch(url.replace('{LINE}', line))
if (response.status == 200) {
const dom = new DOMParser().parseFromString(await response.text(), "text/html")
const headline = dom?.getElementById("content")!.getElementsByTagName("header")[0].getElementsByTagName("h1")[0].textContent.trim()
console.log(`${headline}`)