Skip to content

Instantly share code, notes, and snippets.

@delputnam
delputnam / gist:8aa157d1d0a5a3e5fd48
Created January 5, 2015 13:59
Background images for HTML Emails
<!-- from http://backgrounds.cm/ -->
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td background="http://i.imgur.com/YJOX1PC.png" bgcolor="#7bceeb" valign="top">
<!--[if gte mso 9]>
<v:rect xmlns:v="urn:schemas-microsoft-com:vml" fill="true" stroke="false" style="mso-width-percent:1000;">
<v:fill type="tile" src="http://i.imgur.com/YJOX1PC.png" color="#7bceeb" />
<v:textbox style="mso-fit-shape-to-text:true" inset="0,0,0,0">
<![endif]-->
<div>
@delputnam
delputnam / gist:a0361b939999c8ecf909
Created January 5, 2015 13:58
HTML5 Video Example
<video width="1100" height="619" preload="metadata" poster="/wp-content/uploads/2014/10/here-they-come-16x9.jpg" controls>
<source src="/wp-content/uploads/2014/10/Sample-16x9-HD.mp4" type="video/mp4">
<source src="/wp-content/uploads/2014/10/Sample-16x9-HD.webm" type="video/webm">
<source src="/wp-content/uploads/2014/10/Sample-16x9-HD.ogv" type="video/ogg">
</video>
@delputnam
delputnam / gist:347482e02e5edd6adb7b
Last active August 29, 2015 14:12
Get load time statistics using curl
Create a file named 'curl-format.txt':
time_namelookup: %{time_namelookup} s\n
time_connect: %{time_connect} s\n
time_appconnect: %{time_appconnect} s\n
time_pretransfer: %{time_pretransfer} s\n
time_redirect: %{time_redirect} s\n
time_starttransfer: %{time_starttransfer} s\n
----------\n
time_total: %{time_total} s\n
@delputnam
delputnam / collections_sort.rb
Last active January 29, 2023 15:38
This is a liquid filter for Jekyll that will sort collections based on arbitrary yaml front matter variables.
# collections_sort.rb
#
# Sort Jekyll collections items based on arbitrary yaml front matter variables.
#
# example usage:
#
# if you want to sort a collection based on a yaml variable of "order":
#
# {% assign filtered_events = site.my_collection | collection_sort: 'order' %}
#
@delputnam
delputnam / collections_filter.rb
Last active August 29, 2015 14:03
This is a liquid filter for Jekyll that will filter out individual collection items based on arbitrary yaml front matter variables.
# collections_filter.rb
#
# Filter individual Jekyll collections items based on arbitrary yam front matter variables.
#
# input - the collection array
# property - key to filter by
# value - desired value
#
# Returns the filtered array of objects
#
module Jekyll
class PostPublisher < Generator
safe false
def replace(filepath, regexp, *args, &block)
content = File.read(filepath).gsub(regexp, *args, &block)
File.open(filepath, 'wb') { |file| file.write(content) }
end
def generate(site)
@delputnam
delputnam / gist:6308052
Last active December 21, 2015 12:49
Get the first element of an array using php.
This resets the array's internal pointer to the first element:
reset( $array );
This does not modify the original array, but does make a copy of it, only use it for small arrays:
array_shift(array_values($array));
@delputnam
delputnam / functions.php
Created May 20, 2013 18:36
Get all WordPress posts of a certain type that have been published.
$query = new WP_Query( array(
'post_type' => 'event_type',
'post_status' => 'publish',
'nopaging' => true
) );
while ( $query->have_posts() ) : $query->the_post();
// Do something with the post here...
endwhile;
wp_reset_postdata();
@delputnam
delputnam / gist:5601170
Created May 17, 2013 18:55
To set a WordPress custom post type menu icon in a plugin include this in the args array when registering a custom post type.
'menu_icon' => plugins_url('images/custom-post-type-icon.png', __FILE__)
@delputnam
delputnam / wordpress_post_exists.php
Last active August 4, 2018 09:22
Quick check to determine if a WordPress post exists using the post_name (slug) and post_type (defaults to 'post'). Returns the post ID if found, or 0 (zero) if not found.
/**
* Determine if a post exists based on post_name and post_type
*
* @param $post_name string unique post name
* @param $post_type string post type (defaults to 'post')
*/
function post_exists( $post_name, $post_type='post' ) {
global $wpdb;