Skip to content

Instantly share code, notes, and snippets.

View davidwaterston's full-sized avatar

David Waterston davidwaterston

View GitHub Profile
@davidwaterston
davidwaterston / gist:3767723
Created September 22, 2012 20:25
My Sublime Text 2 Preferences
{
"color_scheme": "Packages/User/Espresso Soda.tmTheme",
"default_line_ending": "windows",
"dictionary": "Packages/Language - English/en_GB.dic",
"draw_white_space": "all",
"font_face": "Source Code Pro",
"font_size": 13,
"word_wrap": "false",
"highlight_line": true,
"highlight_modified_tabs": true,
@davidwaterston
davidwaterston / gist:3902518
Created October 16, 2012 22:38
Git: Delete a remote tag
git tag -d abcde
git push origin :refs/tags/abcde
@davidwaterston
davidwaterston / gist:3927588
Created October 21, 2012 16:54
jQuery: Add 'maxlength' support to textarea fields. Validates cleanly in JSLint.
(function ($) {
'use strict';
$.textareaMaxlength = function () {
// Allows the 'maxlength' attribute to be used with textarea fields to limit the
// number of characters that can be entered.
// e.g <textarea id="myfield" maxlength="250"></textarea>
@davidwaterston
davidwaterston / gist:4191070
Created December 2, 2012 21:05
Javascript: Case-sensitive 'contains'
if (typeof String.prototype.contains != 'function') {
String.prototype.contains = function(str) {
return this.indexOf(str) >= 0;
};
}
@davidwaterston
davidwaterston / startsWith
Last active October 13, 2015 11:47
Javascript: Case-sensitive 'starts with'
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function(str) {
return (this.lastIndexOf(str, 0) === 0);
};
}
@davidwaterston
davidwaterston / toISOString
Created January 13, 2013 09:16
Javascript: converts a Date object into an ISO 8601 formatted string.
if (typeof Date.prototype.toISOString !== 'function') {
(function () {
'use strict';
// Function which takes a 1 or 2-digit number and returns it as a two-character string,
// padded with an extra leading zero, if necessary.
function pad(number) {
var r = String(number);
@davidwaterston
davidwaterston / Increment number part of string
Created April 20, 2014 10:22
Javascript: increment the number part of a text field e.g. take a text field containing "abc15" and increment it by 1 to return "abc16", "xyz99" will become "xyz100", etc. Really shouldn't be doing this but if you have to then this will do it. See it in action: http://jsfiddle.net/davidwaterston/a8yXH/
var myString = "abc99";
newString = myString.replace(/\d+$/, function(n) { return ++n });
@davidwaterston
davidwaterston / no-object-prop-key-value-split.js
Last active August 29, 2015 14:18
ESLint custom rule: Disallow object property values from appearing on a different line from their key
/* global module */
"use strict";
module.exports = function (context) {
function checkObjectExpression(node) {
var props = node.properties;
var numberOfProperties = props.length;
@davidwaterston
davidwaterston / no-multi-object-properties-last-line.js
Last active August 29, 2015 14:18
ESLint custom rule: Disallow last property of a multiple property object to be declared on last line (no-multi-object-properties-last-line)
/* global module */
"use strict";
module.exports = function (context) {
function checkObjectExpression(node) {
var numberOfProperties = node.properties.length;
var objHasMultipleProperties = (numberOfProperties > 1);
@davidwaterston
davidwaterston / no-multi-object-properties-first-line.js
Created April 6, 2015 10:45
ESLint custom rule: Disallow first property of a multiple property object to be declared on first line (no-multi-object-properties-first-line)
/* global module */
"use strict";
module.exports = function (context) {
function checkObjectExpression(node) {
var numberOfProperties = node.properties.length;
var objHasMultipleProperties = (numberOfProperties > 1);