Skip to content

Instantly share code, notes, and snippets.

View jonnymaceachern's full-sized avatar

Jonny jonnymaceachern

  • Developer @ Media Mechanics
  • Halifax, NS
  • 19:48 (UTC -03:00)
View GitHub Profile
### Keybase proof
I hereby claim:
* I am jonnymaceachern on github.
* I am jonnymaceachern (https://keybase.io/jonnymaceachern) on keybase.
* I have a public key whose fingerprint is 6A78 AA59 B2AD 89D9 C60D 0EB3 73C0 1EBB 9860 CAA3
To claim this, I am signing this object:
@jonnymaceachern
jonnymaceachern / equalize.js
Last active August 15, 2019 20:05
Get elements that begin with a common class prefix, group them accordingly, and equalize their heights to their max height
var cousins = [];
// Find all elements that begin with class and return just that matching class
$('[class^=equalize-').each(function(index, el, array) {
var group = $(el).attr('class').match(/\bequalize-[\S]*/);
if ( group.length ) {
cousins.push( group[0] );
}
});
@jonnymaceachern
jonnymaceachern / external-links-in-new-tab.js
Created January 31, 2018 15:27
Add target="_blank" to external links
=SUM(INDIRECT("B1:"&ADDRESS(ROW()-1,COLUMN(),4)))
<?php
// Define custom query parameters
$custom_query_args = array( /* Parameters go here */ );
// Get current page and append to custom query parameters array
$custom_query_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
// Instantiate custom query
$custom_query = new WP_Query( $custom_query_args );
@jonnymaceachern
jonnymaceachern / gist:e248ea3891686e6048889c07cbf95a21
Last active July 17, 2017 19:10
Git find pre-existing file that was deleted and bring it back
git rev-list -n 1 HEAD -- <file_path>
git checkout <deleting_commit>^ -- <file_path>
@jonnymaceachern
jonnymaceachern / _functions.scss
Last active July 17, 2017 17:42
Fluid font-sizes
/// Remove the unit of a length
/// @param {Number} $number - Number to remove unit from
/// @return {Number} - Unitless number
@function strip-unit($number) {
@if type-of($number) == 'number' and not unitless($number) {
@return $number / ($number * 0 + 1);
}
@return $number;
}
@jonnymaceachern
jonnymaceachern / functions.php
Last active July 17, 2017 17:05
Remove related videos from YouTube embeds
// Remove related videos from youtube embeds
add_filter('embed_oembed_html', 'remove_related_videos_from_yt_oembed', 10, 3);
function remove_related_videos_from_yt_oembed($html, $url, $args = array()) {
if(!stristr($html, 'youtube.com/embed/'))
return $html;
preg_match('/src="(.+?(?="))/', $html, $matches);
if(count($matches) >= 2 && stristr($matches[1], 'youtube.com/embed/'))
{
@jonnymaceachern
jonnymaceachern / index.php
Last active July 17, 2017 16:50
Get YouTube ID by URL
<?php
function get_youtube_id( $url ) {
preg_match( "#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $url, $matches );
return $matches[0];
}
// Test
echo get_youtube_id( "https://youtu.be/MZj1bQtRNdk" ) );
@jonnymaceachern
jonnymaceachern / git-ignore-by-directory.sh
Last active July 14, 2017 18:40
Basically a .gitignore file for your local environment. Allows you to ignore files without updating the .gitignore directives.
exclude = !sh -c 'echo "$1" >> .git/info/exclude' -