Skip to content

Instantly share code, notes, and snippets.

View NightOwlPrgmr's full-sized avatar

Christopher Mathis NightOwlPrgmr

  • Broker Exchange Network
  • Minnesota
View GitHub Profile
@NightOwlPrgmr
NightOwlPrgmr / .uStates
Last active January 12, 2021 14:45 — forked from NPashaP/.block
US State Map
license: gpl-3.0
title: uStates
@NightOwlPrgmr
NightOwlPrgmr / validateFormatPhone.php
Created February 21, 2017 15:27
Validate and format phone numbers - retain country codes and extensions
<?php
function formatPhone($num) {
$num = preg_replace('/[^\dx]/i', '', $num);
preg_match('/(x)\.?:?\s*?(\d+)/i', $num, $ext);
if (!empty($ext)) {
$ext = ' ext ' . preg_replace('/\D/', '', $ext[0]);
$num = preg_replace('/(x)\.?:?\s*?(\d+)/i', '', $num);
}
@NightOwlPrgmr
NightOwlPrgmr / config
Created September 28, 2016 17:42
Git Config Output Colorization
[color]
branch = auto
diff = auto
status = auto
[color "branch"]
current = yellow reverse
local = yellow
remote = green
[color "diff"]
meta = yellow
@NightOwlPrgmr
NightOwlPrgmr / exec_time.php
Last active August 31, 2015 18:21
PHP Execution Time
<?php
# execution time (at script start)
$beginTime = microtime(true);
# execution time (upon script end)
$output["time"] = number_format(microtime(true) - $beginTime, 2) . " seconds";
?>
@NightOwlPrgmr
NightOwlPrgmr / JS IE Fixes.js
Last active October 7, 2015 12:12
JS Polyfill for IE Shortcomings
// IE7 fix for .forEach function
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(fn, scope) {
for(var i = 0, len = this.length; i < len; ++i) {
fn.call(scope, this[i], i, this);
}
}
}
// IE7 & IE8 fix for .indexOf function
@NightOwlPrgmr
NightOwlPrgmr / JS Date Prototype.js
Last active September 15, 2015 10:45
Reusable JS Date Prototype
Date.prototype.extractTime = function() {
var h = this.getHours(),
m = this.getMinutes(),
s = this.getSeconds();
return h + ":" + m + ":" + s;
}
var d = new Date();
console.log(d.extractTime());
@NightOwlPrgmr
NightOwlPrgmr / Prevent Page Back: Delete Key.js
Last active August 29, 2015 14:26
Prevent Page Back: Delete Key
$(document).keydown(function(e) {
if (e.keyCode === 8) {
var element = e.target.nodeName.toLowerCase();
if ((element != 'input' && element != 'textarea') || $(e.target).attr("readonly")) {
return false;
}
}
});
@NightOwlPrgmr
NightOwlPrgmr / Base AJAX Call.js
Last active July 9, 2016 16:11
Basic AJAX Example
var request = {};
request['action'] = 'submit';
request['data'] = $(this).val() || $(this).closest('form').serialize();
$.ajax({
url: "<?= $URL; ?>", || url: 'someFile.php',
data: request, || JSON.stringify(request), ||
type: 'POST',
cache: false,
dataType: 'json'
@NightOwlPrgmr
NightOwlPrgmr / JS Format US Dollars Prototype.js
Last active August 29, 2015 14:22
Format numbers to US dollars
Number.prototype.formatMoney = function(c, d, t) {
var n = this,
c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "." : d,
t = t == undefined ? "," : t,
s = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
@NightOwlPrgmr
NightOwlPrgmr / User Defined Key Bindings.json
Last active June 4, 2016 06:21
Sublime Text User Keymap
[
{ "keys": ["alt+shift+up"], "command": "select_lines", "args": {"forward": false} },
{ "keys": ["alt+shift+down"], "command": "select_lines", "args": {"forward": true} },
{ "keys": ["alt+shift+o"], "command": "run_macro_file", "args": {"file": "Packages/User/output.sublime-macro"} },
{ "keys": ["alt+shift+c"], "command": "run_macro_file", "args": {"file": "Packages/User/console.sublime-macro"} },
{ "keys": ["ctrl+shift+t"], "command": "open_recent_file", "args": {"index": 0 } }
]