Skip to content

Instantly share code, notes, and snippets.

View micah1701's full-sized avatar
Working from home

Micah J. Murray micah1701

Working from home
View GitHub Profile
micah1701 / dateFormat.js
Last active July 2, 2024 00:40
Replicate PHP's native date() formatting in JavaScript for many common format types
* Return a formated string from a date Object mimicking PHP's date() functionality
* format string "Y-m-d H:i:s" or similar PHP-style date format string
* date mixed Date Object, Datestring, or milliseconds
function dateFormat(format,date){
if(!date || date === "")
micah1701 / bulma_htmlSelectElement_to_dropdown_with_filter.js
Created June 9, 2024 14:20
A JavaScript class that converts an existing HTML Select input element to a functioning Dropdown component with a search filter
class htmlSelect2BulmaDropownWithFilter {
constructor(HTMLSelectElement_or_ElementId) {
this.selectElement = (typeof (HTMLSelectElement_or_ElementId) == "string") ? document.getElementById(HTMLSelectElement_or_ElementId) : HTMLSelectElement_or_ElementId;
if (this.originalOptions == null) {
this.originalOptions = Array.from(this.selectElement.options).map(option => ({ value: option.value, text: option.text }));
this.options = Array.from(this.selectElement.options).map(option => ({ value: option.value, text: option.text })); //selectElement.options;
this.filter = "";
this.filteredOptions = [];
this.selectElement.parentElement.querySelectorAll('.dropdown').forEach(dropdownElement => {
micah1701 / cleanDEA.php
Last active January 25, 2023 03:50
Validate and sanatize a user entered DEA Registration ID with PHP
* Validate and clean a DEA Registration ID
* @param string $enteredValue user supplied DEA ID
* @param string $lastname OPTIONAL extended validation requires first letter of users last name to match corresponding character in ID
* @return string|bool returns sanitized alphanumeric DEA Registration ID or FALSE
function cleanDEA(string $enteredValue, string $lastname = '') {
//if a " Supervisee Identifier" was supplied, just ignore it
micah1701 / bulma_quick_notification.js
Last active January 12, 2022 08:43
Extends CSS framework with a short-lived notification message that slides up from the bottom of the screen. Useful for showing user that a change has occurred on the page. Requires jQuery.
* display a quick notification box that slides up from the bottom for a few seconds
function quickNotice(message,cssClass,timeOnScreen)
cssClass = (cssClass) ? cssClass : 'is-success';
timeOnScreen = (timeOnScreen) ? timeOnScreen : 3000;
var html = '<div id="quickNotice" style="position: absolute; z-index: 100; width: 100%" class="notification has-text-centered has-text-weight-semibold '+cssClass+'">';
html+= message;
micah1701 / cURL_follow_location.php
Created October 3, 2012 18:22
Recursive cURL function to follow links when local server does not allow CURLOPT_FOLLOWLOCATION
* use cURL to get the contents on a remote page uses redirect headers
* necessary when local server does not allow location
function curl($url,$recursive_attempt=0){
if (!function_exists('curl_init')) { return false; }
$content = false;
$can_follow = ( ini_get('safe_mode') || ini_get('open_basedir') ) ? false : true; //cURL can't follow redirects in safe mode or if open_basedir is on
micah1701 / jQuery-UI-javascript-prompts.js
Last active October 15, 2021 13:48
Three functions to replace the native javascript alert(), confirm() & prompt() popup boxes with customizable jQuery UI dialog boxes. example usage: uiPrompt({ message: 'Enter your name', placeholder: 'Your Name Goes Here', callback: function(value){ uiAlert("hello "+value); }});
* display a styled jQuery UI dialog box in place of the native javascript alert()
* message string HTML message to display
* title string optional title text to display in header of confirmation box
* callback function optional function to trigger when user clicks "OK"
function uiAlert(settings)
micah1701 / bulma_collapsible_menu.js
Created January 31, 2018 19:30
Extends CSS framework's Menu component to make sub-menu items expand and collapse. Requires jQuery and Font Awesome.
$(".is-closed").siblings('a').addClass('menu-has-children has-closed');
$("").on('click', function(){
var firstUL = $(this).siblings('ul');
micah1701 / csv2json.php
Last active February 11, 2019 16:53
Read a CSV file and convert to JSON object
* Read a CSV File an convert to JSON object
* Assumes first row is header data with column titles
* For Google Sheets, publish the sheet in csv format and use the provided URL
function csv2json($url) {
$csv = file_get_contents($url);
$rows = array_map("str_getcsv", explode("\n", $csv));
$result = array();
micah1701 / register-esc.js
Last active November 11, 2017 20:25
Register multiple "ESC" key handlers so hitting the escape key only does the most recently registered action. (requires jQuery)
var escEvents = new Array();
// If something needs to listen for the "ESC" key to be pressed, pass that functionality here
// eventName STRING a name for this event, like "myPopupDialog"
// eventFunction FUNCTION what to do when the user hits the escape key
function setEscEvent(eventName, eventFunction){
escEvents.push({ eventName: eventName, eventFunction: eventFunction });
// When an item doesn't need to listen for the "ESC" key anymore, remove it
micah1701 / set_app_path.php
Last active September 29, 2016 18:30
Determine the server and web directory of the current file.
* set the server directory that this application is stored in.
* if applicaiton is in the root directory, set to "/"
$_app_server_path = rtrim(str_replace('\\', '/', dirname(__FILE__)),"/")."/"; // eg: "/home/ubuntu/workspace/my-website/"
$web_app_path = str_replace(rtrim($_SERVER['DOCUMENT_ROOT'],"/"),'',$_app_server_path); // eg: "/my-website/" or just "/" if in root