Skip to content

Instantly share code, notes, and snippets.

Avatar

Micah J. Murray micah1701

View GitHub Profile
@micah1701
micah1701 / tribune articles remove registration wall beautified-version
Last active Aug 29, 2015
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:…
View tribune articles remove registration wall beautified-version
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 / 0_reuse_code.js
Last active Sep 8, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@micah1701
micah1701 / stateList.php
Created Oct 15, 2012
PHP array of the American state names and their respective 2-letter postal codes
View stateList.php
/**
* 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 / gist:3902167
Created Oct 16, 2012
jQuery Digital Clock that attempts to extend accuracy by removing lag time caused by slow processors
View gist:3902167
<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 / charCount.html
Last active Dec 10, 2015
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.
View charCount.html
<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 / placeholder
Created Feb 13, 2013
Use jQuery to dynamically add "placeholder" text in form inputs that do not support the HTML5 "placeholder" attribute
View placeholder
<input type="text" placeholder="sample text">
<script>
function hasPlaceholder()
{
var psuedoInput = document.createElement("input");
return "placeholder" in psuedoInput
}
$(document).ready(function(){
@micah1701
micah1701 / google_geocode_api_v3.php
Created Apr 11, 2013
Use the Google Maps API to geocode a given address.
View google_geocode_api_v3.php
<?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 / time_ago.php
Last active Dec 26, 2015
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.
View time_ago.php
<?php
function time_ago($pastTime)
{
$datetime1=new DateTime("now");
$datetime2=date_create($pastTime);
$diff=date_diff($datetime1, $datetime2);
$timemsg='';
if($diff->y > 0){
$timemsg = $diff->y .' year'. ($diff->y > 1?"'s":'');
}
@micah1701
micah1701 / required-fields-validation.js
Created Apr 5, 2016
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.
View required-fields-validation.js
var invalid_fields = 0; //global var can be accessed without calling function
function validate()
{
invalid_fields = 0; // reset counter
$("[required]").each(function(){
var val = $(this).val();
if(val == "" || val == null || val.match('/select/i'))
{
@micah1701
micah1701 / responsive-images.js
Last active May 5, 2016
Make all user uploaded images responsive
View responsive-images.js
// 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});
});