Skip to content

Instantly share code, notes, and snippets.

@marcomagdy
marcomagdy / Ping.cpp
Last active October 18, 2023 22:30
Ping.cpp
// Build with > clang++ -std=c++17 pinger.cpp -o pinger -Wall -Werror -fsanitize=address,undefined
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/ip_icmp.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
#include <string>
enum { BMAX = 32, BCUT = BMAX / 2, BHEIGHT = 6 };
typedef uint8_t BIndex;
struct BNode {
BIndex length;
Key keys[BMAX];
union {
BNode *children[BMAX];
Value values[BMAX];
@marcomagdy
marcomagdy / BTree.cpp
Created April 28, 2020 07:07 — forked from pervognsen/BTree.cpp
A B+-tree implementation with find, insert and delete in 176 lines of code.
enum { BMAX = 32, BMIN = BMAX / 2, BHEIGHT = 6 };
struct BNode {
uint32_t length;
Key keys[BMAX];
union {
BNode *children[BMAX];
Value values[BMAX];
};
};
@marcomagdy
marcomagdy / Google MFA
Last active May 30, 2023 17:43
Google MFA in C#
class Program
{
static void Main(string[] args) {
var secretByets = Base32Encoding.ToBytes("supersecretpassword");
var input = GetEpoch() / 30;
var hmac = new HMACSHA1(secretByets);
var output = hmac.ComputeHash(toBytes(input));
Console.WriteLine("{0:d6}", calculate(output));