Skip to content

Instantly share code, notes, and snippets.

@ShirtlessKirk
ShirtlessKirk / cors.js
Last active August 29, 2015 14:15
CORS (Cross-Origin Resource Sharing) library
/**
* @preserve CORS (Cross-Origin Resource Sharing) library (https://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
*
* @author ShirtlessKirk copyright 2014
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
/*jslint unparam: true */
/*global define: false, module: false, require: false */
(function (global, definition) { // non-exporting module magic dance
'use strict';
@ShirtlessKirk
ShirtlessKirk / performance-timing.js
Last active February 12, 2024 00:32
Performance timing polyfill
/**
* performance-timing.js: Polyfill for performance.timing object
* For greatest accuracy, this needs to be run as soon as possible in the page, preferably inline.
* The values returned are necessarily not absolutely accurate, but are close enough for general purposes.
* @author ShirtlessKirk. Copyright (c) 2014.
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
(function (window) {
'use strict';
@ShirtlessKirk
ShirtlessKirk / luhn.js
Last active February 12, 2024 05:09
Luhn validation algorithm
/**
* Luhn algorithm in JavaScript: validate credit card number supplied as string of numbers
* @author ShirtlessKirk. Copyright (c) 2012.
* @license WTFPL (http://www.wtfpl.net/txt/copying)
*/
var luhnChk = (function (arr) {
return function (ccNum) {
var
len = ccNum.length,
bit = 1,