Skip to content

Instantly share code, notes, and snippets.

View toddmotto's full-sized avatar

Todd Motto toddmotto

View GitHub Profile
@toddmotto
toddmotto / extend.js
Last active August 29, 2015 14:03
ECMAScript 5 extend(), preserves original Object values
function extend (target, source) {
target = JSON.parse(JSON.stringify(target));
Object.keys(source).map(function (prop) {
Object.prototype.hasOwnProperty.call(target, prop) && (target[prop] = source[prop]);
});
return target;
};
@toddmotto
toddmotto / annotate.js
Created July 16, 2014 21:26
Angular's annotation mapping process and performance
/**
* Read the post for full details, hope these comments are helpful!
* http://toddmotto.com/angular-js-dependency-injection-annotation-process
*/
function annotate(fn, strictDi, name) {
var $inject,
fnText,
argDecl,
last;
@toddmotto
toddmotto / gist:657ba746e89025a0200b
Created October 23, 2014 21:45
Google Inbox invite code
Z21haWxpbnZpdGU#AAjWDC2eHXTaEvbWN19YkGu-csrdu0xEv0RAqZIRtXDlouoVrL9F7Hgs1ITcurRw4omVdrjPjhYFm7V2pUYPhe57u_s5KqDn7A#ZXRpdm5pbGlhbWc
@toddmotto
toddmotto / example.md
Created May 27, 2014 13:11
Dynamically change $location (with query params) in Angular using search() and path()

Input:

var someDynamicParam = 9812894732432;
$location.search('myParams', someDynamicParam).path('/request');

Output:

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: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
}