This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<!-- | |
Minimal JS, crossbrowser, styled input[type="file"] with simple markup. | |
Tested working in IE[>=7], FF[24], O[16], C[30], S[6.0.5]; Should work in | |
all browsers that support opening a file browser via a label associated | |
to an input[type="file"]. Some adjustments might be necessary for IE[6] | |
support. | |
Tested using html5 doctype. Further testing is necessary to ensure proper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Mutable Binds. | |
* | |
* Why are mutable binds needed? | |
* I don't know about "needed", I came up with the idea because I was | |
* curious about if it would work, how it would work, and if there are | |
* any use cases. As for the use cases, I don't really know. If you can | |
* find a legitimate use case, let me know, I'd be happy to hear from | |
* you. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* querify | |
* | |
* Takes data in a hierarchy and returns a string suitably formatted for a POST | |
* request's postBody or a GET request's query component. | |
* | |
* Note: | |
* This function will not play well with circular referenced objects, it | |
* will result in an infinite loop. Most likely. I haven't tested | |
* that case. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var hasNativeCode = (function(hasNativeCodeRegexp){ // will this need changes because of ES6? | |
return function(f){ | |
return f && ( typeof f === 'function' && ( // This case checks functions/methods that are reported as functions | |
!f.hasOwnProperty('prototype') || // native methods don't have prototypes | |
hasNativeCodeRegexp.test(String(f)) // we don't care about the function name or arguments, just check if it's body is { [native code] } | |
)) || ( typeof f === 'object' && ( // certain browsers (that I know of, IE7 and IE8) report some native methods as object | |
!('constructor' in f) && // these methods don't have a constructor property and it can't be set | |
hasNativeCodeRegexp.test(String(f)) // it's string value will still be the native code string, so check for it | |
)); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isInteger = (function(NEGATIVE_INFINITY, POSITIVE_INFINITY){ | |
return function(n){ | |
return typeof n === 'number' && // Are you even an number? Rules out non numeric types. | |
n > NEGATIVE_INFINITY && // n larger than negative infinity? Rules out NaN and negative infinity. | |
n < POSITIVE_INFINITY && // n smaller than positive infinity? Rules out NaN and positive infinity. | |
!(n % 1); // n has a remainder of 0 when calculating modulo 1? Rules out floating points. | |
}; | |
}(-1/0, 1/0)); // just making sure we're getting negative and positive infinity | |
console.assert(isInteger(false) === false, 'booleans are not integers') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var bind = Function.prototype.bind ? Function.prototype.bind.bind(Function.prototype.call) : (function(){ | |
/** | |
* Some browsers don't have the bind function, so you can use the code | |
* below to achieve more or less the same results... A more complete | |
* implementation of binder can be found on mdn, this was just a quick hack. | |
*/ | |
function binder(fn, that){ | |
for(var i = 0, iLen = arguments.length, arr = new Array(iLen); i < iLen; i++){ | |
arr[i] = arguments[i]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* I feel like javascript functions are missing a method. Here's why: | |
* call is to bind as apply is to ? | |
* | |
* Javascript lacks a native method of binding an array as a list of parameters | |
* to a function. Here's what I came up with: | |
*/ | |
if(Function.prototype.bind && !Function.prototype.bundle){ | |
Function.prototype.bundle = function(thisArg, argsArray){ | |
return this.bind.apply(this, [thisArg].concat(Object.prototype.toString.call(argsArray) === '[object Array]'? argsArray: [])); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* I stumbled upon this solution while trying to help out a colleague. | |
* I was studying a book on the theory of computation at the time | |
* which, coincidentally, talked about state machines, it then ocurred | |
* to me that a state machine could help solve the problems we were | |
* having at the time. | |
*/ | |
(function(){ | |
// 0 = not doing anything | |
// 1 = is dragging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Use a simple object to create your html with variables | |
* and whatever code you need to build it up. | |
* | |
* You can take advantage of type coercion here to | |
* end up with the final strings. | |
*/ | |
var template = { | |
placeholder1: undefined, | |
placeholder2: undefined, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Original nested version | |
if ( a > 0 ) { | |
if ( b > 10 ) { | |
if ( c > 0 ) { | |
//complex code | |
} | |
} | |
} | |
return; |
OlderNewer