Skip to content

Instantly share code, notes, and snippets.

dalethedeveloper

Block or report user

Report or block dalethedeveloper

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dalethedeveloper
dalethedeveloper / .htaccess
Created May 15, 2014
WordPress .htacces redirect to shift to new domain but allow wp-admin access
View .htaccess
# 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 Oct 1, 2014
Poor Mans Image Rotator (multiple slides, minimal jquery)
View gist:0ce24d86cf4c4a12e277
<!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 Dec 12, 2014
Check the Google Tag Manager dataLayer for an Ecommerce transaction and do something only once (cookie enforced)
View gist:460e7c72c1d1e9f55a94
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 Aug 29, 2015
Prepare a Tab Delimited flat file for SQL Import where text fields contain newlines that cause records fall to the next line
View gist:cc1f482f5ebdf07ccf26
# 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 Jan 12, 2015
Plain Javascript to normalize target attribute for External Links
View gist:8bbc30e847543fac088b
<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(){
View JavaScript - DOM Ready(ier)
/**
* 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
Wordpress + Facebook Done Right: Load FBConnect asynchronously for XFBML and handle the channelUrl
View gist:965036
/**
* 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 Jul 19, 2011
Mimic a static HTML file from Wordpress using functions.php
View gist:1093962
/* 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 Aug 3, 2011
Timestamp to a plain words description of elapsed delta (great for Twitter timestamps)
View gist:1123968
// 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 Aug 4, 2011
Minimalist post-load of Twitter Statuses to a page using jQuery (with bonus relative time description + Wordpress wraps!)
View gist:1126105
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)) {
You can’t perform that action at this time.