Skip to content

Instantly share code, notes, and snippets.

@tborychowski
tborychowski / js-overrides.js
Last active December 20, 2015 00:09
JS :: some native objects "extensions"
/**
* JS OVERRIDES
*/
(function (window) {
'use strict';
String.prototype.trim = function (str) {return this.ltrim(str).rtrim(str); };
String.prototype.ltrim = function (str) { return this.replace(new RegExp('^' + (str ? str : '\\s') + '+'), ''); };
String.prototype.rtrim = function (str) { return this.replace(new RegExp((str ? str : '\\s') + '+$'), ''); };
String.prototype.ucfirst = function () {
@tborychowski
tborychowski / js-number-format.js
Created October 11, 2013 10:39
JS :: format number as currency
(2500).toLocaleString("en-GB", {style: "currency", currency: "GBP", minimumFractionDigits: 2})
function encrypt(text){
var cipher = crypto.createCipher('aes-256-cbc','d6F3Efeq')
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}
function decrypt(text){
var decipher = crypto.createDecipher('aes-256-cbc','d6F3Efeq')
var dec = decipher.update(text,'hex','utf8')
@tborychowski
tborychowski / css-transition-end.js
Last active August 29, 2015 13:56
JS :: detect css transition end
/* From Modernizr */
function whichTransitionEvent() {
var el = document.createElement('fakeelement'), t,
transitions = {
'transition': 'transitionend',
'OTransition': 'oTransitionEnd',
'MozTransition': 'transitionend',
'WebkitTransition': 'webkitTransitionEnd',
'MsTransition': 'msTransitionEnd'
};
@tborychowski
tborychowski / jquery-alt-animate.js
Created August 22, 2014 11:54
JS :: jquery alt animate
$({ a:0 }).animate({ a:.3 },{
duration: 1000,
step: function(){
// do something
},
complete: function(){
}
});
@tborychowski
tborychowski / mydate.js
Created August 22, 2014 12:06
JS :: date functions
/* DATE FUNCTIONS */
Date.months = [
{ shortName: 'jan', days: 31, name: 'January' },
{ shortName: 'feb', days: 28, name: 'February' },
{ shortName: 'mar', days: 31, name: 'March' },
{ shortName: 'apr', days: 30, name: 'April' },
{ shortName: 'may', days: 31, name: 'May' },
{ shortName: 'jun', days: 30, name: 'June' },
{ shortName: 'jul', days: 31, name: 'July' },
{ shortName: 'aug', days: 31, name: 'August' },
@tborychowski
tborychowski / firebug.js
Created August 22, 2014 12:49
Firebug Colours
console.log('%cERROR: %c siema %c tom',
'font: bold 12px arial; color:red; line-height:2.6em;',
'font: 12px arial; color:green;',
'font: 12px arial; color:blue;'
);
@tborychowski
tborychowski / fuzzy.js
Created August 22, 2014 12:51
JS :: fuzzy search
String.prototype.fuzzy = function (s) {
var hay = this.toLowerCase(), i = 0, n = -1, l;
s = s.toLowerCase();
for (; l = s[i++] ;) if (!~(n = hay.indexOf(l, n + 1))) return false;
return true;
};
('a haystack with a needle').fuzzy('hay sucks'); // false
('a haystack with a needle').fuzzy('sack hand'); // true
@tborychowski
tborychowski / get-url-vars.js
Created August 22, 2014 12:53
JS :: get url vars
_getUrlVars = function () {
var vars = {},
parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
vars[key] = value;
});
return vars;
}
@tborychowski
tborychowski / weird.js
Last active August 29, 2015 14:05
JS :: weirdness
fail
f (![]+[])[+[]]
a (![]+[])[+!+[]]
i ([![]]+[][[]])[+!+[]+[+[]]]
l (![]+[])[!+[]+!+[]]
t (!![]+[])[+[]]