Skip to content

Instantly share code, notes, and snippets.

View jamiehs's full-sized avatar

Jamie Hamel‑Smith jamiehs

View GitHub Profile
@jamiehs
jamiehs / functions.php
Created July 7, 2015 17:18
Snippet to add a smarter option to Mandrill for WordPress.
<?php
/**
* Add paragraph breaks to plain text notifications sent by Mandrill
*
* Mandrill's default option for handling this is a bit too
* agressive. This method checks the type of email, and attempts
* to detect whether or not it is HTML or not.
*
* @param array $message
@jamiehs
jamiehs / markup.html
Created April 14, 2015 22:53
Equal height strategy for Bootstrap columns
<div class="row equal-height">
<div class="hidden-xs equal-height-trigger"></div>
<div class="col-sm-6 col-md-3">
<div class="card">
<div class="inner">
<header>
<h3>Lorem</h3>
</header>
<p>Lorem ipsum Veniam eiusmod sunt velit deserunt ullamco cillum Duis dolore anim nulla Ut pariatur pariatur labore non esse qui proident ad.</p>
@jamiehs
jamiehs / scrollto-pushstate.js
Created September 23, 2014 17:32
jQuery Scroll To with history.pushState support for using the back button and the location bar: http://stackoverflow.com/a/16732655
$(document).on('click', 'a[href*=#]', function(event){
event.preventDefault();
var targetId = this.hash;
var theTarget = $(targetId);
var customOffset = 0;
switch( targetId ){
case '#target1':
case '#target2':
customOffset = -80;
@jamiehs
jamiehs / find-and-replace.sh
Created April 24, 2014 18:06
Recursively loop over all files, then use simple string replacements.
find . -type f -name "file-pattern*" -exec sh -c 'echo mv "$0" "${0/find/replace}"' '{}' \;
#Remove the echo when you're sure this does what you want.
function openPopup(href, title, width, height){
var left = screen.availLeft + screen.width/2 - width/2,
top = screen.height/2 - height/2;
window.open(href, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left);
};
@jamiehs
jamiehs / gist:9824788
Created March 28, 2014 03:37
ISO 8601 Parser for PHP
<?php
/**
* Parse an ISO 8601 duration string
* @return array
* @param string $str
**/
function parseDuration($str)
{
$result = array();
preg_match('/^(?:P)([^T]*)(?:T)?(.*)?$/', trim($str), $sections);
@jamiehs
jamiehs / sass-mixins.scss
Last active August 29, 2015 13:57
Magical mixins with trees
@mixin gallery-items($size) {
.item {
float: left;
.thumbnail {
margin-bottom: $size/4;
text-align: center;
width: $size;
height: $size;
@jamiehs
jamiehs / update-domain-name-2.sql
Created March 19, 2014 17:38
Simple version of MySQL find and replace for WOrdPress database migration.
# Update wp_options table
UPDATE wp_options SET option_value = REPLACE(option_value,'example.com','example.dev');
# Update wp_posts table
UPDATE wp_posts SET guid = REPLACE(guid,'example.com','example.dev');
@jamiehs
jamiehs / 01-update-domain-name.sql
Last active September 24, 2015 17:12
MySQL Find and replace for WordPress domain changing
# Table Prefix
SET @prefix = 'wp';
# Find and replace strings
SET @find = "www.example.com";
SET @replace = "www.example.dev";
# Build and execute the statements
SET @sql1 = CONCAT('UPDATE ', @prefix, '_options SET option_value = REPLACE(option_value,?,?)');
SET @sql2 = CONCAT('UPDATE ', @prefix, '_posts SET guid = REPLACE(guid,?,?)');
@jamiehs
jamiehs / Pi setup
Last active August 29, 2015 13:57
Setup a new Raspberry Pi Dashing board based on cloned image of "raspberrypi2"
# Find listening port 22 on the network
nmap -T5 -n -p 22 --open --min-parallelism 100 192.168.0.0/24
# edit hostname and hosts to change the hostname.
sudo nano /etc/hostname
sudo nano /etc/hosts
# edit the static IP address in the interfaces file.
sudo nano /etc/network/interfaces