Skip to content

Instantly share code, notes, and snippets.

View jonkemp's full-sized avatar

Jonathan Kemp jonkemp

View GitHub Profile
@jonkemp
jonkemp / Clear localStorage Bookmarklet
Created March 31, 2011 21:14
A bookmarklet for clearing data saved to localStorage in whatever domain you are on.
<a href="javascript:(function(){localStorage.clear();})();">Clear localStorage</a>
@jonkemp
jonkemp / ago.js
Created June 5, 2011 21:32 — forked from gf3/ago.js
Super small relative dates
module.exports = (function(){
const MS =
{ seconds: 1000
, minutes: 60 * 1000
, hours: 60 * 60 * 1000
, days: 24 * 60 * 60 * 1000
, weeks: 7 * 24 * 60 * 60 * 1000
, months: 30 * 7 * 24 * 60 * 60 * 1000
, years: 365 * 24 * 60 * 60 * 1000 }
@jonkemp
jonkemp / futon.js
Created August 28, 2011 04:07
Simple object oriented script for creating a global namespace and then extending via the prototype.
/*
Ex:
ftn.extend({
foo: function() {
console.log( "foo" );
}
});
ftn.foo();
@jonkemp
jonkemp / snippet.js
Created March 8, 2012 16:29 — forked from necolas/snippet.js
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],
@jonkemp
jonkemp / scrolldown.js
Created June 21, 2012 18:24
scrollDown: Scrolls the page down to show an element if it is not currently in the viewport. Requires jQuery.
function scrollDown( options ) {
var settings, winHeight, elementTop;
// override settings by passing in the options object
settings = $.extend({
'offset': 70,
'selector': 'footer',
'speed': 'fast'
}, options);
@jonkemp
jonkemp / dateRange.js
Created December 18, 2012 21:58
Get the current date and the date 30 days ago. Then format the dates like this: M/D/YYYY. This an example of date manipulation in JavaScript.
/**
* Get the current date and the date 30 days ago.
* Then format the dates like this: M/D/YYYY.
*/
var diff = 2592000000;
var now = new Date();
var diffDate = new Date( now.getTime() - diff );
var nowPrint = [ now.getMonth() + 1, now.getDate(), now.getFullYear() ].join("/");
var diffPrint = [ diffDate.getMonth() + 1, diffDate.getDate(), diffDate.getFullYear() ].join("/");
@jonkemp
jonkemp / placeholder.js
Last active December 15, 2015 23:09
Placeholder polyfill for inputs. Detects support for the placeholder attribute on inputs. If it is not present, the placeholder attribute text is inserted into the input, and a class of "placeholder-text" is added to the input. On keydown on the input, the placeholder text and the class is removed. On blur, if the input is empty, the placeholder…
// Jonathan's placeholder polyfill
// *Requires jQuery
(function () {
function PlaceholderDefaults() {
return {
'placeholderText': '',
'className': ''
};
}
@jonkemp
jonkemp / isEmpty.js
Created October 11, 2013 18:31
Checks a string to see if it is empty. Returns false if it finds anything other than white space in a string. Otherwise it returns true.
function isEmpty(val) {
return (!/\S/.test(val));
}
@jonkemp
jonkemp / formatDecimal.js
Created December 12, 2013 15:33
Format decimal numbers to prevent rounding errors. The first function limits decimal numbers to 2 places. The function always returns the number in number format even if you input the number as a string.
function getDecimalLimit2(mnt) {
return (Math.round(mnt * 100)) / 100;
}
@jonkemp
jonkemp / OSX-junos_pulse_listenToMe.sh
Created March 8, 2016 15:31 — forked from Andrewpk/OSX-junos_pulse_listenToMe.sh
wtf juniper. Anyone else find it irritating that junos pulse services and pulse tray must always running in OS X regardless of whether or not you're currently connected? Yeah, me too. I added the following as aliases to my shell to fix this problem. Be sure to change your /Library/LaunchAgents/net.juniper.pulsetray.plist file to reflect the `Kee…
#################################################################################
# start and stop the vpn from the command line from now on with these two commands
# or rename the aliases as you see fit.
#################################################################################
alias startvpn="sudo launchctl load -w /Library/LaunchDaemons/net.juniper.AccessService.plist; open -a '/Applications/Junos Pulse.app/Contents/Plugins/JamUI/PulseTray.app/Contents/MacOS/PulseTray'"
alias quitvpn="osascript -e 'tell application \"PulseTray.app\" to quit';sudo launchctl unload -w /Library/LaunchDaemons/net.juniper.AccessService.plist"