This file contains hidden or 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
| function ajaxLoadScript(file) { | |
| var xhr = new XMLHttpRequest(); | |
| xhr.open("get", file, true); | |
| xhr.onreadystatechange = function () { | |
| if (xhr.readyState == 4) { | |
| if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304) { | |
| var script = document.createElement("script"); | |
| script.type = "text/javascript"; | |
| script.text = xhr.responseText; | |
| document.body.appendChild(script); |
This file contains hidden or 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
| //credit: Jeff Greenberg | |
| var iterations = Math.floor(items.length / 8), | |
| startAt = items.length % 8, | |
| i = 0; | |
| do { | |
| switch (startAt) { | |
| case 0: | |
| process(items[i++]); | |
| case 7: | |
| process(items[i++]); |
This file contains hidden or 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
| function bubblesort() { | |
| var numElements = this.dataStore.length; | |
| var temp; | |
| for (var outer = numElements; outer >= 2; --outer) { | |
| for (var inner = 0; inner <= outer - 1; ++inner) { | |
| if (this.dataStore[inner] > this.dataStore[inner + 1]) { | |
| temp = this.dataStore[inner]; | |
| this.dataStore[inner] = this.dataStore[inner + 1]; | |
| this.dataStore[inner + 1] = temp; | |
| } |
This file contains hidden or 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
| //customized mem function for factorial, with very good performance. | |
| function memfactorial(n) { | |
| if (!memfactorial.cache) { | |
| memfactorial.cache = { | |
| "0": 1, | |
| "1": 1 | |
| }; | |
| } | |
| if (!memfactorial.cache.hasOwnProperty(n)) { | |
| memfactorial.cache[n] = n * memfactorial(n - 1); |
This file contains hidden or 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
| // trim with regular expression | |
| String.prototype.trim = function () { | |
| return this.replace(/^\s*([\s\S]*\S)?\s*$/, "$1"); | |
| }; | |
| // trim with string methods | |
| String.prototype.trim = function () { | |
| var start = 0, | |
| end = this.length - 1, | |
| ws = " \n\r\t\f\x0b\xa0\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u202f\u205f\u3000\ufeff"; |
This file contains hidden or 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
| private void enableHTML5AppCache() { | |
| webView.getSettings().setDomStorageEnabled(true); | |
| // Set cache size to 8 mb by default. should be more than enough | |
| webView.getSettings().setAppCacheMaxSize(1024*1024*8); | |
| // This next one is crazy. It's the DEFAULT location for your app's cache | |
| // But it didn't work for me without this line | |
| webView.getSettings().setAppCachePath("/data/data/"+ getPackageName() +"/cache"); |
This file contains hidden or 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
| /*! | |
| * Pub/Sub implementation | |
| * http://addyosmani.com/ | |
| * Licensed under the GPL | |
| * http://jsfiddle.net/LxPrq/ | |
| */ | |
| ;(function ( window, doc, undef ) { |
This file contains hidden or 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
| def tstamp = new Date().format('yyyy-MM-dd_HH-mm-ss') | |
| def buildLogDir = "${rootDir}/build/logs" | |
| mkdir("${buildLogDir}") | |
| def buildLog = new File("${buildLogDir}/${tstamp}_buildLog.log") | |
| import org.gradle.logging.internal.* | |
| System.setProperty('org.gradle.color.error', 'RED') | |
| gradle.services.get(LoggingOutputInternal).addStandardOutputListener (new StandardOutputListener () { | |
| void onOutput(CharSequence output) { |
This file contains hidden or 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
| // Constructor way | |
| function SingletonKlass() { | |
| var instance; | |
| SingletonKlass = function SingletonKlass() { | |
| return instance; | |
| } | |
| SingletonKlass.prototype = this; | |
| instance = new SingletonKlass(); |
This file contains hidden or 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
| function FactorySample() {} | |
| FactorySample.prototype.action = function() { | |
| return "the id of this instance is " + this.id; | |
| }; | |
| FactorySample.factory = function(type) { | |
| var newInstance; | |
| // check whether constructor type exist |