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 / 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 / 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 / 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 / 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 / getOfferClasses()
Last active April 26, 2018 13:59
Returns an array that represents the _types_ of plans (i.e. offer classes) that should be offered to the customer. An empty array is returned if an offer class cannot be determined due to a coding error and the caller needs to handle accordingly.
// getOfferClasses()
//
// Returns an array that represents the _types_ of plans (i.e. offer classes) that should be offered to the
// customer. An empty array is returned if an offer class cannot be determined due to a coding error and the
// caller needs to handle accordingly.
//
// Parameters:
// custSegment - String customer segment ('A'-Port, 'B'-New, 'C'-Migrator, 'D'-Legacy, 'E'-Inner Circle)
// deviceType - String identifying type of device ('byo'-BYOD, 'c_pl'-Certified Preloved, 'new'-New Device)
// isAppleICDevice - Boolean true if the device is Apple and qualified for an Inner Circle plan
@ptdecker
ptdecker / cardInfo() - JavaScript Credit Card Validity Check Function (Luhn and length checks)
Last active April 26, 2018 15:31
Determines if a credit card number is valid and returns the name of the issuing network.
// cardInfo()
//
// Determines if a credit card number is valid and returns the name of the issuing network. When
// passed a purported card number as a candidate if the card number is valid, the cardInfo()
// function returns a boolean flag ('isValid') indicating if the card is a valid number and a
// string ('network') containing the name of the issuing network. Card validity is determined
// based upon the card number length and Luhn check digit value. Valid card lengths are based
// upon the card lengths valid for a given issuing network. The Luhn check digit is calculated
// using the Luhn algorithm. The function contains a static table ('IINData') that defines the
// supported issuing network. The table is not a complete list--it is only meant to contain
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
// Configuration values that are global to the store. These would need
// Configuration values that are global to the store. These would need
// some sort of a Magento dialog to allow the business team to maintain
// them. Values are stored in cents to avoid JavaScript floating point
// issues
//
// standardShippingRate
// The amount of shipping that should be charged on a per item
// basis unless the individual SKU has a special shipping charge
// freeShippingThreshold
// The amount of the sub-total of the cart of the items that do
@ptdecker
ptdecker / control-flow-5.js
Last active October 15, 2019 17:37
Node.js Concurrency Limited Async Function Calls Using an Array of Functions
/* Control Flow 5 - Concurrency Limited Functions Using an Array of Functions and Callbacks
*
* Based on:
* - http://book.mixu.net/node/ch7.html
* - https://github.com/mixu
*
* The 'Array.prototype.slice.call(arguments)' usage is a JavaScript trick and explained here:
* - http://mariapacana.tumblr.com/post/79170518832/javascript-tricks
* - http://stackoverflow.com/questions/7056925/how-does-array-prototype-slice-call-work
*
@ptdecker
ptdecker / control-flow-4.js
Last active December 6, 2016 15:05
Node.js Serial Execution of an Array of Callback Functions
/* Control Flow 4 - Serial Execution of an Array of Callback Functions
*
* Based on:
* - http://book.mixu.net/node/ch7.html
* - https://github.com/mixu
*
* Revised based upon comments from 'lanzz' to use 'process.nextTick(next)' instead of 'next()'
* Revised based upon comments from 'Israel' to use "typeof(callback) != 'undefined'"
*
* The 'Array.prototype.slice.call(arguments)' usage is a JavaScript trick and explained here: