Skip to content

Instantly share code, notes, and snippets.

View craigmccoy's full-sized avatar

Craig McCoy craigmccoy

View GitHub Profile

Keybase proof

I hereby claim:

  • I am craigmccoy on github.
  • I am craigmccoy (https://keybase.io/craigmccoy) on keybase.
  • I have a public key whose fingerprint is E8D1 A381 FCBC EAFE 5948 491B F8BB AAC1 65E7 6E75

To claim this, I am signing this object:

@craigmccoy
craigmccoy / myservice
Created May 5, 2016 14:08 — forked from bramus/myservice
Running a PHP script as a service/daemon using `start-stop-daemon`
#! /bin/sh
# Installation
# - Move this to /etc/init.d/myservice
# - chmod +x this
#
# Starting and stopping
# - Start: `service myservice start` or `/etc/init.d/myservice start`
# - Stop: `service myservice stop` or `/etc/init.d/myservice stop`
@craigmccoy
craigmccoy / ajax-dialog.js
Created September 20, 2012 04:09
Ajax loaded content for jQuery UI Dialog
/**
* Example HTML markup: <a class="ajax-dialog" href="/path/to/ajax/page" rel="#dialog">Click to open</a>
*/
$(function() {
$('a.ajax-dialog').click(function(evt) {
evt.preventDefault();
var link = $(evt.target);
var contentUrl = link.attr('href');
var targetDialog = $(link.attr('rel'));
@craigmccoy
craigmccoy / jquery.placeholder.js
Created September 13, 2012 15:12
Handling placeholders in IE
(function($) {
$.placeholder = function() {
if(typeof document.createElement('input').placeholder == 'undefined') {
$('[placeholder]').focus(function() {
var input = $(this);
if(input.val() == input.attr('placeholder')) {
input.val('').removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
@craigmccoy
craigmccoy / twitter-entities.js
Created September 3, 2012 19:15 — forked from wadey/twitter-entities.js
JavaScript parser for Tweet Entities
/*
* twitter-entities.js
* This function converts a tweet with "entity" metadata
* from plain text to linkified HTML.
*
* See the documentation here: http://dev.twitter.com/pages/tweet_entities
* Basically, add ?include_entities=true to your timeline call
*
* Copyright 2010, Wade Simmons
* Licensed under the MIT license
@craigmccoy
craigmccoy / jquery.logger.js
Created February 15, 2012 04:20
A simple plugin for turning a textarea into a debug message window.
(function($) {
$.log = function(context, message/*, ...*/) {
if(context.is('textarea')) {
if(arguments.length > 2) {
for(var i = 2; i < arguments.length; i++) {
message += ', ' + arguments[i];
}
}
var contents = context.val();
context.attr('readonly', 'readonly').val(contents + "\n" + message);
@craigmccoy
craigmccoy / jquery.suppressTooltips.js
Created January 20, 2011 21:23
suppressing browser tooltips, usage example: http://jsbin.com/eliro3/11
(function($){
$.fn.suppressTooltips = function() {
return this.each(function() {
var elem = $(this);
var title = elem.attr('title');
var alt = elem.attr('alt');
elem.hover(function() {
elem.attr('title', '').removeAttr('alt');
}, function() {
@craigmccoy
craigmccoy / capslock-detect.js
Created December 29, 2010 04:59
Function to detect whether or not CAPS LOCK key is active. Source: http://dougalmatthews.com/articles/2008/jul/2/javascript-detecting-caps-lock/
function isCapslock(e) {
e = (e) ? e : window.event;
var charCode = false;
if (e.which) {
charCode = e.which;
} else if (e.keyCode) {
charCode = e.keyCode;
}