Skip to content

Instantly share code, notes, and snippets.

View kfriend's full-sized avatar

Kevin Friend kfriend

  • 742 Evergreen Terrace
View GitHub Profile
@kfriend
kfriend / gist:6113222
Last active December 20, 2015 10:09
JavaScript: Open external links and specific file types in a new tab/window
$(document).ready(function() {
/*-------------------------------------------------------------------
| Force external links and specific files to open in a new window/tab
*-------------------------------------------------------------------*/
var externalProtocolRegex = /^https?:\/\//i;
var externalRegex = (window.location.protocol + '//' + window.location.hostname).replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
externalRegex = new RegExp('^(\/\/|' + externalRegex + ')');
var fileRegex = /\.pdf$/;
$('a[href!=""]').not('[target=_blank]').click(function(event) {
@kfriend
kfriend / gist:6184796
Created August 8, 2013 13:55
Wordpress: Disable Admin Dashboard For Subscribers
add_action('admin_init', function() {
if (!current_user_can('manage_options') && $_SERVER['DOING_AJAX'] != '/wp-admin/admin-ajax.php') {
wp_redirect(home_url()); exit;
}
});
@kfriend
kfriend / gist:6184801
Created August 8, 2013 13:56
Wordpress: Remove Admin Toolbar For Non-Admins
add_action('after_setup_theme', function() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
});
@kfriend
kfriend / gist:6225050
Last active December 21, 2015 01:08
CsvArray: Simple array wrapper class for representing CSV data, with methods for converting to CSV from an array.
<?php
class CsvArray
{
protected $data;
protected $delimiter;
protected $enclosure;
protected $forceEnclosement;
public function __construct($data = array(), $delimiter = ',', $enclosure = '"', $forceEnclosement = false)
if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
var viewportmeta = document.querySelector('meta[name="viewport"]');
if (viewportmeta) {
viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';
document.body.addEventListener('gesturestart', function () {
viewportmeta.content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6';
}, false);
}
}
@kfriend
kfriend / send.rb
Created August 25, 2013 23:31
Ruby: Simple script for sending HTML email. Great for testing HTML emails.
require 'pony'
raise 'Please specify an email file path' if ARGV.count < 1
html = File.open(ARGV[0])
Pony.mail(
:to => 'to@example.com',
:from => "from@example.com",
:subject => 'Email Test',
@kfriend
kfriend / gist:6359887
Created August 27, 2013 22:18
PHP: Time-to-seconds helper functions
<?php
function time_to_seconds($time = 0)
{
list($secs, $mins, $hours) = array_pad(array_reverse(explode(':', $time)), 3, 0);
return ($hours * 3600) + ($mins * 60) + $secs;
}
@kfriend
kfriend / gist:6396085
Created August 31, 2013 03:38
Apple Script: Ask for password
beep 1
set passwd to ""
display dialog "Please enter your user password" default answer ""
set passwd to text returned of result
@kfriend
kfriend / gist:6396093
Created August 31, 2013 03:40
Shell: Create tarball w/o git repo and cache system cache files
export COPYFILE_DISABLE=true && tar -czvf tarball.tar.gz --exclude='.DS_Store' --exclude='._*' --exclude='Thumbs.db' --exclude='.git' --exclude='.git*' /path/to/archive
@kfriend
kfriend / gist:6396185
Created August 31, 2013 04:13
Shell: Create tarball without system cache files
export COPYFILE_DISABLE=true && tar -czvf tarball.tar.gz --exclude='.DS_Store' --exclude='._*' --exclude='Thumbs.db' /path/to/archive