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 / 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 / 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 / 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 / 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 / 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
micah1701 / responsive-images.js
Last active May 5, 2016 03:27
Make all user uploaded images responsive
// make all user uploaded images responsive
$(".user_uploaded_content_wrapper img").each(function(){
var oldWidth = ($(this).width() > 0) ? $(this).width()+"px" : '100%';
$(this).css({width:'100%', height:'auto', maxWidth:oldWidth});
micah1701 / required-fields-validation.js
Created April 5, 2016 06:06
Super simple script to enforce required fields in form. Just add a "required" attribute to the tag. If its blank, it adds some bootstrap error classes to the parent form-group container. Also validates e-mail fields.
var invalid_fields = 0; //global var can be accessed without calling function
function validate()
invalid_fields = 0; // reset counter
var val = $(this).val();
if(val == "" || val == null || val.match('/select/i'))
micah1701 / time_ago.php
Last active December 26, 2015 12:59
PHP function to convert a timestamp in the past to a human readable, rounded time frame. For example "2 years ago" or "1 minute ago" or even "Just Now" if in past X number of seconds.
function time_ago($pastTime)
$datetime1=new DateTime("now");
$diff=date_diff($datetime1, $datetime2);
if($diff->y > 0){
$timemsg = $diff->y .' year'. ($diff->y > 1?"'s":'');