Skip to content

Instantly share code, notes, and snippets.

View ptdecker's full-sized avatar

P. Todd Decker ptdecker

  • TripleBlind
  • 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 / 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:
@ptdecker
ptdecker / control-flow-3.js
Last active December 6, 2016 15:05
Node.js Rate Limited Concurrent Execution of an Async Function
/* Control Flow 3 - Rate Limited Concurrent Execution of an Asynchronous Function
*
* Based on:
* - http://book.mixu.net/node/ch7.html
* - https://github.com/mixu
*
* Characteristics:
* - Runs a number of operations concurrently
* - Starts a limited number of operations concurrently (partial concurrency, full concurrency control)
* - No guarantee of order, only that all the operations have been completed
@ptdecker
ptdecker / control-flow-2.js
Last active December 6, 2016 15:05
Node.js Fully Concurrent Execution of an Async Function without Rate Limiting
/* Control Flow 2 - Fully Concurrent Executions of a Function (not rate limited)
*
* Based on:
* - http://book.mixu.net/node/ch7.html
* - https://github.com/mixu
*
* Characteristics:
*
* - Runs a number of operations concurrently
* - Starts all async operations near simultaneously (full concurrency)
@ptdecker
ptdecker / control-flow-1.js
Last active December 6, 2016 15:05
Node.js Serial Execution of an Async Function
/* Control Flow 1 - Repetitive Serial Execution of an Asynchronous Function
*
* Based on:
* - http://book.mixu.net/node/ch7.html
* - https://github.com/mixu
*
* Revised to use "typeof(first_item) != 'undefined'" based upon comments from 'Israel'
*
* Characteristics:
* - Flow control construct 'series' is recursive