Skip to content

Instantly share code, notes, and snippets.

@mcastorina
mcastorina / ipv4-to-u32.c
Last active July 10, 2023 20:13
IPv4 standard address to integer
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
enum {
ERR_MISSING_OCTETS = 1,
ERR_EXTRA_OCTETS,
ERR_INVALID_OCTET
@mcastorina
mcastorina / hexdump.rs
Created October 16, 2022 22:00
Hexdump trait
use std::{fmt, io, result};
/// Result of a hexdump.
pub type Result<T> = result::Result<T, io::Error>;
/// Hexdump provides functionality to output a hexdump to a provided io::Write object.
/// The default Write is io::stdout().
///
/// Examples:
/// ```rust
@mcastorina
mcastorina / tls-workshop.sh
Last active February 9, 2022 05:40
TLS Workshop Playground
#!/bin/bash
## TLS Workshop Playground
## NOTICE: This script is intended for learning purposes only.
# These functions will set environmental variables in your terminal session,
# all beginning with "tls_". Use tls-reset to clean up all variables and remove
# generated temporary files (in the case of asym-gen).
# Print a help message
function tls-help {
@mcastorina
mcastorina / Cargo.toml
Created August 6, 2020 02:03
Clap and rustyline tab completion integration
[package]
name = "tmp"
version = "0.1.0"
authors = ["Miccah Castorina <[email protected]>"]
edition = "2018"
[dependencies]
clap-v3 = { version = "3.0.0-beta.1", features = ["yaml"] }
rustyline = "6.2.0"
serde_yaml = "0.8"
@mcastorina
mcastorina / get_opts.sh
Created November 1, 2019 20:33
Pure bash implementation of getops
#!/bin/bash
# Usage:
# set_opts 'h,help v:,value: l,list'
# OPTS=$(get_opts "$@")
# if [[ $? -ne 0 ]]; then
# exit 1
# fi
# eval set -- "$OPTS"
# while true; do
@mcastorina
mcastorina / queue.c
Created January 18, 2016 04:21
A queue struct for tasks.
#include "queue.h"
void queue_init(struct queue *q) {
q->start = 0;
q->end = 0;
}
uint8_t queue_enqueue(struct queue *q, void (*task)(void*), void *arg) {
if (queue_full(q))
return 1;
q->tasks[q->end] = task;