Skip to content

Instantly share code, notes, and snippets.

@sammydigits
sammydigits / ol.css
Created July 17, 2014 15:39
Styling an ordered list in CSS
/* credit to http://www.456bereastreet.com/archive/201105/styling_ordered_list_numbers/ */
ol {
counter-reset:li; /* Initiate a counter */
margin-left:0; /* Remove the default left margin */
padding-left:0; /* Remove the default left padding */
}
ol > li {
position:relative; /* Create a positioning context */
margin:0 0 6px 2em; /* Give each list item a left margin to make room for the numbers */
@sammydigits
sammydigits / crush.bat
Created June 13, 2014 15:44
pngcrush all images in a directory using 148 different methods
pngcrush -brute -d "crushed" *.png
PAUSE
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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()));
});