Skip to content

Instantly share code, notes, and snippets.

@dalethedeveloper
dalethedeveloper / .htaccess
Created May 15, 2014 19:21
WordPress .htacces redirect to shift to new domain but allow wp-admin access
# Drop at the end of your base .htaccess or virtualhost, hooray for negative lookaheads
RedirectMatch ^\/(?!wp\-admin)(.*)$ http://newdomain.com/$1
@dalethedeveloper
dalethedeveloper / gist:0ce24d86cf4c4a12e277
Created October 1, 2014 15:17
Poor Mans Image Rotator (multiple slides, minimal jquery)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script>
var rollem = function() {
var si = $('#slide ul.current');
si.removeClass('current').fadeOut(
@dalethedeveloper
dalethedeveloper / gist:460e7c72c1d1e9f55a94
Created December 12, 2014 16:33
Check the Google Tag Manager dataLayer for an Ecommerce transaction and do something only once (cookie enforced)
if (typeof (window.dataLayer) !== 'undefined' && window.dataLayer.length) {
for (var d = 0; d < window.dataLayer.length; d++) {
var obj = window.dataLayer[d],
keys = Object.keys(obj);
for (var k = 0; k < keys.length; k++) {
var key = keys[k],
val = obj[key];
@dalethedeveloper
dalethedeveloper / gist:cc1f482f5ebdf07ccf26
Last active August 29, 2015 14:11
Prepare a Tab Delimited flat file for SQL Import where text fields contain newlines that cause records fall to the next line
# Assumes a tab delimited flat file and the first field being a numeric key
BEGIN {
FS = OFS = "\t";
p = "";
}
# Strategy is to readline, check for key in first field, store to print
# on next readline if the next record has a key in first field, otherwise
# append our fragmented line to the stored line
{
sub(/\r/,""); # also scrub those pesky carriage returns
@dalethedeveloper
dalethedeveloper / gist:8bbc30e847543fac088b
Created January 12, 2015 04:57
Plain Javascript to normalize target attribute for External Links
<script>
// I needed to trigger a non-interactive Google Analytics Event on external link click in
// Google Tag Manager v2. This is a hacky workaround for targeting external links on using
// a trigger like this:
// Event Type: Link Click [element: target] [starts with] ["_"]
// This is used as a HTML tag in Google Tag Manager v2 to normalize all external <A> links
// to have a "target" attribute. Priority 100, Triggered on All Pages and Event = gtm.dom
(function(){
/**
* Works in Chrome, Firefox, MSIE, Opera and Safari.
*/
function onDOMContentLoaded( event ) {
if( event ) {
document.removeEventListener( event.type, onDOMContentLoaded, false );
}
document.onreadystatechange = null;
// For testing purposes.
alert( "DOM Content Loaded" );
@dalethedeveloper
dalethedeveloper / gist:965036
Created May 10, 2011 18:18
Wordpress + Facebook Done Right: Load FBConnect asynchronously for XFBML and handle the channelUrl
/**
* A class-based approach to bring in Facbook Connect asynchronously on every
* frontend page load. Also handles side-loading channelURL when using
* Facebook's FB.init() method.
*
* This fits nicely in any functions.php, or can be dropped in to a standalone
* php file to use as a plugin.
*
* @link http://developers.facebook.com/docs/reference/javascript/FB.init/
*/
@dalethedeveloper
dalethedeveloper / gist:1093962
Created July 19, 2011 23:01
Mimic a static HTML file from Wordpress using functions.php
/* When an html page like URL is accessed, return some static content,
In this case, a verification page for Google Apps
In the current theme functions.php:
*/
if( !class_exists('google_verify') ) {
class google_verify {
public function __construct() {
add_filter('rewrite_rules_array', array($this,'gv_rewrite') );
if( !is_admin() ) {
@dalethedeveloper
dalethedeveloper / gist:1123968
Created August 3, 2011 22:20
Timestamp to a plain words description of elapsed delta (great for Twitter timestamps)
// Adapted from jQuery TimeAgo plugin:
// https://github.com/rmm5t/jquery-timeago/blob/master/jquery.timeago.js
// Update, check out performance: http://jsperf.com/twitter-relative-time-parsing
function timetowords(timestamp) {
var words = {
"seconds": "less than a minute",
"minute": "about a minute",
"minutes": "%d minutes",
@dalethedeveloper
dalethedeveloper / gist:1126105
Created August 4, 2011 20:07
Minimalist post-load of Twitter Statuses to a page using jQuery (with bonus relative time description + Wordpress wraps!)
jQuery(document).ready(function($) {
$.getJSON('http://twitter.com/statuses/user_timeline/Shitmydadsays.json?count=4&callback=?', function(data){
var relative_time = function(datetime) {
var delta = parseInt((Date.now() - Date.parse(datetime)) / 1000, 10);
var r = '';
if (delta < 60) {
r = delta + ' seconds ago';
} else if (delta < 120) {
r = 'A minute ago';
} else if (delta < (45 * 60)) {