Skip to content

Instantly share code, notes, and snippets.

View ptdecker's full-sized avatar

Peter Todd Decker ("Todd") ptdecker

  • Kansas City
View GitHub Profile
@ptdecker
ptdecker / serialNumInfo()
Last active December 13, 2021 11:55
Evaluates a mobile device serial number, determines its type (ESN, IMEI, MEID) and attempts to check for validity if possible.
// serialNumInfo()
//
// Evaluates a mobile device serial number, determines its type (ESN, IMEI, MEID) and attempts
// to check for validity if possible.
//
// When the passed purported serial number, the serialNumInfo() function returns a boolean flag
// ('isValid') indicating the validity of the number along with 'numType' indicating the type of
// serial number passed. The function expects the passed serialNumber to be not contain any
// spaces and for hexadecimal values to be passed without a leading "0x" or "0h" prefix.
//
@ptdecker
ptdecker / justfile
Created August 8, 2024 18:45
Justfile Receipts for Just Binary Builds
# Build production releases for all MacOS supported targets and documentation
[macos]
build-release: build-docs
@echo Cleaning...
@cargo clean {{cargo_args}}
@echo "Building all release binaries for 'aarch64-apple-darwin' architecture..."
@rustup target install aarch64-apple-darwin
@cargo install {{cargo_args}} --bin my-project --profile=release --target=aarch64-apple-darwin --root release/macos/aarch64 --force --path .
@echo "Building all release binaries for 'x86_64-apple-darwin' architecture..."
@rustup target install x86_64-apple-darwin
@ptdecker
ptdecker / main.rs
Last active October 17, 2024 18:56
TOML Crate Demonstration
//! TOML Value Manipulation Demonstration
//!
//! This code is to supplement this excellent article:
//!
//! [Rust: Read, Write, and Modify .toml Files — Another way to handle User Set Environment Variables](https://medium.com/@itsuki.enjoy/rust-read-write-and-modify-toml-files-another-way-to-handle-user-set-environment-variables-27e1baf1a65f)
//!
//! This demo code assumes you have added additional entries to your ~/.cargo/config.toml file. Although, I used
//! `foo` and `bar` instead of the `password` and `username` that the article uses.
//!
//! Put this code into `main.rs`. And, here is the corresponding `Cargo.toml` needed for this demo.
@ptdecker
ptdecker / fix-accidental-local-main-commit.sh
Created October 31, 2024 20:05
Quick recovery from accidental commit of changes to local main instead of to a branch
# Assumes local main was current with remote main prior to the fuck up
# Create a new branch containing prior local main + changes
git checkout -b {local branch name}
# Switch back to local main
git checkout -
# Delete local main (which also contains the additional changes)
git branch -D main
# Check out remote main (which matches what was local main before changes)
git checkout main
# Switch back to new branch which would contain the changes
@ptdecker
ptdecker / consumers.rs
Created July 15, 2025 14:08
Invalid type mismatch
#[derive(Debug, Serialize, Deserialize)]
pub struct ConsumerRequest {
/// The unique identifier for the consumer record. This parameter is optional and only used
/// when updating or deleting a consumer record.
#[cfg(feature = "string-consumer-id")]
pub consumer_id: Option<String>,
#[cfg(not(feature = "string-consumer-id"))]
pub consumer_id: Option<Uuid>,
pub organization_id: Option<String>,
trace_id: Option<Uuid>,
@ptdecker
ptdecker / client.rs
Created July 15, 2025 14:08
Incorrect type identification
impl ConsumerId {
pub fn new() -> Self {
#[cfg(not(feature = "string-consumer-id"))]
let consumer_id = Uuid::new_v4();
#[cfg(feature = "string-consumer-id")]
let consumer_id = {
let length = 10;
let mut rng = rand::thread_rng();
let letters: Vec<char> = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().collect();
(0..length)