Skip to content

Instantly share code, notes, and snippets.

View jonkemp's full-sized avatar

Jonathan Kemp jonkemp

View GitHub Profile
@jonkemp
jonkemp / timestamp.js
Created May 11, 2012 15:06
Print out a nicely formatted timestamp in JavaScript.
/**
* Return a timestamp with the format "m/d/yy h:MM:ss TT"
* @type {Date}
*/
function timeStamp() {
// Create a date object with the current time
var now = new Date();
// Create an array with the current month, day and time
@jonkemp
jonkemp / css-calc.css
Created April 2, 2012 04:17
Cross Browser CSS Calc()
/* 1. write it out for older browsers */
/* 2. use the vendor prefix for webkit */
/* 3. use the vendor prefix for moz */
/* 4. include the un-prefixed version last */
#foo {
width: 200px;
width: -webkit-calc(50% - 100px);
width: -moz-calc(50% - 100px);
width: calc(50% - 100px);
@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 / 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 / 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 / prepopulate.html
Created April 5, 2011 15:11
Pre-populate your forms with random data. For testing forms. Requires jQuery. Includes a bookmarklet.
<!-- include jQuery -->
<script>
$('form').find('input:text').val( function(i, val) {
return $(this).attr('name');
});
$('form').find('select').each( function(a) {
$(this).find('option').each( function(b) {
if ( $(this).val() !== '' ) {
$(this).parent().val( $(this).val() );
@jonkemp
jonkemp / Check localStorage Bookmarklet
Created March 31, 2011 21:29
A bookmarklet for viewing localStorgage key/value pairs in your console.
<a href="javascript:(function(){if(localStorage.length){for(var i=0;i<localStorage.length;i++){console.log(localStorage.key(i)+':'+localStorage.getItem(localStorage.key(i)));}}})();">Check localStorage</a>
@jonkemp
jonkemp / Check localStorage
Created March 31, 2011 21:24
This code will log key/value pairs saved in localStorage to your console for whatever domain you are on.
if ( localStorage.length ) {
for ( var i=0; i < localStorage.length; i++ ) {
console.log( localStorage.key(i) + ":" + localStorage.getItem( localStorage.key(i) ) );
}
}
@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>