Skip to content

Instantly share code, notes, and snippets.

View matthewjberger's full-sized avatar

Matthew J. Berger matthewjberger

View GitHub Profile
@matthewjberger
matthewjberger / instructions.md
Last active July 26, 2024 20:48
Install a nerd font on ubuntu

1.) Download a Nerd Font

2.) Unzip and copy to ~/.fonts

3.) Run the command fc-cache -fv to manually rebuild the font cache

@matthewjberger
matthewjberger / main.rs
Last active July 26, 2024 03:07
Watch a file with debounced file events using notify and tokio in Rust
// Cargo.toml
//
// notify = "5.1.0"
// notify-debouncer-mini = "0.2.1"
// tokio = { version = "1.28.1", features = ["full"] }
use notify::RecursiveMode;
use notify_debouncer_mini::{new_debouncer, DebouncedEventKind};
use std::{error::Error, path::Path, time::Duration};
use tokio::time::sleep;
@matthewjberger
matthewjberger / macro.rs
Last active July 8, 2024 19:09
egui enum dropdown selection in rust
// This is a macro that can generate the egui enum dropdown pattern for a c-style Rust enum
// meaning it contains only fieldless, unit variants
#[macro_export]
macro_rules! generate_enum {
(
$name:ident {
$($variant:ident),* $(,)?
}
) => {
@matthewjberger
matthewjberger / pubsub.rs
Created July 4, 2024 22:48
An in-process pub/sub message broker in rust using async_std
// [dependencies]
// async-std = { version = "1.12.0", features = ["attributes"] }
// futures = "0.3.30"
use async_std::{
future::timeout,
sync::{Arc, Mutex},
};
use futures::{
channel::mpsc::{unbounded, UnboundedReceiver, UnboundedSender},
futures::stream::StreamExt,
From: http://redteams.net/bookshelf/
Techie
Unauthorised Access: Physical Penetration Testing For IT Security Teams by Wil Allsopp.
Social Engineering: The Art of Human Hacking by Christopher Hadnagy
Practical Lock Picking: A Physical Penetration Tester's Training Guide by Deviant Ollam
The Art of Deception: Controlling the Human Element of Security by Kevin Mitnick
Hacking: The Art of Exploitation by Jon Erickson and Hacking Exposed by Stuart McClure and others.
Nmap Network Scanning: The Official Nmap Project Guide to Network Discovery and Security Scanning by Fyodor
The Shellcoder's Handbook: Discovering and Exploiting Security Holes by several authors
// petgraph v0.6.5
use petgraph::graph::{NodeIndex, DiGraph};
fn number_children(graph: &DiGraph<(), ()>, parent: NodeIndex, depth: usize) -> Vec<(NodeIndex, usize, usize)> {
let mut tree = Vec::new();
let mut index = 0;
// Start numbering the children from index 0
for child in graph.neighbors(parent) {
tree.push((child, index, depth));
// petgraph v0.6.5
use petgraph::graph::DiGraph;
use petgraph::visit::{EdgeRef, Topo};
fn main() {
// Create a new directed graph
let mut graph = DiGraph::new();
// Add nodes and edges (similar to previous examples)
let a1 = graph.add_node("A1");
@matthewjberger
matthewjberger / graph_equality.rs
Created May 15, 2024 22:55
Create a newtype for equating petgraph graphs (use this if you want to #[derive(PartialEq)] but your struct has a petgraph::Graph field)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CustomGraph {
pub graph: petgraph::Graph<MakelineNode, ()>,
}
impl PartialEq for CustomGraph {
fn eq(&self, other: &Self) -> bool {
graph_eq(&self.graph, &other.graph)
}
@matthewjberger
matthewjberger / configuration.nix
Created June 22, 2021 03:52
/etc/nixos/configuration.nix minimal configuration for using kde plasma
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
@matthewjberger
matthewjberger / types.rs
Last active May 3, 2024 03:52
Type id pattern matching in rust
use std::any::TypeId;
// Define some example types
struct Foo;
struct Bar;
struct Baz;
// Define a function to perform type-based pattern matching and return the value
fn match_type<T: 'static>(value: T) -> Option<T> {
// Get the TypeId of the value