Skip to content

Instantly share code, notes, and snippets.

@benplum
benplum / HTML List-less Navigation
Last active December 15, 2015 08:09
Simple navigation structure without using lists.
<nav>
<div class="item">
<a href="#">Home</a>
</div>
<div class="item">
<a href="#">About</a>
<div class="children">
<div class="item">
<a href="#">Sub-1</a>
<div class="children">
@benplum
benplum / PHP Date Formats
Last active December 15, 2015 08:39
Definitions for standard PHP date formats.
define("DATE_FORMAT", "F j, Y");
define("PUBDATE_FORMAT", "Y-m-d H:i");
define("MYSQL_DATETIME", "Y-m-d H:i:s");
@benplum
benplum / PHP YouTube Thumbnail
Last active December 15, 2015 08:39
Return YouTube thumbnail URL.
/*
default.jpg
mqdefault.jpg
hqdefault.jpg
maxresdefault.jpg
0.jpg - 3.jpg
*/
function youTubeThumbnail($id, $size = "mqdefault") {
return "http://img.youtube.com/vi/" . $id . "/" . $size . ".jpg";
}
@benplum
benplum / PHP Relative Time Format
Created March 24, 2013 18:45
Return human readable relative time string.
define("SECOND", 1);
define("MINUTE", 60 * SECOND);
define("HOUR", 60 * MINUTE);
define("DAY", 24 * HOUR);
define("MONTH", 30 * DAY);
function relativeTime($time) {
if (!is_numeric($time)) {
$time = strtotime($time);
}
@benplum
benplum / PHP trim HTML
Created March 25, 2013 19:44
Random HTML string functions
function splitFirstP($html) {
$parts = explode("</p>", $html, 2);
$parts[0] = $parts[0]."</p>";
return $parts;
}
function splitCenterContent($html) {
$return = array();
$parts = explode("</p>", $html);
$middle = floor(count($parts) / 2) - 1;
@benplum
benplum / Colored List Styles
Last active December 16, 2015 12:38
List styles colored differently then list text.
ol { counter-reset: item; }
ol li, ul li { color: black; list-style: none; }
ol li:before { color: red; counter-increment: item; content: counter(item) ". "; margin: 0 0 0 -20px; text-align: right; }
ul li:before { background: transparent; border: 1px solid red; border-radius: 100%; content: ''; display: block; float: left; height: 8px; margin: 10px 0 0 -20px; width: 8px; }
@benplum
benplum / matchMedia - IE9
Last active April 16, 2020 15:57
matchMedia Polyfill w/ Listeners - IE9
// Modernizr style test
if (!(window.webkitMatchMedia || window.mozMatchMedia || window.oMatchMedia || window.msMatchMedia || window.matchMedia)) {
var root = document.getElementsByTagName( 'html' )[0];
root.className += ' no-matchmedia';
}
/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas, David Knight. Dual MIT/BSD license */
window.matchMedia || (window.matchMedia = function() {
"use strict";
@benplum
benplum / matchMedia - IE8
Last active February 1, 2017 21:37
matchMedia Polyfill w/ Listeners - IE8
// Modernizr style test
if (!(window.webkitMatchMedia || window.mozMatchMedia || window.oMatchMedia || window.msMatchMedia || window.matchMedia)) {
var root = document.getElementsByTagName( 'html' )[0];
root.className += ' no-matchmedia';
}
/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license - IE8 VERSION! */
window.matchMedia = window.matchMedia || (function(doc, undefined){
var docElem = doc.documentElement,
@benplum
benplum / HTML5 Enabler
Created December 19, 2013 20:06
HTML5 Enabler
/* Pre-Define HTML5 Elements in IE */
(function(){ var els = "source|address|article|aside|audio|canvas|command|datalist|details|dialog|figure|figcaption|footer|header|hgroup|keygen|mark|meter|menu|nav|picture|progress|ruby|section|time|video".split('|'); for(var i = 0; i < els.length; i++) { document.createElement(els[i]); } } )();
@benplum
benplum / Paragraph Trim Functions
Last active August 29, 2015 13:59
Paragraph Trim Functions
function getFirstPP($html) {
$start = strpos($html, '<p');
$end = strpos($html, '</p>', $start);
$html = substr($html, $start, ($end - $start + 4));
return $html;
}
function splitFirstPP($html) {
$parts = explode("</p>", $html, 2);
$first = $parts[0] . "</p>";