Skip to content

Instantly share code, notes, and snippets.

View codfish's full-sized avatar

Chris O'Donnell codfish

View GitHub Profile
@codfish
codfish / find_string_in_repo.sh
Created May 24, 2016 17:57
Get an alphabetical list of files that a specific string is found within your repo
git grep '<string to search for>' | awk '{print $1}' | sed 's/:$//' | sort -u
@codfish
codfish / search_multi_array.php
Created May 16, 2016 13:27
Search multi-dimensional array based on key value pair. i.e. you have an array of posts, and you want to return the post with the id of `1231`
<?php
$posts = [
[
'id' => 1231,
'title' => 'Test'
],
[
'id' => 1111,
'title' => 'Test #2'
@codfish
codfish / wedding.sh
Last active March 11, 2016 03:32
Download wedding photos. Photographer put all of our photos for us and family to buy, but wasn't going to give us a digital copy. So...
#!/usr/bin/env bash
# need to set env variable for the public base url for the photos
if [[ -z "$WEDDING_URL_PREFIX" ]]; then
printf '\nError: WEDDING_URL_PREFIX needs to be set in your environment!\n'
exit 1
fi
# image filenames had two different prefixes
IMG_TOTAL=2405
@codfish
codfish / dynamic_iframe_height.js
Last active September 16, 2015 20:52
Update the height of an iframe dynamically based on the height of the source content. Code is dependent on jQuery, and will only work when iframe is the same host/domain as the parent page, or if you have access to the content of the iframe. Reference: http://goo.gl/Rz3Ryz
// @example
// <iframe src="/form.html" id="infographic-iframe"></iframe>
document.getElementById('infographic-iframe').style.height = $('#infographic-iframe').contents().height() + 'px';
@codfish
codfish / wp_redirect_short_links.php
Last active November 15, 2017 15:12
Wordpress short links don't automatically redirect to the post permalink, like some (me) might think they should. If you switch your permalink structure to something more SEO friendly, existing posts should automatically redirect to the proper format. However, future posts will not. If you want all "short links" (mywordpresssite.com/?p=123456) t…
@codfish
codfish / php_show_errors.php
Last active August 29, 2015 14:25
Quick way to display all php errors on your page for debugging purposes.
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
@codfish
codfish / rick-roll-terminal.sh
Last active September 28, 2018 22:13
Rick roll terminal prank
#!/bin/bash
#
# some shortcomings:
# - prankee needs to be running rvm, rbenv, or some other
# ruby version manager that doesn't require sudo permissions to
# install gems.
# - can be killed by simply closing current tab/session
#
# Any bug reports or suggestions on improvements are welcome!
#
@codfish
codfish / regex-html-attribute.js
Last active August 29, 2015 14:24
Quick and dirty way to grab the value of an attribute from an HTML string with regex.
var html = '<iframe width="420" height="315" src="https://www.youtube.com/embed/cwhLueAWItA" frameborder="0" allowfullscreen></iframe>';
var width = html.match( /(?:.*width="(.*?)".*)?/i ).pop();
var height = html.match( /(?:.*height="(.*?)".*)?/i ).pop();
var src = html.match( /(?:.*src="(.*?)".*)?/i ).pop();
@codfish
codfish / handlebars-helpers.js
Last active April 13, 2022 10:29
Some useful helpers for the handlebars js templating library.
/**
* Useful helpers for the handlebars js templating library
*
* @uses Handlebars
* @link https://gist.github.com/elidupuis/1468937 <Some credit due>
*/
;(function(Handlebars, window, document, undefined) {
'use strict';
/**
@codfish
codfish / clean-multi-line-string.js
Last active August 29, 2015 14:22
Interesting way to write a multiline string in JS, to keep things clean.
var multiLiner = String() +
'<section>' +
'<div class="content-wrapper">' +
'<a href="#" class="js-link">Click Here</a>' +
'</div>' +
'</section>';