Skip to content

Instantly share code, notes, and snippets.

@jwbensley
jwbensley / ex-members.py
Created October 14, 2022 14:03
Depth first search of a tree with a per-branch "exclude" list
#!/usr/bin/env python3
"""
ASN to AS-SET mapping:
AS4200000011 -> AS-A1
AS4200000021 -> AS-B1
AS4200000022 -> AS-B2
AS4200000023 -> AS-B3
AS4200000031 -> AS-C1
AS4200000032 -> AS-C2
@jwbensley
jwbensley / memcpy_aligned.c
Created June 26, 2020 08:58
memcpy() using cache and page aligned values
#include <inttypes.h> // uint*_t
#include <stdio.h> // perror(), printf()
#include <stdlib.h> // memcpy, posix_memalign()
#include <string.h> // malloc()
#include <time.h> // clock_t, CLOCKS_PER_SEC
#include <unistd.h> // getpagesize()
static inline void memcpy_aligned(void *to, const void *from, size_t len) {
if (len <= 64) {
memcpy(to, from, 64);
// Not all functions are referenced below are called, that is intentional to verify that they are not being called.
// Provide timestamps:
function print_ts() {
ts = gettimeofday_us();
printf("[%10d.%06d] ", ts/1000000, ts%1000000);
}
#!/bin/bash
#
# Kills all iptables rules and unloads all iptables/netfilter related
# kernel modules.
#
# From: https://github.com/netoptimizer/network-testing/blob/master/bin/netfilter_unload_modules.sh
# Author: Jesper Dangaard Brouer <netoptimizer@brouer.com>
# Trick so, program can be run as normal user, will just use "sudo"
if [ "$EUID" -ne 0 ]; then
@jwbensley
jwbensley / grpc_cfg.py
Last active November 15, 2016 09:46
Example gRPC client for IOS-XR which loads a json plain text file and sends it over gRPC, using certificate authentication.
# Code from https://github.com/cisco-grpc-connection-libs/ios-xr-grpc-python/blob/master/examples/grpc_cfg.py
from grpc.framework.interfaces.face.face import AbortionError
import json
from time import sleep
import sys
sys.path.insert(0, '../')
from lib.cisco_grpc_client import CiscoGRPCClient