Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View toddmotto's full-sized avatar

Todd Motto toddmotto

View GitHub Profile
add_filter('pre_comment_content', 'encode_code_in_comment');
function encode_code_in_comment($source) {
$encoded = preg_replace_callback('/<code>(.*?)<\/code>/ims',
create_function(
'$matches',
'$matches[1] = preg_replace(
array("/^[\r|\n]+/i", "/[\r|\n]+$/i"), "",
$matches[1]);
return "<code>" . esc_html( $matches[1] ) . "</code>";'
@toddmotto
toddmotto / gist:4267440
Created December 12, 2012 12:41
Kickass micro reset and helper.
*, *:after, *:before {
margin:0;
padding:0;
box-sizing:border-box;
-webkit-box-sizing:border-box;
-moz-box-sizing:border-box;
-webkit-font-smoothing:antialiased;
-moz-font-smoothing:antialiased;
-o-font-smoothing:antialiased;
font-smoothing:antialiased;
@toddmotto
toddmotto / gist:4369618
Created December 24, 2012 15:18
Progressive enhancement technique for HTML5, retina detection to optimise your CSS. Usage in CSS: .no-retina { /* styles */ } .retina { /* styles */ }
// Retina Device, add 'retina' to HTML tag
if (window.devicePixelRatio >= 2) {
document.getElementsByTagName('html')[0].className += ' retina';
}
// No-retina Device, add 'no-retina' to HTML tag
else {
document.getElementsByTagName('html')[0].className += ' no-retina';
}
@toddmotto
toddmotto / gist:4485795
Created January 8, 2013 17:23
Google CDN fallback to CloudFlare CDN
<!-- jQuery CDN Failsafe to CloudFlare CDN -->
<script>window.jQuery || document.write('<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.8.3/jquery.min.js"><\/script>');</script>
@toddmotto
toddmotto / gist:4491950
Created January 9, 2013 09:44
SVG feature detection script, with SVG to PNG fallback and HTML classes
// SVG custom feature detection and svg to png fallback
// toddmotto.com/mastering-svg-use-for-a-retina-web-fallbacks-with-png-script#update
function supportsSVG() {
return !! document.createElementNS && !! document.createElementNS('http://www.w3.org/2000/svg','svg').createSVGRect;
}
if (supportsSVG()) {
document.documentElement.className += ' svg';
} else {
document.documentElement.className += ' no-svg';
var imgs = document.getElementsByTagName('img'),
@toddmotto
toddmotto / gist:4613107
Last active December 11, 2015 14:18
WordPress shortcode for H tags.
// Headings
function heading( $atts )
{
extract(shortcode_atts(array(
'tag' => '',
'text' => '',
), $atts));
return '<h' . $tag . '>' . $text . '</h' . $tag . '>';
}
add_shortcode('heading', 'heading');
@toddmotto
toddmotto / gist:4655457
Created January 28, 2013 13:22
iOS detect
var iOS = navigator.userAgent.match(/(iPad)|(iPhone)|(iPod)/i);
if (!iOS) {
// Run scripts for anything but iOS
}
@toddmotto
toddmotto / gist:4972263
Created February 17, 2013 17:00
Retina media query
@media only screen and (-webkit-min-device-pixel-ratio: 1.5),
only screen and (min-resolution: 144dpi) {
/* Retina stuff here */
}
@toddmotto
toddmotto / gist:5477991
Created April 28, 2013 18:56
Center Google Maps Marker positioning on window.resize
google.maps.event.addDomListener(window, 'resize', function() {
var center = map.getCenter()
google.maps.event.trigger(map, "resize")
map.setCenter(center)
})
@toddmotto
toddmotto / gist:5481116
Created April 29, 2013 11:46
Remove whitespace from Java includes/tags
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<trim-directive-whitespaces>true</trim-directive-whitespaces>
</jsp-property-group>
</jsp-config>