Skip to content

Instantly share code, notes, and snippets.

@ms0g
ms0g / ipv4_checksum.cpp
Created July 30, 2020 11:33
Ipv4 header checksum calculation
/**
* Compute Internet Checksum for "count" bytes
* beginning at location "addr".
* @param addr start of the ip header
* @param count ip header size
* @return Taking the ones' complement (flipping every bit) yields 0000,
* which indicates that no error is detected.
*/
uint16_t checksum(void *addr, int count) {
uint32_t sum = 0;
@mjackson
mjackson / multiple-git-hooks.sh
Created February 6, 2018 00:58
Run multiple scripts for the same git hook
#!/bin/sh
# This script should be saved in a git repo as a hook file, e.g. .git/hooks/pre-receive.
# It looks for scripts in the .git/hooks/pre-receive.d directory and executes them in order,
# passing along stdin. If any script exits with a non-zero status, this script exits.
script_dir=$(dirname $0)
hook_name=$(basename $0)
hook_dir="$script_dir/$hook_name.d"
@saidsay-so
saidsay-so / cdrom-emulation.patch
Last active January 9, 2024 21:12
A recent patch to add CD-ROM emulation to your Android kernel (3.18+).
From 45b0c1da3ed92b232b35cc2922e696a5d0fc5c16 Mon Sep 17 00:00:00 2001
From: MusiKid
Date: Sat, 23 Sep 2017 19:46:02 +0200
Subject: [PATCH] Add CD-ROM emulation support.
# This is a recent patch to add CD-ROM emulation to your kernel
---
drivers/usb/gadget/function/f_mass_storage.c | 25 +++++++++++++++++++++++++
drivers/usb/gadget/function/storage_common.c | 4 ++--
@h0tw1r3
h0tw1r3 / aria2.daemon
Last active February 27, 2025 10:16
Aria2c systemd service
continue
dir=/var/www/downloads
file-allocation=falloc
max-connection-per-server=4
max-concurrent-downloads=2
max-overall-download-limit=0
min-split-size=25M
rpc-allow-origin-all=true
rpc-secret=YouShouldChangeThis
input-file=/var/tmp/aria2c.session
@aras-p
aras-p / preprocessor_fun.h
Last active June 2, 2025 18:02
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
/*
* Simple MD5 implementation
*
* Compile with: gcc -o md5 -O3 -lm md5.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>