Skip to content

Instantly share code, notes, and snippets.

View linuskmr's full-sized avatar

Linus linuskmr

  • Germany
  • 20:20 (UTC +02:00)
View GitHub Profile
@linuskmr
linuskmr / presentation.js
Created December 27, 2022 12:43
Make a navigable presentation from a HTML page
const sections = document.getElementsByTagName("section");
let currentSectionIndex = 0
// Add style
const style = `
section {
padding: 10px 0;
height: 100vh;
}
`
@linuskmr
linuskmr / password_match_prefix.c
Last active November 14, 2022 18:45
Reading a password into a finite buffer allows shorter prefixes to match as well — Live demo at https://cplayground.com/?p=koala-phil-cod
// Reading a password into a finite buffer allows shorter prefixes to match as well.
// Live demo at https://cplayground.com/?p=koala-phil-cod
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main() {
@linuskmr
linuskmr / multipart_extractor.py
Created October 22, 2022 09:43
HTTP Multipart Form-Data Extractor
import re
import os
# Read captured multipart form data that was extracted via Wireshark
with open('extracted_multipart.bin', 'rb') as file:
multipart = file.read()
# Multipart parts are separated by a boundary like
# -----------------------------1881080412979790561529271372
@linuskmr
linuskmr / multicast-client.rs
Created October 12, 2022 09:10
Multicast client and server in Rust
use anyhow::Context;
use nix::sys::socket::*;
use std::{str, net};
fn main() -> anyhow::Result<()> {
log::debug!("Creating socket");
let fd = socket(
AddressFamily::Inet,
SockType::Datagram,
@linuskmr
linuskmr / congestion-control.py
Created October 10, 2022 14:27
Comparing leaky and token bucket
from datetime import datetime, timedelta
from typing import List, Tuple
from enum import Enum
BUCKET_SIZE = 512
PROCESS_EVERY_MS = 30
# Read dump produced by `tcpdump -q`. Lines look like this:
@linuskmr
linuskmr / log_macro.c
Last active November 12, 2022 11:08
Logging macro with file, line number and function name
/**
* A macro that works like printf, but prints to stderr and includes the file, line number and function name.
* From https://bitsector.net/useful-logging-macro/
*/
#define LOG(...) printf("%s:%d %s(): ", __FILE_NAME__, __LINE__, __func__);\
printf(__VA_ARGS__); \
printf("\r\n");
# Downloads all hrefs from a webpage
import os
import re
import urllib
from pathlib import Path
from multiprocessing import Pool
import httpx
@linuskmr
linuskmr / testrunner.cpp
Last active September 20, 2022 17:26
Simple Testrunner for C++
#include <iostream>
#include <cassert>
#include <vector>
#include <functional>
#include <unistd.h>
#include <sys/wait.h>
#include <cstring>
void test_ok() {
@linuskmr
linuskmr / abbr.js
Last active December 19, 2022 10:49
Clicking on an abbr opens an alert box showing its title/explanation. This is useful on mobile devices that don't show the title in a tooltip.
// Setup onclick handler for abbr tags. Clicking on an abbr opens an alert box
// showing its title/explanation. This is useful on mobile devices that don't
// show the title in a tooltip.
const abbrs = document.getElementsByTagName("abbr")
const titleSpans = document.querySelectorAll("span[title]")
for (const abbr of [...abbrs, ...titleSpans]) {
abbr.onclick = e => alert(`${e.target.innerText}: ${e.target.title}`)
}
@linuskmr
linuskmr / docker-compose.yml
Created May 29, 2022 16:43
Nextcloud Docker-Compose
# https://www.ionos.com/digitalguide/server/configuration/nextcloud-installation-with-docker/
version: '3'
services:
db:
image: mariadb
container_name: nextcloud-mariadb
networks:
- nextcloud_network
volumes:
- db:/var/lib/mysql