Skip to content

Instantly share code, notes, and snippets.

@sammydigits
sammydigits / _cq_editConfig.xml
Created April 9, 2014 15:53
CQ5: Display the name/title of the component
<jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
cq:actions="[text:Your Component Name,-,edit,delete,copymove,-,insert]"
cq:dialogMode="floating"
jcr:primaryType="cq:EditConfig">
</jcr:root>
@sammydigits
sammydigits / iframe-from-js.html
Last active August 29, 2015 14:00
Create iframe element from javascript
<script type="text/javascript">
window.onload = function(){
var jvurl = 'http://www.example.com';
var iframe = document.createElement('iframe');
iframe.frameBorder=0;
iframe.width="800px";
iframe.height="450px";
iframe.setAttribute("src", jvurl);
document.getElementById("container").innerHTML = '';
document.getElementById("container").appendChild(iframe);
@sammydigits
sammydigits / icmp.js
Last active August 29, 2015 14:00
Tag links with ICMP tracking using jQuery
//add tracking to each CTA on the hero slides
jq('.hero').find('.hero-content').find('a').each(function(){
jq(this).attr('href', jq(this).attr('href')+'?icmp=Hero:'+encodeURI(jq(this).parent().parent().find("h1").text()));
});
@sammydigits
sammydigits / youtube-playlist.js
Created May 1, 2014 18:37
List videos in a YouTube playlist with jQuery
var playListURL = '//gdata.youtube.com/feeds/api/playlists/PLOGi5-fAu8bFt81BE77HOVzO4S4M1ZexJ?v=2&alt=json&callback=?';
jq.getJSON(playListURL, function (data) {
var list_data = "";
jq.each(data.feed.entry, function (i, item) {
var feedTitle = item.title.$t;
var feedURL = item.link[1].href;
var fragments = feedURL.split("/");
var videoID = fragments[fragments.length - 2];
var thumb = "//i1.ytimg.com/vi/" + videoID + "/mqdefault.jpg";
@sammydigits
sammydigits / jpegtran.bat
Created May 2, 2014 20:11
Run jpegtran on a directory of images
@echo none
for /f "delims=" %%a in ('dir "*.jpg" /b /s /a-d') do (
echo processing "%%a"
"C:\dev\jpegtran.exe" -optimize -progressive -copy none "%%a" "%%a.tmp"
move /Y "%%a.tmp" "%%a" >nul
)
pause
@sammydigits
sammydigits / functions.php
Created May 7, 2014 13:47
Bulk remove featured image from Wordpress posts
/*
Paste the following into functions.php, hit save, then remove it, hit save again.
*/
global $wpdb;
$wpdb->query( "
DELETE FROM $wpdb->postmeta
WHERE meta_key = '_thumbnail_id'
" );
@sammydigits
sammydigits / multiple-scripts.js
Created May 8, 2014 20:19
jQuery ajax load multiple scripts
jq.when(
jq.getScript( "/js/libs/picker.js" ),
jq.getScript( "/js/libs/picker.date.js" ),
jq.getScript( "/js/libs/legacy.js" ),
jq.Deferred(function( deferred ){
jq( deferred.resolve );
})
).done(function(){
console.log('all required scripts are all loaded');
});
@sammydigits
sammydigits / https.js
Created May 15, 2014 16:05
Javascript switch between protocols
function isHTTPS() {
return (window.location.href.indexOf('https') > -1 || window.location.host.indexOf('localhost') > -1);
};
var loc = window.location.href,
httpsHref = 'https' + loc.substring(4),
if (!isHTTPS()) {
window.location = httpsHref;
}
@sammydigits
sammydigits / functions.php
Created May 16, 2014 15:35
Fix oversize images posted when using Jetpack for Wordpress post by email functionality, paste this into top of your themes functions.php file
add_filter( 'post_thumbnail_html', 'remove_width_attribute', 10 );
add_filter( 'the_content', 'remove_width_attribute', 10 );
function remove_width_attribute( $html ) {
$html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
return $html;
}
@sammydigits
sammydigits / detect.js
Created June 3, 2014 15:27
Javascript detect windows, ie, 64bit, net framework
var is_win = navigator.userAgent.match(/(Windows)/i)?true:false;
var is_ie = navigator.userAgent.match(/(MSIE)/i)?true:false;
var is_64bit = navigator.userAgent.match(/(64)/i)?true:false;
var has_net = navigator.userAgent.match(/.NET CLR [0-9.]+/g)?true:false; //only works in IE