Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Kemp jonkemp

View GitHub Profile
@jonkemp
jonkemp / git-best-practices.md
Last active Aug 29, 2015
Tips for using Git.
View git-best-practices.md

Tips for using Git

Tagging

Listing your tags

$ git tag

Creating Tags

View babySteps.js
var args = process.argv.slice(2);
var total = 0;
for (var i = 0, len = args.length; i < len; i++) {
total += Number(args[i]);
}
console.log(total);
@jonkemp
jonkemp / formatDate.js
Last active Aug 29, 2015
Take a date string and return it in a certain format.
View formatDate.js
function pad(num) {
return (num < 10 ? '0' : '') + num;
}
function formatDateMonthDayYear(date) {
if (date) {
date = new Date(date);
} else {
date = new Date();
}
@jonkemp
jonkemp / reverseIt.js
Last active Aug 29, 2015
Reverse a string using JavaScript.
View reverseIt.js
function reverseIt(str) {
return str.split('').reverse().join('');
}
@jonkemp
jonkemp / diffObjKeys.js
Created Mar 4, 2014
Compare 2 objects based on their keys: WIP
View diffObjKeys.js
var _ = _ || {};
_.contains = function (obj, target) {
if (obj == null) return false;
if (Array.prototype.indexOf && obj.indexOf === Array.prototype.indexOf) return obj.indexOf(target) != -1;
return obj.some(function(value) {
return value === target;
});
};
@jonkemp
jonkemp / README.md
Last active Aug 29, 2015
Bootstrap 'Digg-Style' Pagination template for Backbone
View README.md
@jonkemp
jonkemp / jQuery Checkbox Shortcut
Created Mar 14, 2011
An alias or shortcut for selecting checkboxes quickly in jQuery.
View jQuery Checkbox Shortcut
$.fn.checkbox = function () {
return this.find('input[type="checkbox"]');
};
@jonkemp
jonkemp / query.js
Last active Sep 25, 2015
A simple function for getting parameters from a query string.
View query.js
function query( key ) {
if ( location.href.indexOf("?") !== -1 ) {
var q = location.search,
p = [],
i, val;
q = q.slice(1);
if ( q.indexOf("&") !== -1 ) {
q = q.split("&");
for ( i=0; i < q.length; i++ ) {
p.push( q[i].split("=") );
@jonkemp
jonkemp / Check localStorage Bookmarklet
Created Mar 31, 2011
A bookmarklet for viewing localStorgage key/value pairs in your console.
View Check localStorage Bookmarklet
<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 Mar 31, 2011
This code will log key/value pairs saved in localStorage to your console for whatever domain you are on.
View Check localStorage
if ( localStorage.length ) {
for ( var i=0; i < localStorage.length; i++ ) {
console.log( localStorage.key(i) + ":" + localStorage.getItem( localStorage.key(i) ) );
}
}