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
micah1701 / tribune articles remove registration wall beautified-version
Last active August 29, 2015 14:08
Bookmarklet to view content behind the registration walls on Tribune newspaper sites, like chicagotribune.com and the Hartford Courant. To use, simply create a new bookmark in Chrome and set the minified version of the below code as the "URL." Then click the bookmark whenever you encounter a modal popup that asks you to register or log in. Note:…
javascript: void((function(d) {
var modalblock = document.getElementById("reg-overlay");
modalblock.parentElement.removeChild(modalblock);
var style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = 'body,html { overflow: auto !important; }';
d.getElementsByTagName("head")[0].appendChild(style);
})(document));
@micah1701
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
micah1701 / google_geocode_api_v3.php
Created April 11, 2013 16:40
Use the Google Maps API to geocode a given address.
<?php
$url = "https://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=" . urlencode($_GET['addr']);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$raw_xml = curl_exec($ch);
curl_close($ch);
$xml = new SimpleXMLElement($raw_xml);
@micah1701
micah1701 / placeholder
Created February 13, 2013 20:50
Use jQuery to dynamically add "placeholder" text in form inputs that do not support the HTML5 "placeholder" attribute
<input type="text" placeholder="sample text">
<script>
function hasPlaceholder()
{
var psuedoInput = document.createElement("input");
return "placeholder" in psuedoInput
}
$(document).ready(function(){
@micah1701
micah1701 / charCount.html
Last active December 10, 2015 00:49
Set the maximum character count of a form field with jQuery, providing the user with a visual count and stripping any values entered greater than the predetermined amount.
<div>
<textarea id="myTextarea" class="lengthcount" maxlength="150"></textarea>
</div>
<div>
<input type="text" id="myInput" class="lengthcount" maxlength="40">
</div>
<script type="text/javascript">
function charCount(element)
@micah1701
micah1701 / dateFormat.js
Last active November 30, 2023 21:42
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
micah1701 / gist:3902167
Created October 16, 2012 21:29
jQuery Digital Clock that attempts to extend accuracy by removing lag time caused by slow processors
<script>
/**
* Show the time and update it every second
*
* clock_id (string) DOM id value of element to update
* offset (int) Optional value to modify local time by, usefull if synchronizing to another clock
*/
function clock(clock_id, offset)
{
if(offset == null || offset == ""){ offset = 0; }
@micah1701
micah1701 / stateList.php
Created October 15, 2012 21:04
PHP array of the American state names and their respective 2-letter postal codes
/**
* formatted as: array("2-letter state code" => "State Name")
*
* example usage:
* <select>
* <?php $selected = "CT"; //default to this selected state
* foreach( $stateList as $code => $state_name ){ ?>
* <option value="<?=$code ?>" <?=($selected==$code) ? " SELECTED" : "" ?> ><?=$state_name ?></option>
* <? } ?>
* </select>
@micah1701
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