Skip to content

Instantly share code, notes, and snippets.

View rkeVader's full-sized avatar

Chris Atienza rkeVader

  • Beagle and Pug Inc
  • Virginia
View GitHub Profile
@rkeVader
rkeVader / UI.validators.misc.js
Last active March 12, 2019 12:38
html text input validators for Floating Point and Integers... BETA - threw together for quick-n-dirty job.
// prevent non-floating points from being typed
// pressed key must either be a number,
// or a decimal point (only if one has not already been typed)
// or a negative sign (only we are at the start of the input)
// USAGE:
// <input type="text" onkeypress="return isFloatingPoint(event);" />
function isFloatingPoint(evt)
{
var nochars = evt.currentTarget.value.trim().length == 0;
var alreadyHasDecimal = evt.currentTarget.value.indexOf(".") >= 0;
@rkeVader
rkeVader / InactivityTimeout.js
Last active March 12, 2019 12:38
POC Inactivity Timeout written for colleague
function inactivityTimeout(
timeoutWarningMinutes,
timeoutLogoutMinutes,
contentID,
warningCallback,
kickedOffCallback) {
// the # of seconds before we warn the user of inactivity...
this.timeoutWarningSeconds = timeoutWarningMinutes * 60;
// the # of seconds we wait after the inactivity warning to log the user out...
this.timeoutLogoutSeconds = timeoutLogoutMinutes * 60;
function /* CLASS */ context_menu_system() {
if (context_menu_system.instance !== null) {
throw "You should only instantiate one context_menu_system!";
}
context_menu_system.instance = this;
this.menuPosition;
this.menuPositionX;
this.menuPositionY;
const colors = {
aliceblue: "#f0f8ff",
antiquewhite: "#faebd7",
aqua: "#00ffff",
aquamarine: "#7fffd4",
azure: "#f0ffff",
beige: "#f5f5dc",
bisque: "#ffe4c4",
black: "#000000",
blanchedalmond: "#ffebcd",
/* canvas-toBlob-polyfill.js
* A canvas.toBlob() implementation.
*/
(function(view) {
"use strict";
var
Uint8Array = view.Uint8Array
, HTMLCanvasElement = view.HTMLCanvasElement
, canvas_proto = HTMLCanvasElement && HTMLCanvasElement.prototype
if (Array.prototype.forEach != undefined) {
// Array->forEach exists... no polyfill necessary
console.log("Array->forEach exists. No PolyFill necessary!");
} else {
// Array->forEach does not exist... polyfill necessary
console.log("Array->forEach does not exist. Resorting to PolyFill!");
Array.prototype.forEach = function(callback, thisArg) {
if (typeof(callback) !== 'function') {
throw new TypeError(callback + ' is not a function!');
}
// 2018.12.03 Atienza, Chris
// Given a slash specified network (ie: 10.1.1.1/24) returns the low and hi IPs in the defined range
// does not exclude any special reserved addresses
function _cidrToRange(cidr) {
var range = [2];
cidr = cidr.split('/');
var cidr_1 = parseInt(cidr[1])
range[0] = long2ip((ip2long(cidr[0])) & ((-1 << (32 - cidr_1))));
start = ip2long(range[0])
function CreateProperty(O, P, Getter, Setter) {
Object.defineProperty(O, P, {
get: Getter,
set: Setter
});
} // CreateProperty
// SAMPLE USAGE
/*
// This JS file implements a selector that mimics the JQUERY selector '$'
// identical usage. It caches selectors for speed. If there is dynamic html
// you can call $clearElementCache to clear a specific entry in the cache
// or the entire cache structure.
// In addition to $ we have $1 which returns the first item found
var __cache_Elements = [];
function $(selector, context) {
if (!__cache_Elements.hasOwnProperty(selector)) {
__cache_Elements[selector] = (context || document).querySelectorAll(selector);
function /* CLASS */ fileutil() {
// this is a static class - no need to instantiate - just call its static/shared methods...
}; /* CLASS fileutil */
fileutil.filecontenttypes = {
text_plain: 'text/plain',
text_css: 'text/css',
text_csv: 'text/csv',
text_html: 'text/html',
image_bmp: 'image/bmp',