Skip to content

Instantly share code, notes, and snippets.

View szaydel's full-sized avatar

Sam Zaydel szaydel

  • RackTop Systems
  • Moss Beach
View GitHub Profile
@szaydel
szaydel / leak.c
Last active December 16, 2020 04:55
#include <errno.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <stdarg.h>
#include <time.h>
#include <unistd.h>
#include <sys/mman.h>
# Run me with python3 <thisfile.py>
import socket, ssl
import logging
import threading
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
@szaydel
szaydel / cli.py
Last active September 28, 2020 03:54
#!/usr/bin/env python3
import random
import socket
import time
HOST, PORT = "localhost", 9999
def sendall(sock, msg):
  • Create a file on the system in the same directory as you login is just fine, called mock-audit.c with contents from the mock-audit.c in this snippet.
  • Compile it with: gcc -o mock-audit mock-audit.c
  • Run the program from the same directory with ./mock-audit
  • If the system seems to be getting cripped, double the default 100000000, then double again if necessary
class Singleton:
_instance = None # class attribute
def __new__(cls, *args, **kwargs):
if Singleton._instance is None:
Singleton._instance = object.__new__(cls)
return Singleton._instance
class Logger:
def print_log(self, message):
print(f'[Logger]: {message}')
class NetworkLogger:
def print_log(self, message):
print(f'[NetworkLogger]: {message}')
class Person:
def __init__(self, name):
class Iter:
def __init__(self, data):
self.data = data
self.index = 0
def __next__(self):
if self.index >= len(self.data):
raise StopIteration
value = self.data[self.index]
#!/usr/bin/env python3
import shlex
import subprocess
class ExceptionA(Exception):
pass
class ExceptionB(Exception):
@szaydel
szaydel / time-size.c
Last active May 14, 2020 21:52
Implementations for time coversion from interval/duration string to a long integer, and for size string conversion to long integer bytes.
/*
* Convert a time string into seconds; format is
* a sequence of:
* time[qualifier]
*
* Valid time qualifiers are:
* <none> seconds
* s|S seconds
* m|M minutes
* h|H hours
#!/bin/bash
# Generate prometheus-compatible output, which could be used with node_exporter
# file collector. This script needs to be run periodically, perhaps via cron.
#
# format_memory_usage_metrics: Takes value of memory.usage_in_bytes
# file in the relevant cgroup and re-formats it to prometheus text format.
#
function format_memory_usage_metrics {