Skip to content

Instantly share code, notes, and snippets.

@roylory
roylory / NaN shits (javascript)
Last active October 19, 2018 00:21
NaN shits (javascript)
NaN==NaN // false, wtf?
isNaN(NaN) // true
isNaN(0/0) // true
isNaN(10) // false
isNaN("10") // false
isNaN("any string that can't become number") // true
isNaN(true) // false
isNaN(false) // false
typeof NaN === 'number' // true
@roylory
roylory / responsive-text-align-and-float.css
Last active August 29, 2015 14:12
Responsive text-align and Responsive float
//========================================================================
// Responsive text-align (https://github.com/twbs/bootstrap/issues/11292)
// and Responsive float
//========================================================================
.text-left-not-xs, .text-left-not-sm, .text-left-not-md, .text-left-not-lg {
text-align: left;
}
.text-center-not-xs, .text-center-not-sm, .text-center-not-md, .text-center-not-lg {
text-align: center;
@roylory
roylory / string.normalize.js
Last active October 12, 2015 01:07
toSnakeCase() and toCamelCase() as String.prototype
var hasSpace = /\s/;
var hasSeparator = /[\W_]/;
var separatorSplitter = /[\W_]+(.|$)/g;
var camelSplitter = /(.)([A-Z]+)/g;
function unseparate(string) {
return string.replace(separatorSplitter, function (m, next) {
return next ? ' ' + next : '';
});
}
function uncamelize(string) {
@roylory
roylory / gist:5eaeb8afc73145d9091a
Created April 24, 2015 21:37
UTC Date String Comparison
console.log("2015-03-16T21:29:54.23Z" > "2015-03-16T21:13:58.303Z") // expects true
console.log("2015-03-16T21:29:54.23Z" < "2015-03-16T21:13:58.303Z") // expects false
console.log("2015-03-16T21:13:58.303Z" > "2015-03-16T21:29:54.23Z") // expects false
console.log("2015-03-16T21:13:58.303Z" < "2015-03-16T21:29:54.23Z") // expects true
@roylory
roylory / mediaQuery.js
Last active November 17, 2019 08:11
Media query with Bootstrap grid classes in Javascript
mediaQuery = (function() {
// Same as in bootstrap/_variables.less
// var screenXs = 480; // Not used
var screenSm = 768;
var screenMd = 992;
var screenLg = 1200;
var screenXsMax = screenSm - 1;
var screenSmMax = screenMd - 1;
ANGULAR_APP
.filter('toNoCase', function () {
var hasSpace = /\s/;
var hasSeparator = /[\W_]/;
var separatorSplitter = /[\W_]+(.|$)/g;
var camelSplitter = /(.)([A-Z]+)/g;
function unseparate(string) {
return string.replace(separatorSplitter, function (m, next) {
return next ? ' ' + next : '';
});