Skip to content

Instantly share code, notes, and snippets.

View samhernandez's full-sized avatar
🎈

Sam Hernandez samhernandez

🎈
  • Precocity LLC
  • Plano TX
  • X @sam_h
View GitHub Profile
@samhernandez
samhernandez / drupal_swap_form_error_message.php
Last active December 20, 2015 09:29
Swap Drupal form error messages
<?php
// Drupal 7.22
// If there's an easier way please let me know
/**
* Swap out a form error message.
*
* This must be done with the actual message comparison since error keys
* are not stored in drupal messages.
*
@samhernandez
samhernandez / gist:5717071
Created June 5, 2013 20:34
Quick color hex value in JavaScript. Taken from the comments at http://www.paulirish.com/2009/random-hex-color-code-snippets/
var randomBgHex = '#' + ('000000' + Math.floor(Math.random()*16777215).toString(16)).slice(-6);
@samhernandez
samhernandez / round-to-nearest.js
Created May 30, 2013 16:59
Round a number to the nearest interval of a given number. (Because I always forget how darned simple this is.)
/**
* Returns the number rounded to the nearest interval.
* Example:
*
* roundToNearest(80, 100); // 100
* roundToNearest(25, 15); // 30
*
* @param {number} value The number to round
* @param {number} interval The numeric interval to round to
* @return {number}
@samhernandez
samhernandez / gist:5260558
Last active September 24, 2019 11:58
Get an RSS pubDate from a Javascript Date instance.
/**
* Get an RSS pubDate from a Javascript Date instance.
* @param Date - optional
* @return String
*/
function pubDate(date) {
if (typeof date === 'undefined') {
date = new Date();
}